llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Henry Kleynhans (hkleynhans)

<details>
<summary>Changes</summary>

Add a test for N3605: Generic replacement (v. 2 of quasi-literals)

The paper clarifies existing behavior of _Generic selection and parenthesis.  
This PR adds tests along the same lines and mark the feature as supported.

---
Full diff: https://github.com/llvm/llvm-project/pull/178479.diff


3 Files Affected:

- (added) clang/test/C/C2y/n3605.c (+50) 
- (added) clang/test/C/C2y/n3605_1.c (+3) 
- (modified) clang/www/c_status.html (+1-1) 


``````````diff
diff --git a/clang/test/C/C2y/n3605.c b/clang/test/C/C2y/n3605.c
new file mode 100644
index 0000000000000..a8eaf34a37d3a
--- /dev/null
+++ b/clang/test/C/C2y/n3605.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s
+// expected-no-diagnostics
+// RUN: %clang_cc1 -std=c2y %s -triple x86_64 --embed-dir=%S/Inputs -emit-llvm 
-o - | FileCheck %s
+
+enum A{ a=(int)(_Generic(0, int: (2.5))) };
+enum B{ b=(int)(_Generic(0, int: (2 + 1))) };
+
+constexpr int c  = _Generic((float*)0, default: 0);
+
+constexpr int d = _Generic((float*)0, default: (sizeof(c)));
+
+char s[] = _Generic(0, default: ("word"));
+
+// static_assert(1, _Generic(1, default: "Error Message"));
+
+int value_of_a() {
+       // CHECK: ret i32 2
+       return a;
+}
+
+int value_of_b() {
+       // CHECK: ret i32 3
+       return b;
+}
+
+int value_of_c() {
+       // CHECK: ret i32 0
+       return c;
+}
+
+int value_of_d() {
+       // CHECK: ret i32 4
+       return d;
+}
+
+char *value_of_s() {
+       // CHECK: ret ptr @s
+    return s;
+}
+
+float value_of_float() {
+       // CHECK: %f = alloca ptr, align 8
+       // CHECK: store ptr null, ptr %f, align 8
+       // CHECK: %0 = load ptr, ptr %f, align 8
+       // CHECK: %call = call float %0()
+       // CHECK: ret float %call
+
+       float (*f)(void)  = _Generic(1, default: (void*)0);
+       return f();
+}
\ No newline at end of file
diff --git a/clang/test/C/C2y/n3605_1.c b/clang/test/C/C2y/n3605_1.c
new file mode 100644
index 0000000000000..3e0975d338c6f
--- /dev/null
+++ b/clang/test/C/C2y/n3605_1.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s
+
+static_assert(1, _Generic(1, default: "Error Message"));  // 
expected-error{{expected string literal for diagnostic message in 
static_assert}}
diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index ccf19ea86957a..6c920773aba61 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -354,7 +354,7 @@ <h2 id="c2y">C2y implementation status</h2>
     <tr>
       <td>Generic replacement (v. 2 of quasi-literals)</td>
       <td><a 
href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3605.pdf";>N3605</a></td>
-      <td class="unknown" align="center">Unknown</td>
+      <td class="full" align="center">Yes</td>
        </tr>
     <tr>
       <td>Member access of an incomplete object</td>

``````````

</details>


https://github.com/llvm/llvm-project/pull/178479
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to