| 1 |
// RUN: %clang_cc1 -ast-dump %s | FileCheck %s |
| 2 |
|
| 3 |
/* WG14 N1365: Clang 16 |
| 4 |
* Constant expressions |
| 5 |
*/ |
| 6 |
|
| 7 |
// Note: we don't allow you to expand __FLT_EVAL_METHOD__ in the presence of a |
| 8 |
// pragma that changes its value. However, we can test that we have the correct |
| 9 |
// constant expression behavior by testing that the AST has the correct implicit |
| 10 |
// casts, which also specify that the cast was inserted due to an evaluation |
| 11 |
// method requirement. |
| 12 |
void func(void) { |
| 13 |
{ |
| 14 |
#pragma clang fp eval_method(double) |
| 15 |
_Static_assert(123.0F * 2.0F == 246.0F, ""); |
| 16 |
// CHECK: StaticAssertDecl |
| 17 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean> |
| 18 |
// CHECK-NEXT: BinaryOperator {{.*}} 'int' '==' |
| 19 |
// CHECK-NEXT: BinaryOperator {{.*}} 'double' '*' FPEvalMethod=1 |
| 20 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=1 |
| 21 |
// CHECK-NEXT: FloatingLiteral |
| 22 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=1 |
| 23 |
// CHECK-NEXT: FloatingLiteral |
| 24 |
|
| 25 |
// Ensure that a cast removes the extra precision. |
| 26 |
_Static_assert(123.0F * 2.0F == 246.0F, ""); |
| 27 |
// CHECK: StaticAssertDecl |
| 28 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean> |
| 29 |
// CHECK-NEXT: BinaryOperator {{.*}} 'int' '==' |
| 30 |
// CHECK-NEXT: BinaryOperator {{.*}} 'double' '*' FPEvalMethod=1 |
| 31 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=1 |
| 32 |
// CHECK-NEXT: FloatingLiteral |
| 33 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=1 |
| 34 |
// CHECK-NEXT: FloatingLiteral |
| 35 |
} |
| 36 |
|
| 37 |
{ |
| 38 |
#pragma clang fp eval_method(extended) |
| 39 |
_Static_assert(123.0F * 2.0F == 246.0F, ""); |
| 40 |
// CHECK: StaticAssertDecl |
| 41 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean> |
| 42 |
// CHECK-NEXT: BinaryOperator {{.*}} 'int' '==' |
| 43 |
// CHECK-NEXT: BinaryOperator {{.*}} 'long double' '*' FPEvalMethod=2 |
| 44 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'long double' <FloatingCast> FPEvalMethod=2 |
| 45 |
// CHECK-NEXT: FloatingLiteral |
| 46 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'long double' <FloatingCast> FPEvalMethod=2 |
| 47 |
// CHECK-NEXT: FloatingLiteral |
| 48 |
} |
| 49 |
|
| 50 |
{ |
| 51 |
#pragma clang fp eval_method(source) |
| 52 |
_Static_assert(123.0F * 2.0F == 246.0F, ""); |
| 53 |
// CHECK: StaticAssertDecl |
| 54 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean> |
| 55 |
// CHECK-NEXT: BinaryOperator {{.*}} 'int' '==' |
| 56 |
// CHECK-NEXT: BinaryOperator {{.*}} 'float' '*' FPEvalMethod=0 |
| 57 |
// CHECK-NEXT: FloatingLiteral |
| 58 |
// CHECK-NEXT: FloatingLiteral |
| 59 |
} |
| 60 |
} |