Test C DR conformance (part one of many)

This starts to fill out the C DR status page with information
determined from tests. It also starts to add some test coverage for the
DRs we can add tests for (some are difficult as not all C DRs involve
questions about code and some DRs are about the behavior of linking
multiple TUs together).

Note: there is currently no automation for filling out the HTML page
from test coverage like there is for the C++ DRs, but this commit
attempts to use a similar comment style in case we want to add such a
script in the future.
This commit is contained in:
Aaron Ballman 2022-05-21 14:59:16 -04:00
parent 8bfccb963b
commit df46fb4055
3 changed files with 200 additions and 21 deletions

18
clang/test/C/drs/dr011.c Normal file
View File

@ -0,0 +1,18 @@
/* RUN: %clang_cc1 -std=c89 -emit-llvm -o - %s | FileCheck %s
RUN: %clang_cc1 -std=c99 -emit-llvm -o - %s | FileCheck %s
RUN: %clang_cc1 -std=c11 -emit-llvm -o - %s | FileCheck %s
RUN: %clang_cc1 -std=c17 -emit-llvm -o - %s | FileCheck %s
RUN: %clang_cc1 -std=c2x -emit-llvm -o - %s | FileCheck %s
*/
/* WG14 DR011: yes
* Merging of declarations for linked identifier
*
* Note, more of this DR is tested in dr0xx.c
*/
int i[10];
int j[];
// CHECK: @i = {{.*}} global [10 x i32] zeroinitializer
// CHECK-NEXT: @j = {{.*}} global [1 x i32] zeroinitializer

161
clang/test/C/drs/dr0xx.c Normal file
View File

@ -0,0 +1,161 @@
/* RUN: %clang_cc1 -std=c89 -verify=expected,c89 -pedantic -Wno-declaration-after-statement -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c99 -verify -pedantic -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c11 -verify -pedantic %s
RUN: %clang_cc1 -std=c17 -verify -pedantic %s
RUN: %clang_cc1 -std=c2x -verify -pedantic %s
*/
/* The following are DRs which do not require tests to demonstrate
* conformance or nonconformance.
*
* WG14 DR005: yes
* May a conforming implementation define and recognize a pragma which would
* change the semantics of the language?
*
* WG14 DR008: yes
* Can a conforming C compiler to perform dead-store elimination?
*
* WG14 DR020: yes
* Is a compiler which allows the Relaxed Ref/Def linkage model to be
* considered a conforming compiler?
*
* WG14 DR025: yes
* What is meant by 'representable floating-point value?'
*
* WG14 DR026: yes
* Can a strictly conforming program contain a string literal with '$' or '@'?
*
* WG14 DR033: yes
* Conformance questions around 'shall' violations outside of constraints
* sections
*/
/* WG14 DR004: yes
* Are multiple definitions of unused identifiers with external linkage
* permitted?
*/
int dr004(void) {return 0;} /* expected-note {{previous definition is here}} */
int dr004(void) {return 1;} /* expected-error {{redefinition of 'dr004'}} */
/* WG14 DR007: yes
* Are declarations of the form struct-or-union identifier ; permitted after
* the identifier tag has already been declared?
*/
struct dr007_a;
struct dr007_a;
struct dr007_a {int a;};
struct dr007_a;
struct dr007_b {int a;};
struct dr007_b;
/* WG14 DR009: no
* Use of typedef names in parameter declarations
*/
typedef int dr009_t;
void dr009_f(int dr009_t);
/* WG14 DR010:
* Is a typedef to an incomplete type legal?
*/
typedef int dr010_t[];
dr010_t dr010_a = {1};
dr010_t dr010_b = {1, 2};
int dr010_c = sizeof(dr010_t); /* expected-error {{invalid application of 'sizeof' to an incomplete type 'dr010_t' (aka 'int[]')}} */
/* WG14 DR011: yes
* Merging of declarations for linked identifier
*
* Note: more of this DR is tested in dr011.c
*/
static int dr011_a[]; /* expected-warning {{tentative array definition assumed to have one element}} */
void dr011(void) {
extern int i[];
{
/* a different declaration of the same object */
extern int i[10];
(void)sizeof(i);
_Static_assert(sizeof(i) == 10 * sizeof(int), "fail");
}
(void)sizeof(i); /* expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}} */
extern int dr011_a[10];
(void)sizeof(dr011_a);
_Static_assert(sizeof(dr011_a) == 10 * sizeof(int), "fail");
extern int j[10];
{
extern int j[];
(void)sizeof(j);
_Static_assert(sizeof(j) == 10 * sizeof(int), "fail");
}
}
/* WG14 DR012: yes
* Is it valid to take the address of a dereferenced void pointer?
*/
void dr012(void *p) {
/* The behavior changed between C89 and C99. */
(void)&*p; /* c89-warning {{ISO C forbids taking the address of an expression of type 'void'}} */
}
/* WG14 DR013: yes
* Compatible and composite function types
*/
int dr013(int a[4]);
int dr013(int a[5]);
int dr013(int *a);
struct dr013_t {
struct dr013_t *p;
} dr013_v[sizeof(struct dr013_t)];
/* WG14 DR015: yes
* What is the promoted type of a plain int bit-field?
*/
void dr015(void) {
struct S {
int small_int_bitfield : 16;
unsigned int small_uint_bitfield : 16;
int int_bitfield : 32;
unsigned int uint_bitfield : 32;
} s;
_Static_assert(__builtin_types_compatible_p(__typeof__(+s.small_int_bitfield), int), "fail");
_Static_assert(__builtin_types_compatible_p(__typeof__(+s.small_uint_bitfield), int), "fail");
_Static_assert(__builtin_types_compatible_p(__typeof__(+s.int_bitfield), int), "fail");
_Static_assert(__builtin_types_compatible_p(__typeof__(+s.uint_bitfield), unsigned int), "fail");
}
/* WG14 DR027: yes
* Can there be characters in the character set that are not in the required
* source character set?
*/
#define THIS$AND$THAT(a, b) ((a) + (b)) /* expected-warning 2 {{'$' in identifier}} */
_Static_assert(THIS$AND$THAT(1, 1) == 2, "fail"); /* expected-warning 2 {{'$' in identifier}} */
/* WG14 DR029: no
* Do two types have to have the same tag to be compatible?
* Note: the rule changed in C99 to be different than the resolution to DR029,
* so it's not clear there's value in implementing this DR.
*/
_Static_assert(__builtin_types_compatible_p(struct S { int a; }, union U { int a; }), "fail"); /* expected-error {{static_assert failed due to requirement '__builtin_types_compatible_p(struct S, union U)' "fail"}} */
/* WG14 DR031: yes
* Can constant expressions overflow?
*/
void dr031(int i) {
switch (i) {
case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; result is -2147483648 with type 'int'}} */
case __INT_MAX__ + 2ul: break;
case (__INT_MAX__ * 4) / 4: break; /* expected-warning {{overflow in expression; result is -4 with type 'int'}} */
}
}
/* WG21 DR032: no
* Must implementations diagnose extensions to the constant evaluation rules?
*
* This should issue a diagnostic because a constant-expression is a
* conditional-expression, which excludes the comma operator.
*/
int dr032 = (1, 2);

