https://github.com/hkleynhans created https://github.com/llvm/llvm-project/pull/178479
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. >From 722ec904999f402cf15f695ab1c3c65573542530 Mon Sep 17 00:00:00 2001 From: Henry Kleynhans <[email protected]> Date: Wed, 28 Jan 2026 18:17:04 +0000 Subject: [PATCH] [clang] add test for ISO-C n3605 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. --- clang/test/C/C2y/n3605.c | 50 ++++++++++++++++++++++++++++++++++++++ clang/test/C/C2y/n3605_1.c | 3 +++ clang/www/c_status.html | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 clang/test/C/C2y/n3605.c create mode 100644 clang/test/C/C2y/n3605_1.c 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> _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
