Skip to content

Commit 7fc57d7

Browse files
committed
Add more tests for C DRs and update the status page
1 parent f01b68e commit 7fc57d7

File tree

7 files changed

+269
-16
lines changed

7 files changed

+269
-16
lines changed

clang/test/C/drs/dr464.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* RUN: %clang_cc1 -std=c89 -verify -pedantic -Wno-c11-extensions %s
2+
RUN: %clang_cc1 -std=c99 -verify -pedantic -Wno-c11-extensions %s
3+
RUN: %clang_cc1 -std=c11 -verify -pedantic %s
4+
RUN: %clang_cc1 -std=c17 -verify -pedantic %s
5+
RUN: %clang_cc1 -std=c2x -verify -pedantic %s
6+
*/
7+
8+
/* expected-no-diagnostics */
9+
10+
/* WG14 DR464: yes
11+
* Clarifying the Behavior of the #line Directive
12+
*
13+
* Note: the behavior described by this DR allows for two different
14+
* interpretations, but WG14 N2322 (adopted for C2x) adds a recommended
15+
* practice which is what we're testing our interpretation against.
16+
*/
17+
#line 10000
18+
_Static_assert(__LI\
19+
NE__ == 10000, "");

clang/test/C/drs/dr466.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* RUN: %clang_cc1 -std=c89 -Wno-gcc-compat -ast-dump -o - %s | FileCheck %s
2+
RUN: %clang_cc1 -std=c99 -ast-dump -o - %s | FileCheck %s
3+
RUN: %clang_cc1 -std=c11 -ast-dump -o - %s | FileCheck %s
4+
RUN: %clang_cc1 -std=c17 -ast-dump -o - %s | FileCheck %s
5+
RUN: %clang_cc1 -std=c2x -ast-dump -o - %s | FileCheck %s
6+
*/
7+
8+
/* WG14 DR466: yes
9+
* Scope of a for loop control declaration
10+
*/
11+
int dr466(void) {
12+
for (int i = 0; ; ) {
13+
long i = 1; /* valid C, invalid C++ */
14+
// ...
15+
return i; /* (perhaps unexpectedly) returns 1 in C */
16+
}
17+
}
18+
19+
/*
20+
CHECK: FunctionDecl 0x{{.+}} dr466 'int (void)'
21+
CHECK-NEXT: CompoundStmt
22+
CHECK-NEXT: ForStmt
23+
CHECK-NEXT: DeclStmt
24+
CHECK-NEXT: VarDecl 0x{{.+}} {{.+}} i 'int'
25+
CHECK: CompoundStmt
26+
CHECK-NEXT: DeclStmt
27+
CHECK-NEXT: VarDecl [[ACTUAL:0x.+]] <col:{{.+}}> col:{{.+}} used i 'long'
28+
CHECK: ReturnStmt
29+
CHECK: DeclRefExpr 0x{{.+}} <col:{{.+}}> 'long' lvalue Var [[ACTUAL]] 'i' 'long'
30+
*/

clang/test/C/drs/dr483.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* RUN: %clang_cc1 -std=c89 -verify -pedantic -Wno-c11-extensions %s
2+
RUN: %clang_cc1 -std=c99 -verify -pedantic -Wno-c11-extensions %s
3+
RUN: %clang_cc1 -std=c11 -verify -pedantic %s
4+
RUN: %clang_cc1 -std=c17 -verify -pedantic %s
5+
RUN: %clang_cc1 -std=c2x -verify -pedantic %s
6+
*/
7+
8+
/* expected-no-diagnostics */
9+
10+
/* WG14 DR483: yes
11+
* __LINE__ and __FILE__ in macro replacement list
12+
*
13+
* The crux of this DR is to ensure that __LINE__ (and __FILE__) use in a macro
14+
* replacement list report the line and file of the expansion of that macro,
15+
* not the line and file of the macro definition itself.
16+
*/
17+
#line 500
18+
#define MAC() __LINE__
19+
20+
#line 1000
21+
_Static_assert(MAC() == 1000, "");
22+

