Skip to content

Commit 527a624

Browse files
committed
[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.
1 parent d2f6846 commit 527a624

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

clang/test/C/C11/n1365.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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((float)(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+
}

clang/www/c_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ <h2 id="c11">C11 implementation status</h2>
471471
<tr>
472472
<td>Constant expressions</td>
473473
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1365.htm">N1365</a></td>
474-
<td class="unknown" align="center">Unknown</td>
474+
<td class="Clang 16" align="center">Full</td>
475475
</tr>
476476
<tr>
477477
<td>Contractions and expression evaluation methods</td>

0 commit comments

Comments
 (0)