Add tests for C11 DRs and update the status page

This gets a start on testing how we're doing for C11 DRs
This commit is contained in:
Aaron Ballman 2022-10-26 13:53:13 -04:00
parent b115ba0050
commit 5e676aa702
3 changed files with 185 additions and 16 deletions

33
clang/test/C/drs/dr411.c Normal file
View File

@ -0,0 +1,33 @@
/* RUN: %clang_cc1 -std=c89 -fsyntax-only -verify -DC89 -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c99 -fsyntax-only -verify -DC99 -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c11 -fsyntax-only -verify -DC11 %s
RUN: %clang_cc1 -std=c17 -fsyntax-only -verify -DC17 %s
RUN: %clang_cc1 -std=c2x -fsyntax-only -verify -DC2X %s
*/
/* expected-no-diagnostics */
/* WG14 DR411: yes
* Predefined macro values
*
* Note: the DR is about the C11 macro value, but we'll test all the standard
* version macro values just to be sure. We do not need to test
* __STDC_LIB_EXT1__ values because that requires an Annex K-compatible header.
*/
#if defined(C89)
#ifdef __STDC_VERSION__
#error "C89 didn't have this macro!"
#endif
#elif defined(C99)
_Static_assert(__STDC_VERSION__ == 199901L, "");
#elif defined(C11)
_Static_assert(__STDC_VERSION__ == 201112L, "");
#elif defined(C17)
_Static_assert(__STDC_VERSION__ == 201710L, "");
#elif defined(C2X)
/* FIXME: this value will change once WG14 picks the final value for C2x. */
_Static_assert(__STDC_VERSION__ == 202000L, "");
#else
#error "unknown language standard version"
#endif

View File

@ -1,14 +1,102 @@
/* RUN: %clang_cc1 -std=c89 -verify=expected,c89only -pedantic -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c99 -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c11 -verify=expected,c99untilc2x -pedantic %s
RUN: %clang_cc1 -std=c17 -verify=expected,c99untilc2x -pedantic %s
RUN: %clang_cc1 -std=c2x -verify=expected,c2xandup -pedantic %s
RUN: %clang_cc1 -std=c99 -verify=expected -pedantic -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c11 -verify=expected -pedantic %s
RUN: %clang_cc1 -std=c17 -verify=expected -pedantic %s
RUN: %clang_cc1 -std=c2x -verify=expected -pedantic %s
*/
/* The following are DRs which do not require tests to demonstrate
* conformance or nonconformance.
*
* WG14 DR401: yes
* "happens before" can not be cyclic
*
* WG14 DR402: yes
* Memory model coherence is not aligned with C++11
*
* WG14 DR404: yes
* Joke fragment remains in a footnote
*
* WG14 DR406: yes
* Visible sequences of side effects are redundant
*
* WG14 DR415: yes
* Missing divide by zero entry in Annex J
*
* WG14 DR417: yes
* Annex J not updated with necessary aligned_alloc entries
*
* WG14 DR419: yes
* Generic Functions
*
* WG14 DR420: yes
* Sytax error in specification of for-statement
*
* WG14 DR425: yes
* No specification for the access to variables with temporary lifetime
*
* WG14 DR434: yes
* Possible defect report: Missing constraint w.r.t. Atomic
*
* WG14 DR435: yes
* Possible defect report: Missing constraint w.r.t. Imaginary
*
* WG14 DR436: yes
* Request for interpretation of C11 6.8.5#6
* Note: This is not really testable because it requires -O1 or higher for LLVM
* to perform its reachability analysis and -Wunreachable-code only verifies
* diagnostic behavior, not runtime behavior. Also, both are a matter of QoI as
* to what they optimize/diagnose. But if someone thinks of a way to test this,
* we can add a test case for it then.
*/
/* WG14 DR412: yes
* #elif
*
* Note: this is testing that #elif behaves the same as #else followed by #if.
*/
#if 1
#elif this is not a valid expression
#else
#if this is not a valid expression
#endif
#endif
/* WG14 DR413: yes
* Initialization
*/
void dr413(void) {
typedef struct {
int k;
int l;
int a[2];
} T;
typedef struct {
int i;
T t;
} S;
/* Ensure that explicit initialization (.t = { ... }) takes precedence over a
* later implicit partial initialization (.t.l = 41). The value should be 42,
* not 0.
*/
_Static_assert((S){ /* c89only-warning {{compound literals are a C99-specific feature}}
expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
*/
1,
.t = { /* c89only-warning {{designated initializers are a C99 feature}} */
.l = 43, /* c89only-warning {{designated initializers are a C99 feature}}
expected-note {{previous initialization is here}}
*/
.k = 42,
.a[1] = 19, /* expected-note {{previous initialization is here}} */
.a[0] = 18
},
.t.l = 41, /* expected-warning {{initializer overrides prior initialization of this subobject}} */
.t.a[1] = 17 /* expected-warning {{initializer overrides prior initialization of this subobject}} */
}.t.k == 42, "");
}
/* WG14 DR423: partial
* Defect Report relative to n1570: underspecification for qualified rvalues
@ -30,3 +118,47 @@ void dr423_func(void) {
v2 = 100; /* Not an error; the qualifier was stripped. */
}
/* WG14 DR432: yes
* Possible defect report: Is 0.0 required to be a representable value?
*
* We're going to lean on the fpclassify builtin to tell us whether 0.0
* represents the value 0, and we'll test that adding and subtracting 0.0 does
* not change the value, and we'll hope that's enough to validate this DR.
*/
_Static_assert(__builtin_fpclassify(0, 1, 2, 3, 4, 0.0f) == 4, "");
_Static_assert((1.0 / 3.0) + 0.0 == (1.0 / 3.0) - 0.0, ""); /* expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}} */
/* WG14 DR444: partial
* Issues with alignment in C11, part 1
*/
void dr444(void) {
_Alignas(int) int i;
_Alignas(int) struct S {
_Alignas(int) int i;
} s;
/* FIXME: This should be accepted as per this DR. */
int j = (_Alignas(int) int){12}; /* expected-error {{expected expression}} */
/* FIXME: The diagnostic in this case is really bad; moving the specifier to
* where the diagnostic recommends causes a different, more inscrutable error
* about anonymous structures.
*/
_Alignas(int) struct T { /* expected-warning {{attribute '_Alignas' is ignored, place it after "struct" to apply attribute to type declaration}} */
int i;
};
struct U {
_Alignas(int) int bit : 1; /* expected-error {{'_Alignas' attribute cannot be applied to a bit-field}} */
};
_Alignas(int) typedef int foo; /* expected-error {{'_Alignas' attribute only applies to variables and fields}} */
_Alignas(int) register int bar; /* expected-error {{'_Alignas' attribute cannot be applied to a variable with 'register' storage class}} */
_Alignas(int) void func(void); /* expected-error {{'_Alignas' attribute only applies to variables and fields}} */
/* FIXME: it is correct for us to accept this per 6.7.3p5, but it seems like
* a situation we'd want to diagnose because the alignments are different and
* the user probably doesn't know which one "wins".
*/
_Alignas(int) _Alignas(double) int k;
}

