61 lines · c
1// RUN: %clang_cc1 -ast-dump %s | FileCheck %s2 3/* WG14 N1365: Clang 164 * Constant expressions5 */6 7// Note: we don't allow you to expand __FLT_EVAL_METHOD__ in the presence of a8// pragma that changes its value. However, we can test that we have the correct9// constant expression behavior by testing that the AST has the correct implicit10// casts, which also specify that the cast was inserted due to an evaluation11// method requirement.12void func(void) {13 {14 #pragma clang fp eval_method(double)15 _Static_assert(123.0F * 2.0F == 246.0F, "");16 // CHECK: StaticAssertDecl17 // CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean>18 // CHECK-NEXT: BinaryOperator {{.*}} 'int' '=='19 // CHECK-NEXT: BinaryOperator {{.*}} 'double' '*' FPEvalMethod=120 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=121 // CHECK-NEXT: FloatingLiteral22 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=123 // CHECK-NEXT: FloatingLiteral24 25 // Ensure that a cast removes the extra precision.26 _Static_assert(123.0F * 2.0F == 246.0F, "");27 // CHECK: StaticAssertDecl28 // CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean>29 // CHECK-NEXT: BinaryOperator {{.*}} 'int' '=='30 // CHECK-NEXT: BinaryOperator {{.*}} 'double' '*' FPEvalMethod=131 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=132 // CHECK-NEXT: FloatingLiteral33 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=134 // CHECK-NEXT: FloatingLiteral35 }36 37 {38 #pragma clang fp eval_method(extended)39 _Static_assert(123.0F * 2.0F == 246.0F, "");40 // CHECK: StaticAssertDecl41 // CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean>42 // CHECK-NEXT: BinaryOperator {{.*}} 'int' '=='43 // CHECK-NEXT: BinaryOperator {{.*}} 'long double' '*' FPEvalMethod=244 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'long double' <FloatingCast> FPEvalMethod=245 // CHECK-NEXT: FloatingLiteral46 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'long double' <FloatingCast> FPEvalMethod=247 // CHECK-NEXT: FloatingLiteral48 }49 50 {51 #pragma clang fp eval_method(source)52 _Static_assert(123.0F * 2.0F == 246.0F, "");53 // CHECK: StaticAssertDecl54 // CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean>55 // CHECK-NEXT: BinaryOperator {{.*}} 'int' '=='56 // CHECK-NEXT: BinaryOperator {{.*}} 'float' '*' FPEvalMethod=057 // CHECK-NEXT: FloatingLiteral58 // CHECK-NEXT: FloatingLiteral59 }60}61