Skip to content

Commit 0913547

Browse files
authored
[C2y] Claim partial conformance to WG14 N3244 (#98525)
This paper had several changes within it, and Clang implements some of the changes, but not others. This updates the status accordingly.
1 parent 1bad702 commit 0913547

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

clang/test/C/C2y/n3244.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// RUN: %clang_cc1 -std=c2y %s -verify -Wno-gnu-alignof-expression
2+
3+
/* WG14 N3244: Partial
4+
* Slay Some Earthly Demons I
5+
*
6+
* NB: the committee adopted:
7+
* Annex J Item 21 (including additional change) -- no, we lack explicit documentation
8+
* Annex J Item 56 -- yes
9+
* Annex J Item 57 Option 1 -- yes
10+
* Annex J Item 67 -- no
11+
* Annex J Item 69 (alternative wording for semantics) -- no
12+
*/
13+
14+
void reg_array(void) {
15+
// Decay of an array with the register storage class specifier has gone from
16+
// explicit undefined behavior to be implementation defined instead. Clang
17+
// does not support this.
18+
register int array[10];
19+
(void)sizeof(array); // okay
20+
int *vp = array; // expected-error {{address of register variable requested}}
21+
int val = array[0]; // expected-error {{address of register variable requested}}
22+
}
23+
24+
struct F; // expected-note {{forward declaration of 'struct F'}}
25+
void incomplete_no_linkage(struct F); // okay
26+
void incomplete_no_linkage(struct F f) { // expected-error {{variable has incomplete type 'struct F'}}
27+
struct G g; // expected-error {{variable has incomplete type 'struct G'}} \
28+
expected-note {{forward declaration of 'struct G'}}
29+
int i[]; // expected-error {{definition of variable with array type needs an explicit size or an initializer}}
30+
}
31+
32+
void block_scope_non_extern_func_decl(void) {
33+
static void f(void); // expected-error {{function declared in block scope cannot have 'static' storage class}}
34+
extern void g(void); // okay
35+
__private_extern__ void h(void); // okay
36+
}
37+
38+
// FIXME: this function should be diagnosed as it is never defined in the TU.
39+
extern inline void never_defined_extern_inline(void);
40+
41+
// While this declaration is fine because the function is defined within the TU.
42+
extern inline void is_defined_extern_inline(void);
43+
extern inline void is_defined_extern_inline(void) {}
44+
45+
int NoAlignmentOnOriginalDecl;
46+
// FIXME: the original declaration has no alignment specifier, so the
47+
// declaration below should be diagnosed due to the incompatible alignment
48+
// specifier.
49+
_Alignas(8) int NoAlignmentOnOriginalDecl;
50+
_Static_assert(_Alignof(NoAlignmentOnOriginalDecl) == 8, "");
51+
52+
_Alignas(8) int AlignmentOnOriginalDecl; // expected-note {{declared with '_Alignas' attribute here}}
53+
// FIXME: this should be accepted because the redeclaration has no alignment
54+
// specifier.
55+
int AlignmentOnOriginalDecl; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}
56+
_Static_assert(_Alignof(AlignmentOnOriginalDecl) == 8, "");
57+
58+
long long CompatibleAlignment;
59+
_Static_assert(_Alignof(CompatibleAlignment) == _Alignof(long long), "");
60+
_Alignas(_Alignof(long long)) long long CompatibleAlignment; // Okay, alignment is the same as the implied alignment
61+
62+
_Alignas(_Alignof(long long)) long long CompatibleAlignment2; // expected-note {{declared with '_Alignas' attribute here}}
63+
// FIXME: this should be accepted because the redeclaration has no alignment
64+
// specifier.
65+
long long CompatibleAlignment2; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}
66+
67+
// FIXME: this should be accepted because the definition specifies the
68+
// alignment and a subsequent declaration does not specify any alignment.
69+
_Alignas(8) long long DefnWithInit = 12; // expected-note {{declared with '_Alignas' attribute here}}
70+
long long DefnWithInit; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}
71+
72+
// This is accepted because the definition has an alignment specifier and the
73+
// subsequent redeclaration does not specify an alignment.
74+
_Alignas(8) long long DefnWithInit2 = 12;
75+
extern long long DefnWithInit2;
76+
77+
// FIXME: this should be accepted because the definition specifies the
78+
// alignment and a subsequent declaration specifies a compatible alignment.
79+
long long DefnWithInit3 = 12; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}
80+
_Alignas(_Alignof(long long)) long long DefnWithInit3; // expected-note {{declared with '_Alignas' attribute here}}
81+
82+
_Alignas(8) int Mismatch; // expected-note {{previous declaration is here}}
83+
_Alignas(16) int Mismatch; // expected-error {{redeclaration has different alignment requirement (16 vs 8)}}

clang/www/c_status.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,14 +1265,22 @@ <h2 id="c2y">C2y implementation status</h2>
12651265
<tr>
12661266
<td>Slay some earthly demons I</td>
12671267
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3244.pdf">N3244</a></td>
1268-
<td class="unknown" align="center">Unknown</td>
1268+
<td class="partial" align="center">
12691269
<!-- Voted in:
12701270
Annex J Item 21 (including additional change)
12711271
Annex J Item 56
12721272
Annex J Item 57 Option 1
12731273
Annex J Item 67
12741274
Annex J Item 69 (alternative wording for semantics)
12751275
-->
1276+
<details><summary>Partial</summary>
1277+
Clang does not document the implementation-defined behavior for decay
1278+
of an array with the register storage class specifier. Clang does not
1279+
diagnose an <code>extern inline</code> function with no definition in
1280+
the TU. Clang accepts and rejects redeclarations with/without an
1281+
alignment specifier, depending on the order of the declarations.
1282+
</details>
1283+
</td>
12761284
</tr>
12771285
<tr>
12781286
<td>Support ++ and -- on complex values</td>

0 commit comments

Comments
 (0)