[clang] 6bc71cd - [C99] Claim partial conformance to n448
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 20 10:29:48 PDT 2024
Author: Aaron Ballman
Date: 2024-06-20T13:29:36-04:00
New Revision: 6bc71cdd32de0add80d620b1342b5549efff363a
URL: https://github.com/llvm/llvm-project/commit/6bc71cdd32de0add80d620b1342b5549efff363a
DIFF: https://github.com/llvm/llvm-project/commit/6bc71cdd32de0add80d620b1342b5549efff363a.diff
LOG: [C99] Claim partial conformance to n448
This is the paper that added the 'restrict' keyword. Clang is
conforming to the letter of the standard's requirements, so it would be
defensible for us to claim full support instead. However, LLVM does not
currently support the optimization semantics with restricted local
variables or data members, only with restricted pointers declared in
function parameters. So we're only claiming partial support because we
don't yet take full advantage of what the feature allows.
Added:
clang/test/C/C99/n448.c
Modified:
clang/www/c_status.html
Removed:
################################################################################
diff --git a/clang/test/C/C99/n448.c b/clang/test/C/C99/n448.c
new file mode 100644
index 0000000000000..c9f97920b2079
--- /dev/null
+++ b/clang/test/C/C99/n448.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -verify -std=c99 %s
+// RUN: %clang_cc1 -verify -std=c23 %s
+
+/* WG14 N448: Partial
+ * Restricted pointers
+ *
+ * NB: we claim partial conformance only because LLVM does not attempt to apply
+ * the semantics on local variables or structure data members; it only
+ * considers function parameters. However, Clang itself is fully conforming for
+ * this feature.
+ */
+
+// Restrict is only allowed on pointers.
+int * restrict ipr;
+int restrict ir; // expected-error {{restrict requires a pointer or reference ('int' is invalid)}}
+
+// Restrict only applies to object pointers.
+void (* restrict fp)(void); // expected-error {{pointer to function type 'void (void)' may not be 'restrict' qualified}}
+
+typedef int *int_ptr;
+int_ptr restrict ipr2; // okay, still applied to the pointer.
+
+// Show that the qualifer is dropped on lvalue conversion
+_Static_assert(
+ _Generic(ipr,
+ int * : 1,
+ int * restrict : 0, // expected-warning {{due to lvalue conversion of the controlling expression, association of type 'int *restrict' will never be selected because it is qualified}}
+ default : 0),
+ "");
+
+// Show that it's allowed as a qualifier for array parameters.
+void f(int array[restrict]) {
+ int *ipnr = ipr; // okay to drop the top-level qualifier
+
+ // Show that it's not okay to drop the qualifier when it's not at the top level.
+ int * restrict * restrict iprpr;
+ int **ipp = iprpr; // expected-warning {{initializing 'int **' with an expression of type 'int *restrict *restrict' discards qualifiers}}
+ int ** restrict ippr = iprpr; // expected-warning {{initializing 'int **restrict' with an expression of type 'int *restrict *restrict' discards qualifiers}}
+}
+
+#if __STDC_VERSION__ >= 202311L
+// C23 doesn't allow constexpr to mix with restrict. See C23 6.7.2p5.
+constexpr int * restrict ip; // expected-error {{constexpr variable cannot have type 'int *const restrict'}}
+#endif // __STDC_VERSION__ >= 202311L
diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index b691bcf6bee9c..715bc5f024926 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -115,7 +115,16 @@ <h2 id="c99">C99 implementation status</h2>
<tr>
<td>restricted pointers</td>
<td>N448</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="partial" align="center">
+ <details><summary>Partial</summary>
+ Clang's support for <code>restrict</code> is fully conforming but
+ considered only partially implemented. Clang implements all of the
+ constraints required for <code>restrict</code> support, but LLVM only
+ supports <code>restrict</code> optimization semantics for restricted
+ pointers used as function parameters; it does not fully support the
+ semantics for restrict on local variables or data members.
+ </details>
+ </td>
</tr>
<tr>
<td>variable length arrays</td>
More information about the cfe-commits
mailing list