Skip to content

[C2y] Claim partial conformance to WG14 N3244 #98525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

AaronBallman
Copy link
Collaborator

This paper had several changes within it, and Clang implements some of the changes, but not others. This updates the status accordingly.

This paper had several changes within it, and Clang implements some of
the changes, but not others. This updates the status accordingly.
@AaronBallman AaronBallman added documentation clang:frontend Language frontend issues, e.g. anything involving "Sema" c2y labels Jul 11, 2024
@AaronBallman
Copy link
Collaborator Author

The paper in question can be found at: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3244.pdf

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2024

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

Changes

This paper had several changes within it, and Clang implements some of the changes, but not others. This updates the status accordingly.


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

2 Files Affected:

  • (added) clang/test/C/C2y/n3244.c (+65)
  • (modified) clang/www/c_status.html (+9-1)
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>

Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AaronBallman AaronBallman merged commit 0913547 into llvm:main Jul 12, 2024
7 checks passed
@AaronBallman AaronBallman deleted the aballman-wg14-n3244 branch July 12, 2024 10:54
@mgorny
Copy link
Member

mgorny commented Jul 13, 2024

The added test fails on 32-bit x86:

FAIL: Clang :: C/C2y/n3244.c (1461 of 20066)
******************** TEST 'Clang :: C/C2y/n3244.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/x/y/clang-abi_x86_32.x86/bin/clang -cc1 -internal-isystem /var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/19/include -nostdsysteminc -std=c2y /var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/clang/test/C/C2y/n3244.c -verify -Wno-gnu-alignof-expression
+ /var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/x/y/clang-abi_x86_32.x86/bin/clang -cc1 -internal-isystem /var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/19/include -nostdsysteminc -std=c2y /var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/clang/test/C/C2y/n3244.c -verify -Wno-gnu-alignof-expression
error: 'expected-error' diagnostics seen but not expected: 
  File /var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/clang/test/C/C2y/n3244.c Line 59: static assertion failed due to requirement '_Alignof (CompatibleAlignment) == _Alignof(long long)': 
error: 'expected-note' diagnostics seen but not expected: 
  File /var/tmp/portage/sys-devel/clang-19.0.0_pre20240713/work/clang/test/C/C2y/n3244.c Line 59: expression evaluates to '8 == 4'
2 errors generated.

--

********************

aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
This paper had several changes within it, and Clang implements some of
the changes, but not others. This updates the status accordingly.
@AaronBallman
Copy link
Collaborator Author

Thank you for letting me know, I've pushed a fix for that.

Curiously, it seems _Alignof on an expression always returns the preferred alignment and not the actual alignment. This is consistent with GCC, even if it's a bit surprising: https://godbolt.org/z/nvKx98ff9

@mgorny
Copy link
Member

mgorny commented Jul 15, 2024

Thanks. I can confirm that the tests pass for me with the patch applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c2y clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants