Author: Henry Kleynhans Date: 2026-01-30T08:04:23-05:00 New Revision: 5bd8dadb899d257b82db84e782a0982a2c838b70
URL: https://github.com/llvm/llvm-project/commit/5bd8dadb899d257b82db84e782a0982a2c838b70 DIFF: https://github.com/llvm/llvm-project/commit/5bd8dadb899d257b82db84e782a0982a2c838b70.diff LOG: clang: add test for C2y n3605 (#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. Added: clang/test/C/C2y/n3605.c clang/test/C/C2y/n3605_1.c clang/test/C/C2y/n3605_2.c Modified: clang/www/c_status.html Removed: ################################################################################ diff --git a/clang/test/C/C2y/n3605.c b/clang/test/C/C2y/n3605.c new file mode 100644 index 0000000000000..f04ec557ddc11 --- /dev/null +++ b/clang/test/C/C2y/n3605.c @@ -0,0 +1,57 @@ +// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s +// RUN: %clang_cc1 -verify -std=c23 -Wall -pedantic %s +// RUN: %clang_cc1 -verify -std=c17 -Wall -pedantic %s +// RUN: %clang_cc1 -verify -std=c11 -Wall -pedantic %s +// expected-no-diagnostics +// RUN: %clang_cc1 -std=c2y %s -triple x86_64 --embed-dir=%S/Inputs -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -std=c23 %s -triple x86_64 --embed-dir=%S/Inputs -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -std=c17 %s -triple x86_64 --embed-dir=%S/Inputs -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -std=c11 %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))) }; + +int c = _Generic((float*)0, default: 0); +int d = _Generic((float*)0, default: (sizeof(c))); + +char s[] = _Generic(0, default: ("word")); + +int value_of_a(void) { + // CHECK: ret i32 2 + return a; +} + +int value_of_b(void) { + // CHECK: ret i32 3 + return b; +} + +int value_of_c(void) { + // CHECK: %0 = load i32, ptr @c, align 4 + // CHECK: ret i32 %0 + return c; +} + +int value_of_d(void) { + // CHECK: %0 = load i32, ptr @d, align 4 + // CHECK: ret i32 %0 + return d; +} + +char *value_of_s(void) { + // CHECK: ret ptr @s + return s; +} + +float value_of_float(void) { + // 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(); +} + + diff --git a/clang/test/C/C2y/n3605_1.c b/clang/test/C/C2y/n3605_1.c new file mode 100644 index 0000000000000..ee33beadeaadd --- /dev/null +++ b/clang/test/C/C2y/n3605_1.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s +// RUN: %clang_cc1 -verify -std=c23 -Wall -pedantic %s +// expected-no-diagnostics +// RUN: %clang_cc1 -std=c2y %s -triple x86_64 --embed-dir=%S/Inputs -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -std=c23 %s -triple x86_64 --embed-dir=%S/Inputs -emit-llvm -o - | FileCheck %s + +constexpr int a = _Generic((float*)0, default: 0); +constexpr int b = _Generic((float*)0, default: (sizeof(a))); + +int value_of_a(void) { + // CHECK: ret i32 0 + return a; +} + +int value_of_b(void) { + // CHECK: ret i32 4 + return b; +} + diff --git a/clang/test/C/C2y/n3605_2.c b/clang/test/C/C2y/n3605_2.c new file mode 100644 index 0000000000000..cb336ab9af7fa --- /dev/null +++ b/clang/test/C/C2y/n3605_2.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s +// RUN: %clang_cc1 -verify -std=c23 -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
