Skip to content

Commit

Permalink
Test C DR conformance (part three of many)
Browse files Browse the repository at this point in the history
This adds more of the tests for the first 100 DRs in C and updates
their status on the status page.
  • Loading branch information
AaronBallman committed May 25, 2022
1 parent 09ef6da commit f96aa83
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 24 deletions.
29 changes: 29 additions & 0 deletions clang/test/C/drs/dr094.c
@@ -0,0 +1,29 @@
/* 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 DR094: yes
* Are constraints on function return the same as assignment?
*/

float func(void) { return 1.0f; }
void other_func(void) {
int i;
float f;

/* Test that there's been a conversion from float to int. */
i = func();
// CHECK: %call = call float @func()
// CHECK-NEXT: %conv = fptosi float %call to i32
// CHECK-NEXT: store i32 %conv, ptr %i, align 4

/* Test that the conversion looks the same as an assignment. */
i = f;
// CHECK: %0 = load float, ptr %f, align 4
// CHECK-NEXT: %conv1 = fptosi float %0 to i32
// CHECK-NEXT: store i32 %conv1, ptr %i, align 4
}

175 changes: 175 additions & 0 deletions clang/test/C/drs/dr0xx.c
Expand Up @@ -57,6 +57,27 @@
*
* WG14 DR067: yes
* Integer and integral type confusion
*
* WG14 DR069: yes
* Questions about the representation of integer types
*
* WG14 DR077: yes
* Stability of addresses
*
* WG14 DR080: yes
* Merging of string constants
*
* WG14 DR086: yes
* Object-like macros in system headers
*
* WG14 DR091: yes
* Multibyte encodings
*
* WG14 DR092: dup 060
* Partial initialization of strings
*
* WG14 DR093: yes
* Reservation of identifiers
*/


Expand Down Expand Up @@ -238,6 +259,17 @@ _Static_assert(DR038(DR038_X + DR038_Y) == DR038_X + DR038_Y, "fail");
*/
_Static_assert(sizeof('a') == sizeof(int), "fail");

/* WG14 DR040: partial
* 9 unrelated questions about C89
*
* Question 6
*/
struct dr040 { /* expected-note {{definition of 'struct dr040' is not complete until the closing '}'}} */
char c;
short s;
int i[__builtin_offsetof(struct dr040, s)]; /* expected-error {{offsetof of incomplete type 'struct dr040'}} */
};

/* WG14 DR043: yes
* On the definition of the NULL macro
*/
Expand Down Expand Up @@ -345,3 +377,146 @@ void dr068(void) {
_Static_assert('\xFF' == 0xFF, "fail");
#endif
}

#if __STDC_VERSION__ < 202000L
/* WG14: DR070: yes
* Interchangeability of function arguments
*
* Note: we could issue a pedantic warning in this case. We are claiming
* conformance not because we diagnose the UB when we could but because we're
* not obligated to do anything about it and we make it "just work" via the
* usual conversion rules.
*
* This behavior is specific to functions without prototypes. A function with
* a prototype causes implicit conversions rather than relying on default
* argument promotion and warm thoughts.
*/
void dr070_1(c) /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}} */
int c; {
}

void dr070_2(void) {
dr070_1(6);
dr070_1(6U); /* Pedantically UB */
}
#endif /* __STDC_VERSION__ < 202000L */

/* WG14 DR071: yes
* Enumerated types
*/
enum dr071_t { foo_A = 0, foo_B = 1, foo_C = 8 };
void dr071(void) {
/* Test that in-range values not present in the enumeration still round-trip
* to the original value.
*/
_Static_assert(100 == (int)(enum dr071_t)100, "fail");
}

/* WG14 DR081: yes
* Left shift operator
*/
void dr081(void) {
/* Demonstrate that we don't crash when left shifting a signed value; that's
* implementation defined behavior.
*/
_Static_assert(-1 << 1 == -2, "fail"); /* Didn't shift a zero into the "sign bit". */
_Static_assert(1 << 3 == 1u << 3u, "fail"); /* Shift of a positive signed value does sensible things. */
}