clang/test/C/drs/dr491.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* RUN: %clang_cc1 -std=c89 -verify -Wreserved-macro-identifier %s
2+
RUN: %clang_cc1 -std=c99 -verify -Wreserved-macro-identifier %s
3+
RUN: %clang_cc1 -std=c11 -verify -Wreserved-macro-identifier %s
4+
RUN: %clang_cc1 -std=c17 -verify -Wreserved-macro-identifier %s
5+
RUN: %clang_cc1 -std=c2x -verify -Wreserved-macro-identifier %s
6+
*/
7+
8+
/* WG14 DR491: partial
9+
* Concern with Keywords that Match Reserved Identifiers
10+
*
11+
* Claiming this as partial because we do not reject code using a reserved
12+
* identifier, but our reserved identifier code incorrectly identifies some
13+
* keywords as reserved identifiers for macro names, but not others.
14+
*/
15+
16+
#define const const
17+
#define int int
18+
#define restrict restrict
19+
20+
/* FIXME: none of these should diagnose the macro name as a reserved
21+
* identifier per C2x 6.4.2p7 (similar wording existed in earlier standard
22+
* versions).
23+
*/
24+
#define _Static_assert _Static_assert /* expected-warning {{macro name is a reserved identifier}} */
25+
#define _Alignof(x) _Alignof(x) /* expected-warning {{macro name is a reserved identifier}} */
26+
#define _Bool _Bool /* expected-warning {{macro name is a reserved identifier}} */
27+
#define __has_c_attribute __has_c_attribute /* expected-warning {{macro name is a reserved identifier}}
28+
expected-warning {{redefining builtin macro}}
29+
*/
30+
#define __restrict__ __restrict__ /* expected-warning {{macro name is a reserved identifier}} */

clang/test/C/drs/dr494.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* RUN: %clang_cc1 -std=c89 %s -emit-llvm -o - | FileCheck %s
2+
RUN: %clang_cc1 -std=c99 %s -emit-llvm -o - | FileCheck %s
3+
RUN: %clang_cc1 -std=c11 %s -emit-llvm -o - | FileCheck %s
4+
RUN: %clang_cc1 -std=c17 %s -emit-llvm -o - | FileCheck %s
5+
RUN: %clang_cc1 -std=c2x %s -emit-llvm -o - | FileCheck %s
6+
*/
7+
8+
/* WG14 DR494: yes
9+
* Part 1: Alignment specifier expression evaluation
10+
*/
11+
void dr494(void) {
12+
int i = 12;
13+
int j = _Alignof(int [++i]);
14+
int k = sizeof(int [++i]);
15+
/* Check that we store a straight value for i and j, but have to calculate a
16+
* value for storing into k. That's because sizeof() needs to execute code to
17+
* get the correct value from a VLA, but _Alignof is not allowed to execute
18+
* the VLA extent at runtime.
19+
*/
20+
/* CHECK: %[[I:.+]] = alloca i32
21+
CHECK: %[[J:.+]] = alloca i32
22+
CHECK: %[[K:.+]] = alloca i32
23+
CHECK: store i32 12, ptr %[[I]]
24+
CHECK: store i32 4, ptr %[[J]]
25+
CHECK: %[[ZERO:.+]] = load i32, ptr %[[I]]
26+
CHECK: %[[INC:.+]] = add nsw i32 %[[ZERO]], 1
27+
CHECK: store i32 %[[INC]], ptr %[[I]]
28+
*/
29+
}
30+

clang/test/C/drs/dr4xx.c

Lines changed: 119 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@
6060
*
6161
* WG14 DR459: yes
6262
* atomic_load missing const qualifier
63+
*
64+
* WG14 DR475: yes
65+
* Misleading Atomic library references to atomic types
66+
*
67+
* WG14 DR485: yes
68+
* Problem with the specification of ATOMIC_VAR_INIT
69+
*
70+
* WG14 DR486: yes
71+
* Inconsistent specification for arithmetic on atomic objects
72+
*
73+
* WG14 DR490: yes
74+
* Unwritten Assumptions About if-then
6375
*/
6476

