forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C11] Update the status of N1365 on constant expression handling
This paper is about constant expression handling in the presence of FLT_EVAL_METHOD, which we handle via insertion of implicit cast nodes in the AST.
- Loading branch information
1 parent
a7a2e9a
commit c4d5141
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// RUN: %clang_cc1 -ast-dump %s | FileCheck %s | ||
|
||
/* WG14 N1365: Clang 16 | ||
* Constant expressions | ||
*/ | ||
|
||
// Note: we don't allow you to expand __FLT_EVAL_METHOD__ in the presence of a | ||
// pragma that changes its value. However, we can test that we have the correct | ||
// constant expression behavior by testing that the AST has the correct implicit | ||
// casts, which also specify that the cast was inserted due to an evaluation | ||
// method requirement. | ||
void func(void) { | ||
{ | ||
#pragma clang fp eval_method(double) | ||
_Static_assert(123.0F * 2.0F == 246.0F, ""); | ||
// CHECK: StaticAssertDecl | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean> | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'int' '==' | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'double' '*' FPEvalMethod=1 | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=1 | ||
// CHECK-NEXT: FloatingLiteral | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=1 | ||
// CHECK-NEXT: FloatingLiteral | ||
|
||
// Ensure that a cast removes the extra precision. | ||
_Static_assert((float)(123.0F * 2.0F) == 246.0F, ""); | ||
// CHECK: StaticAssertDecl | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean> | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'int' '==' | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'double' '*' FPEvalMethod=1 | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=1 | ||
// CHECK-NEXT: FloatingLiteral | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'double' <FloatingCast> FPEvalMethod=1 | ||
// CHECK-NEXT: FloatingLiteral | ||
} | ||
|
||
{ | ||
#pragma clang fp eval_method(extended) | ||
_Static_assert(123.0F * 2.0F == 246.0F, ""); | ||
// CHECK: StaticAssertDecl | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean> | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'int' '==' | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'long double' '*' FPEvalMethod=2 | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'long double' <FloatingCast> FPEvalMethod=2 | ||
// CHECK-NEXT: FloatingLiteral | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'long double' <FloatingCast> FPEvalMethod=2 | ||
// CHECK-NEXT: FloatingLiteral | ||
} | ||
|
||
{ | ||
#pragma clang fp eval_method(source) | ||
_Static_assert(123.0F * 2.0F == 246.0F, ""); | ||
// CHECK: StaticAssertDecl | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} '_Bool' <IntegralToBoolean> | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'int' '==' | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'float' '*' FPEvalMethod=0 | ||
// CHECK-NEXT: FloatingLiteral | ||
// CHECK-NEXT: FloatingLiteral | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters