[clang] [C2y] Claim partial conformance to WG14 N3244 (PR #98525)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 11 13:08:49 PDT 2024


https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/98525

>From 4de208a88fb57a7d94bfa6ed391f04af9cf6b996 Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aaron at aaronballman.com>
Date: Thu, 11 Jul 2024 15:22:15 -0400
Subject: [PATCH 1/2] [C2y] Claim partial conformance to WG14 N3244

This paper had several changes within it, and Clang implements some of
the changes, but not others. This updates the status accordingly.
---
 clang/test/C/C2y/n3244.c | 65 ++++++++++++++++++++++++++++++++++++++++
 clang/www/c_status.html  | 10 ++++++-
 2 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/C/C2y/n3244.c

diff --git a/clang/test/C/C2y/n3244.c b/clang/test/C/C2y/n3244.c
new file mode 100644
index 0000000000000..f03533f93340f
--- /dev/null
+++ b/clang/test/C/C2y/n3244.c
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -std=c2y %s -verify -Wno-gnu-alignof-expression
+
+/* WG14 N3244: Partial
+ * Slay Some Earthly Demons I
+ *
+ * NB: the committee adopted:
+ *   Annex J Item 21 (including additional change) -- no, we lack explicit documentation
+ *   Annex J Item 56 -- yes
+ *   Annex J Item 57 Option 1 -- yes
+ *   Annex J Item 67 -- no
+ *   Annex J Item 69 (alternative wording for semantics) -- no
+ */
+
+void reg_array(void) {
+  // Decay of an array with the register storage class specifier has gone from
+  // explicit undefined behavior to be implementation defined instead. Clang
+  // does not support this.
+  register int array[10];
+  (void)sizeof(array); // okay
+  int *vp = array;    // expected-error {{address of register variable requested}}
+  int val = array[0]; // expected-error {{address of register variable requested}}
+}
+
+struct F;  // expected-note {{forward declaration of 'struct F'}}
+void incomplete_no_linkage(struct F); // okay
+void incomplete_no_linkage(struct F f) { // expected-error {{variable has incomplete type 'struct F'}}
+  struct G g; // expected-error {{variable has incomplete type 'struct G'}} \
+                 expected-note {{forward declaration of 'struct G'}}
+  int i[];    // expected-error {{definition of variable with array type needs an explicit size or an initializer}}
+}
+
+void block_scope_non_extern_func_decl(void) {
+  static void f(void); // expected-error {{function declared in block scope cannot have 'static' storage class}}
+  extern void g(void); // okay
+  __private_extern__ void h(void); // okay
+}
+
+// FIXME: this function should be diagnosed as it is never defined in the TU.
+extern inline void never_defined_extern_inline(void);
+
+// While this declaration is fine because the function is defined within the TU.
+extern inline void is_defined_extern_inline(void);
+extern inline void is_defined_extern_inline(void) {}
+
+int NoAlignmentOnOriginalDecl;
+// FIXME: the original declaration has no alignment specifier, so the
+// declaration below should be diagnosed due to the incompatible alignment
+// specifier.
+_Alignas(8) int NoAlignmentOnOriginalDecl;
+_Static_assert(_Alignof(NoAlignmentOnOriginalDecl) == 8, "");
+
+_Alignas(8) int AlignmentOnOriginalDecl;
+// FIXME: this should be accepted because the redeclaration has no alignment
+// specifier.
+int AlignmentOnOriginalDecl; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}
+_Static_assert(_Alignof(AlignmentOnOriginalDecl) == 8, "");
+
+long long CompatibleAlignment;
+_Static_assert(_Alignof(CompatibleAlignment) == _Alignof(long long), "");
+_Alignas(_Alignof(long long)) long long CompatibleAlignment; // Okay, alignment is the same as the implied alignment
+
+_Alignas(_Alignof(long long)) long long CompatibleAlignment2;
+// FIXME: this should be accepted because the redeclaration has no alignment
+// specifier.
+long long CompatibleAlignment2; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}
diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index 890ac1cd92286..1b0cf4065019e 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -1265,7 +1265,7 @@ <h2 id="c2y">C2y implementation status</h2>
     <tr>
       <td>Slay some earthly demons I</td>
       <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3244.pdf">N3244</a></td>