6577
/* WG14 DR412: yes
@@ -201,13 +213,112 @@ void dr463(void) {
201213
(void)(1 << ((__CHAR_BIT__ * sizeof(int)) - 1));
202214
}
203215

204-
/* WG14 DR464: yes
205-
* Clarifying the Behavior of the #line Directive
216+
/* WG14 DR478: yes
217+
* Valid uses of the main function
218+
*/
219+
int main(void) {
220+
/* This DR clarifies that C explicitly allows you to call main() in a hosted
221+
* environment; it is not special as it is in C++, so recursive calls are
222+
* fine as well as nonrecursive direct calls.
223+
*/
224+
main(); /* ok */
225+
}
226+
227+
void dr478(void) {
228+
int (*fp)(void) = main; /* ok */
229+
main(); /* ok */
230+
}
231+
232+
/* WG14 DR481: yes
233+
* Controlling expression of _Generic primary expression
234+
*/
235+
void dr481(void) {
236+
/* The controlling expression undergoes lvalue to rvalue conversion, and that
237+
* performs array decay and strips qualifiers.
238+
*/
239+
(void)_Generic("bla", char *: "blu");
240+
(void)_Generic((int const){ 0 }, int: "blu"); /* c89only-warning {{compound literals are a C99-specific feature}} */
241+
(void)_Generic(+(int const){ 0 }, int: "blu"); /* c89only-warning {{compound literals are a C99-specific feature}} */
242+
243+
(void)_Generic("bla", /* expected-error {{controlling expression type 'char *' not compatible with any generic association type}} */
244+
char[4]: "blu"); /* expected-warning {{due to lvalue conversion of the controlling expression, association of type 'char[4]' will never be selected because it is of array type}} */
245+
246+
(void)_Generic((int const){ 0 }, /* expected-error {{controlling expression type 'int' not compatible with any generic association type}}
247+
c89only-warning {{compound literals are a C99-specific feature}}
248+
*/
249+
int const: "blu"); /* expected-warning {{due to lvalue conversion of the controlling expression, association of type 'const int' will never be selected because it is qualified}} */
250+
251+
(void)_Generic(+(int const){ 0 }, /* expected-error {{controlling expression type 'int' not compatible with any generic association type}}
252+
c89only-warning {{compound literals are a C99-specific feature}}
253+
*/
254+
int const: "blu"); /* expected-warning {{due to lvalue conversion of the controlling expression, association of type 'const int' will never be selected because it is qualified}} */
255+
}
256+
257+
/* WG14 DR489: partial
258+
* Integer Constant Expression
206259
*
207-
* Note: the behavior described by this DR allows for two different
208-
* interpretations, but WG14 N2322 (adopted for C2x) adds a recommended
209-
* practice which is what we're testing our interpretation against.
260+
* The DR is about whether unevaluated operands have to follow the same
261+
* restrictions as the rest of the expression in an ICE, and according to the
262+
* committee, they do.
263+
*/
264+
void dr489(void) {
265+
struct S {
266+
int bit : 12 || 1.0f; /* expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}} */
267+
};
268+
enum E {
269+
Val = 0 && 1.0f /* expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}} */
270+
};
271+
272+
int i;
273+
274+
/* FIXME: mentioning the 'aligned' attribute is confusing, but also, should
275+
* this be folded as an ICE as a GNU extension? GCC does not fold it.
276+
*/
277+
_Alignas(0 ? i++ : 8) char c; /* expected-error {{'aligned' attribute requires integer constant}} */
278+
279+
/* FIXME: this should get the constant folding diagnostic as this is not a
280+
* valid ICE because the floating-point constants are not the immediate
281+
* operand of a cast. It should then also get a diagnostic about trying to
282+
* declare a VLA with static storage duration and the C99 extension warning
283+
* for VLAs in C89.
284+
*/
285+
static int vla[sizeof(1.0f + 1.0f)];
286+
287+
int val[5] = { [1 ? 0 : i--] = 12 }; /* expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
288+
c89only-warning {{designated initializers are a C99 feature}}
289+
*/
290+
291+
/* FIXME: this should be the constant folding diagnostic as this is not a
292+
* valid ICE because of the / operator.
293+
*/
294+
_Static_assert(sizeof(0 / 0), "");
295+
296+
/* FIXME: this should also get the constant folding diagnostic as this is not
297+
* a valid ICE because of the = operator.
298+
*/
299+
(void)_Generic(i = 12, int : 0); /* expected-warning {{expression with side effects has no effect in an unevaluated context}} */
300+
301+
switch (i) {
302+
case (int)0.0f: break; /* okay, a valid ICE */
303+
304+
/* FIXME: this should be accepted in C2x and up without a diagnostic, as C23
305+
* added compound literals to the allowed list of things in an ICE. The
306+
* diagnostic is correct for C17 and earlier though.
307+
*/
308+
case (int){ 2 }: break; /* expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
309+
c89only-warning {{compound literals are a C99-specific feature}}
310+
*/
311+
case 12 || main(): break; /* expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}} */
312+
}
313+
}
314+
315+
/* WG14 DR492: yes
316+
* Named Child struct-union with no Member
210317
*/
211-
#line 10000
212-
_Static_assert(__LI\
213-
NE__ == 10000, "");
318+
struct dr492_t {
319+
union U11 { /* expected-warning {{declaration does not declare anything}} */
320+
int m11;
321+
float m12;
322+
};
323+
int m13;
324+
} dr492;