/* WG14 DR084: yes
* Incomplete type in function declaration
*
* Note: because the situation is UB, we're free to do what we want. We elect
* to accept and require the incomplete type to be completed before the
* function definition.
*/
struct dr084_t; /* expected-note {{forward declaration of 'struct dr084_t'}} */
extern void (*dr084_1)(struct dr084_t);
void dr084_2(struct dr084_t);
void dr084_2(struct dr084_t val) {} /* expected-error {{variable has incomplete type 'struct dr084_t'}} */

/* WG14 DR088: yes
* Compatibility of incomplete types
*/
struct dr088_t_1;

void dr088_f(struct dr088_t_1 *); /* expected-note {{passing argument to parameter here}} */
void dr088_1(void) {
/* Distinct type from the file scope forward declaration. */
struct dr088_t_1;
/* FIXME: this diagnostic could be improved to not be utterly baffling. */
dr088_f((struct dr088_t_1 *)0); /* expected-warning {{incompatible pointer types passing 'struct dr088_t_1 *' to parameter of type 'struct dr088_t_1 *'}} */
}

void dr088_2(struct dr088_t_1 *p) { /* Pointer to incomplete type. */ }
struct dr088_t_1 { int i; }; /* Type is completed. */
void dr088_3(struct dr088_t_1 s) {
/* When passing a pointer to the completed type, is it the same type as the
* incomplete type used in the call declaration?
*/
dr088_2(&s);
}

/* WG14 DR089: yes
* Multiple definitions of macros
*/
#define DR089 object_like /* expected-note {{previous definition is here}} */
#define DR089(argument) function_like /* expected-warning {{'DR089' macro redefined}} */

/* WG14 DR095: yes
* Is initialization as constrained as assignment?
*/
void dr095(void) {
/* Ensure that type compatibility constraints on assignment are also honored
* for initializations.
*/
struct One {
int a;
} one;
struct Two {
float f;
} two = one; /* expected-error {{initializing 'struct Two' with an expression of incompatible type 'struct One'}} */

two = one; /* expected-error {{assigning to 'struct Two' from incompatible type 'struct One'}} */
}

/* WG14 DR096: yes
* Arrays of incomplete types
*/
void dr096(void) {
typedef void func_type(void);
func_type array_funcs[10]; /* expected-error {{'array_funcs' declared as array of functions of type 'func_type' (aka 'void (void)')}} */

void array_void[10]; /* expected-error {{array has incomplete element type 'void'}} */

struct S; /* expected-note {{forward declaration of 'struct S'}} */
struct S s[10]; /* expected-error {{array has incomplete element type 'struct S'}} */

union U; /* expected-note {{forward declaration of 'union U'}} */
union U u[10]; /* expected-error {{array has incomplete element type 'union U'}} */
union U { int i; };

int never_completed_incomplete_array[][]; /* expected-error {{array has incomplete element type 'int[]'}} */

extern int completed_later[][]; /* expected-error {{array has incomplete element type 'int[]'}} */
extern int completed_later[10][10];
}

