[clang] 527a624 - [C11] Update the status of N1365 on constant expression handling

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 22 09:50:30 PDT 2024


Author: Aaron Ballman
Date: 2024-03-22T12:50:18-04:00
New Revision: 527a624205748814dd9309eda7ee308b40b2359a

URL: https://github.com/llvm/llvm-project/commit/527a624205748814dd9309eda7ee308b40b2359a
DIFF: https://github.com/llvm/llvm-project/commit/527a624205748814dd9309eda7ee308b40b2359a.diff

LOG: [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.

Added: 
    clang/test/C/C11/n1365.c

Modified: 
    clang/www/c_status.html

Removed: 
    


################################################################################
diff  --git a/clang/test/C/C11/n1365.c b/clang/test/C/C11/n1365.c
new file mode 100644
index 00000000000000..3f769faa365d6a
--- /dev/null
+++ b/clang/test/C/C11/n1365.c
@@ -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
+  }
+}

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 0069da74cbd56c..f00d5a6b709479 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -471,7 +471,7 @@ <h2 id="c11">C11 implementation status</h2>
     <tr>
       <td>Constant expressions</td>
       <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1365.htm">N1365</a></td>
-      <td class="unknown" align="center">Unknown</td>
+      <td class="Clang 16" align="center">Full</td>
     </tr>
     <tr>
       <td>Contractions and expression evaluation methods</td>


        


More information about the cfe-commits mailing list