clang/www/c_dr_status.html

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,7 +2441,7 @@ <h2 id="cdr">C defect report implementation status</h2>
24412441
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_466">466</a></td>
24422442
<td>NAD</td>
24432443
<td>Scope of a for loop control declaration</td>
2444-
<td class="unknown" align="center">Unknown</td>
2444+
<td class="full" align="center">Yes</td>
24452445
</tr>
24462446
<tr id="467">
24472447
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_467">467</a></td>
@@ -2513,7 +2513,7 @@ <h2 id="cdr">C defect report implementation status</h2>
25132513
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_478">478</a></td>
25142514
<td>NAD</td>
25152515
<td>Valid uses of the main function</td>
2516-
<td class="unknown" align="center">Unknown</td>
2516+
<td class="full" align="center">Yes</td>
25172517
</tr>
25182518
<tr id="479">
25192519
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_479">479</a></td>
@@ -2531,7 +2531,7 @@ <h2 id="cdr">C defect report implementation status</h2>
25312531
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_481">481</a></td>
25322532
<td>C11</td>
25332533
<td>Controlling expression of _Generic primary expression</td>
2534-
<td class="unknown" align="center">Unknown</td>
2534+
<td class="full" align="center">Clang 3.8</td>
25352535
</tr>
25362536
<tr id="482">
25372537
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_482">482</a></td>
@@ -2543,7 +2543,7 @@ <h2 id="cdr">C defect report implementation status</h2>
25432543
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_483">483</a></td>
25442544
<td>NAD</td>
25452545
<td>__LINE__ and __FILE__ in macro replacement list</td>
2546-
<td class="unknown" align="center">Unknown</td>
2546+
<td class="full" align="center">Yes</td>
25472547
</tr>
25482548
<tr id="484">
25492549
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_484">484</a></td>
@@ -2579,7 +2579,12 @@ <h2 id="cdr">C defect report implementation status</h2>
25792579
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_489">489</a></td>
25802580
<td>NAD</td>
25812581
<td>Integer Constant Expression</td>
2582-
<td class="unknown" align="center">Unknown</td>
2582+
<td class="partial" align="center">
2583+
<details><summary>Partial</summary>
2584+
Clang inconsistently diagnoses folding a constan expression into an ICE
2585+
as an extension.
2586+
</details>
2587+
</td>
25832588
</tr>
25842589
<tr id="490">
25852590
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_490">490</a></td>
@@ -2591,13 +2596,19 @@ <h2 id="cdr">C defect report implementation status</h2>
25912596
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_491">491</a></td>
25922597
<td>C11</td>
25932598
<td>Concern with Keywords that Match Reserved Identifiers</td>
2594-
<td class="unknown" align="center">Unknown</td>
2599+
<td class="partial" align="center">
2600+
<details><summary>Partial</summary>
2601+
Clang issues a reserved identifier diagnostic when the identifier leads
2602+
with an underscore followed by a capital letter or double underscores,
2603+
even if the identifier is used for a macro definition.
2604+
</details>
2605+
</td>
25952606
</tr>
25962607
<tr id="492">
25972608
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_492">492</a></td>
25982609
<td>NAD</td>
25992610
<td>Named Child struct-union with no Member</td>
2600-
<td class="unknown" align="center">Unknown</td>
2611+
<td class="full" align="center">Clang 3.6</td>
26012612
</tr>
26022613
<tr id="493">
26032614
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_493">493</a></td>
@@ -2609,7 +2620,7 @@ <h2 id="cdr">C defect report implementation status</h2>
26092620
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_494">494</a></td>
26102621
<td>C11</td>
26112622
<td>Part 1: Alignment specifier expression evaluation</td>
2612-
<td class="unknown" align="center">Unknown</td>
2623+
<td class="full" align="center">Yes</td>
26132624
</tr>
26142625
<tr class="open" id="495">
26152626
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_495">495</a></td>

0 commit comments

Comments
 (0)