-      <td class="unknown" align="center">Unknown</td>
+      <td class="partial" align="center">
       <!-- Voted in:
              Annex J Item 21 (including additional change)
              Annex J Item 56
@@ -1273,6 +1273,14 @@ <h2 id="c2y">C2y implementation status</h2>
              Annex J Item 67
              Annex J Item 69 (alternative wording for semantics)
       -->
+        <details><summary>Partial</summary>
+          Clang does not document the implementation-defined behavior for decay
+          of an array with the register storage class specifier. Clang does not
+          diagnose an <code>extern inline</code> function with no definition in
+          the TU. Clang accepts and rejects redeclarations with/without an
+          alignment specifier, depending on the order of the declarations.
+        </details>
+      </td>
     </tr>
     <tr>
       <td>Support ++ and -- on complex values</td>

>From 26320b2c23958934f616ebda51f33322303552b2 Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aaron at aaronballman.com>
Date: Thu, 11 Jul 2024 16:07:38 -0400
Subject: [PATCH 2/2] More test cases

---
 clang/test/C/C2y/n3244.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/clang/test/C/C2y/n3244.c b/clang/test/C/C2y/n3244.c
index f03533f93340f..c1f62d59d2690 100644
--- a/clang/test/C/C2y/n3244.c
+++ b/clang/test/C/C2y/n3244.c
@@ -49,7 +49,7 @@ int NoAlignmentOnOriginalDecl;
 _Alignas(8) int NoAlignmentOnOriginalDecl;
 _Static_assert(_Alignof(NoAlignmentOnOriginalDecl) == 8, "");
 
-_Alignas(8) int AlignmentOnOriginalDecl;
+_Alignas(8) int AlignmentOnOriginalDecl; // expected-note {{declared with '_Alignas' attribute here}}
 // FIXME: this should be accepted because the redeclaration has no alignment
 // specifier.
 int AlignmentOnOriginalDecl; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}
@@ -59,7 +59,25 @@ long long CompatibleAlignment;
 _Static_assert(_Alignof(CompatibleAlignment) == _Alignof(long long), "");
 _Alignas(_Alignof(long long)) long long CompatibleAlignment; // Okay, alignment is the same as the implied alignment
 
-_Alignas(_Alignof(long long)) long long CompatibleAlignment2;
+_Alignas(_Alignof(long long)) long long CompatibleAlignment2; // expected-note {{declared with '_Alignas' attribute here}}
 // FIXME: this should be accepted because the redeclaration has no alignment
 // specifier.
 long long CompatibleAlignment2; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}
+
+// FIXME: this should be accepted because the definition specifies the
+// alignment and a subsequent declaration does not specify any alignment.
+_Alignas(8) long long DefnWithInit = 12; // expected-note {{declared with '_Alignas' attribute here}}
+long long DefnWithInit; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}
+
+// This is accepted because the definition has an alignment specifier and the
+// subsequent redeclaration does not specify an alignment.
+_Alignas(8) long long DefnWithInit2 = 12;
+extern long long DefnWithInit2;
+
+// FIXME: this should be accepted because the definition specifies the
+// alignment and a subsequent declaration specifies a compatible alignment.
+long long DefnWithInit3 = 12; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}
+_Alignas(_Alignof(long long)) long long DefnWithInit3; // expected-note {{declared with '_Alignas' attribute here}}
+
+_Alignas(8) int Mismatch;  // expected-note {{previous declaration is here}}
+_Alignas(16) int Mismatch; // expected-error {{redeclaration has different alignment requirement (16 vs 8)}}



More information about the cfe-commits mailing list