View File

@ -70,16 +70,16 @@ conformance.</p>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_004.html">4</a></td>
<td>NAD</td>
<td>Are multiple definitions of unused identifiers with external linkage permitted?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="5">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_005.html">5</a></td>
<td>C89</td>
<td>NAD</td>
<td>May a conforming implementation define and recognize a pragma which would change the semantics of the language?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="6">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_006.html">7</a></td>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_006.html">6</a></td>
<td>C89</td>
<td>It is unclear how the strtoul function behaves when presented with a subject sequence that begins with a minus sign</td>
<td class="na" align="center">N/A</td>
@ -88,43 +88,43 @@ conformance.</p>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_007.html">7</a></td>
<td>NAD</td>
<td>Are declarations of the form struct-or-union identifier ; permitted after the identifier tag has already been declared?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="8">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_008.html">8</a></td>
<td>NAD</td>
<td>Can a conforming C compiler to perform dead-store elimination?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="9">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_009.html">9</a></td>
<td>C89</td>
<td>Use of typedef names in parameter declarations</td>
<td class="unknown" align="center">Unknown</td>
<td class="none" align="center">No</td>
</tr>
<tr id="10">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_010.html">10</a></td>
<td>NAD</td>
<td>Is a typedef to an incomplete type legal?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="11">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_011.html">11</a></td>
<td>C89</td>
<td>Merging of declarations for linked identifier</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="12">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_012.html">12</a></td>
<td>NAD</td>
<td>Questions on the validity of various expressions</td>
<td class="unknown" align="center">Unknown</td>
<td>Is it valid to take the address of a dereferenced void pointer?</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="13">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_013.html">13</a></td>
<td>C89</td>
<td>Compatible and composite function types</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="14">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_014.html">14</a></td>
@ -136,7 +136,7 @@ conformance.</p>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_015.html">15</a></td>
<td>NAD</td>
<td>What is the promoted type of a plain int bit-field?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="16">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_016.html">16</a></td>
@ -166,7 +166,7 @@ conformance.</p>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_020.html">20</a></td>
<td>NAD</td>
<td>Is a compiler which allows the Relaxed Ref/Def linkage model to be considered a conforming compiler?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="21">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_021.html">21</a></td>
@ -196,19 +196,19 @@ conformance.</p>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_025.html">25</a></td>
<td>NAD</td>
<td>What is meant by 'representable floating-point value?'</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="26">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_026.html">26</a></td>
<td>NAD</td>
<td>Can a strictly conforming program contain a string literal with '$' or '@'?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="27">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_027.html">27</a></td>
<td>C89</td>
<td>Can there be characters in the character set that are not in the required source character set?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="28">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_028.html">28</a></td>
@ -220,7 +220,7 @@ conformance.</p>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_029.html">29</a></td>
<td>NAD</td>
<td>Do two types have to have the same tag to be compatible?</td>
<td class="unknown" align="center">Unknown</td>
<td class="none" align="center">No</td>
</tr>
<tr id="30">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_030.html">30</a></td>
@ -232,19 +232,19 @@ conformance.</p>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_031.html">31</a></td>
<td>NAD</td>
<td>Can constant expressions overflow?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="32">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_032.html">32</a></td>
<td>NAD</td>
<td>Must implementations diagnose extensions to the constant evaluation rules?</td>
<td class="unknown" align="center">Unknown</td>
<td class="none" align="center">No</td>
</tr>
<tr id="33">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_033.html">33</a></td>
<td>NAD</td>
<td>Conformance questions around 'shall' violations outside of constraints sections</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="34">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_034.html">34</a></td>