/* WG14 DR098: yes
* Pre/post increment/decrement of function or incomplete types
*/
void dr098(void) {
typedef void func_type(void);
func_type fp;
struct incomplete *incomplete_ptr;

++fp; /* expected-error {{cannot increment value of type 'func_type' (aka 'void (void)')}} */
fp++; /* expected-error {{cannot increment value of type 'func_type' (aka 'void (void)')}} */
--fp; /* expected-error {{cannot decrement value of type 'func_type' (aka 'void (void)')}} */
fp--; /* expected-error {{cannot decrement value of type 'func_type' (aka 'void (void)')}} */

(*incomplete_ptr)++; /* expected-error {{cannot increment value of type 'struct incomplete'}} */
++(*incomplete_ptr); /* expected-error {{cannot increment value of type 'struct incomplete'}} */
(*incomplete_ptr)--; /* expected-error {{cannot decrement value of type 'struct incomplete'}} */
--(*incomplete_ptr); /* expected-error {{cannot decrement value of type 'struct incomplete'}} */
}
52 changes: 28 additions & 24 deletions clang/www/c_dr_status.html
Expand Up @@ -291,7 +291,11 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_040.html">40</a></td>
<td>NAD</td>
<td>9 unrelated questions about C89</td>
<td class="unknown" align="center">Unknown</td>
<td class="partial" align="center">
<details><summary>Partial</summary>
Question 6 has full support, the rest of the questions are currently unknown.
</details>
</td>
</tr>
<tr id="41">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_041.html">41</a></td>
Expand Down Expand Up @@ -465,19 +469,19 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_069.html">69</a></td>
<td>NAD</td>
<td>Questions about the representation of integer types</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="70">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_070.html">70</a></td>
<td>NAD</td>
<td>Interchangeability of function arguments</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="71">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_071.html">71</a></td>
<td>C89</td>
<td>Enumerated types</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="72">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_072.html">72</a></td>
Expand Down Expand Up @@ -513,7 +517,7 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_077.html">77</a></td>
<td>NAD</td>
<td>Stability of addresses</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="78">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_078.html">78</a></td>
Expand All @@ -531,13 +535,13 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_080.html">80</a></td>
<td>C89</td>
<td>Merging of string constants</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="81">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_081.html">81</a></td>
<td>NAD</td>
<td>Left shift operator</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="82">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_082.html">82</a></td>
Expand All @@ -555,7 +559,7 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_084.html">84</a></td>
<td>NAD</td>
<td>Incomplete type in function declaration</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="85">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_085.html">85</a></td>
Expand All @@ -567,7 +571,7 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_086.html">86</a></td>
<td>NAD</td>
<td>Object-like macros in system headers</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="87">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_087.html">87</a></td>
Expand All @@ -579,13 +583,13 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_088.html">88</a></td>
<td>NAD</td>
<td>Compatibility of incomplete types</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="89">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_089.html">89</a></td>
<td>C89</td>
<td>Multiple definitions of macros</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="90">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_090.html">90</a></td>
Expand All @@ -597,49 +601,49 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_091.html">91</a></td>
<td>NAD</td>
<td>Multibyte encodings</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="92">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_092.html">92</a></td>
<td>Dup</td>
<td>Partial initialization of strings</td>
<td class="unknown" align="center">Duplicate of <a href="#60">60</a></td>
<td class="full" align="center">Duplicate of <a href="#60">60</a></td>
</tr>
<tr id="93">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_093.html">93</a></td>
<td>C89</td>
<td>Reservation of identifiers</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="94">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_094.html">94</a></td>
<td>NAD</td>
<td>ANSI/ISO C Defect report #rfg1</td>
<td class="unknown" align="center">Unknown</td>
<td>Are constraints on function return the same as assignment?</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="95">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_095.html">95</a></td>
<td>NAD</td>
<td>ANSI/ISO C Defect report #rfg2</td>
<td class="unknown" align="center">Unknown</td>
<td>Is initialization as constrained as assignment?</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="96">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_096.html">96</a></td>
<td>NAD</td>
<td>ANSI/ISO C Defect report #rfg3</td>
<td class="unknown" align="center">Unknown</td>
<td>Arrays of incomplete types</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="97">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_097.html">97</a></td>
<td>Dup</td>
<td>ANSI/ISO C Defect report #rfg4</td>
<td class="unknown" align="center">Duplicate of <a href="#40">40</a></td>
<td>Use of offsetof with an incomplete type</td>
<td class="full" align="center">Duplicate of <a href="#40">40</a></td>
</tr>
<tr id="98">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_098.html">98</a></td>
<td>NAD</td>
<td>ANSI/ISO C Defect report #rfg5</td>
<td class="unknown" align="center">Unknown</td>
<td>Pre/post increment/decrement of function or incomplete types</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="99">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_099.html">99</a></td>
Expand Down

0 comments on commit f96aa83

Please sign in to comment.