View File

@ -2042,13 +2042,13 @@ conformance.</p>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_401">401</a></td>
<td>C11</td>
<td>"happens before" can not be cyclic</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="402">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_402">402</a></td>
<td>C11</td>
<td>Memory model coherence is not aligned with C++11</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="403">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_403">403</a></td>
@ -2072,7 +2072,7 @@ conformance.</p>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_406">406</a></td>
<td>C11</td>
<td>Visible sequences of side effects are redundant</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="407">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_407">407</a></td>
@ -2101,20 +2101,20 @@ conformance.</p>
<tr id="411">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_411">411</a></td>
<td>C11</td>
<td>#elif</td>
<td class="unknown" align="center">Unknown</td>
<td>Predefined macro values</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="412">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_412">412</a></td>
<td>C11</td>
<td>#elif</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="413">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_413">413</a></td>
<td>NAD</td>
<td>Initialization</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="414">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_414">414</a></td>
@ -2150,7 +2150,7 @@ conformance.</p>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_419">419</a></td>
<td>C11</td>
<td>Generic Functions</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="420">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_420">420</a></td>
@ -2191,7 +2191,7 @@ conformance.</p>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_425">425</a></td>
<td>NAD</td>
<td>No specification for the access to variables with temporary lifetime</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="426">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_426">426</a></td>
@ -2233,7 +2233,7 @@ conformance.</p>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_432">432</a></td>
<td>C11</td>
<td>Possible defect report: Is 0.0 required to be a representable value?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="433">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_433">433</a></td>
@ -2257,7 +2257,7 @@ conformance.</p>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_436">436</a></td>
<td>C11</td>
<td>Request for interpretation of C11 6.8.5#6</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="437">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_437">437</a></td>
@ -2305,7 +2305,11 @@ conformance.</p>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_444">444</a></td>
<td>C11</td>
<td>Issues with alignment in C11, part 1</td>
<td class="unknown" align="center">Unknown</td>
<td class="partial" align="center">
<details><summary>Partial</summary>
Clang rejects use of an alignment specifier in a compound literal expression.
</details>
</td>
</tr>
<tr id="445">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_445">445</a></td>