[clang] 202a4fd - Test more C DR conformance (part two of many)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Sun May 22 10:37:38 PDT 2022
Author: Aaron Ballman
Date: 2022-05-22T13:37:30-04:00
New Revision: 202a4fde2ba92d70f1eb8760e1919b6ab19f0ced
URL: https://github.com/llvm/llvm-project/commit/202a4fde2ba92d70f1eb8760e1919b6ab19f0ced
DIFF: https://github.com/llvm/llvm-project/commit/202a4fde2ba92d70f1eb8760e1919b6ab19f0ced.diff
LOG: Test more C DR conformance (part two of many)
This continues the work started earlier at filling our the C DR status
page based on test coverage.
Added:
clang/test/C/drs/dr060.c
Modified:
clang/test/C/drs/dr0xx.c
clang/www/c_dr_status.html
Removed:
################################################################################
diff --git a/clang/test/C/drs/dr060.c b/clang/test/C/drs/dr060.c
new file mode 100644
index 0000000000000..2650871e5dd6a
--- /dev/null
+++ b/clang/test/C/drs/dr060.c
@@ -0,0 +1,17 @@
+/* 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 DR060:
+ * Array initialization from a string literal
+ */
+
+const char str[5] = "foo";
+const __typeof__(*L"a") wstr[5] = L"foo";
+
+// CHECK: @str = {{.*}}constant [5 x i8] c"foo\00\00"
+// CHECK-NEXT: @wstr = {{.*}}constant [5 x i{{16|32}}] [i{{16|32}} 102, i{{16|32}} 111, i{{16|32}} 111, i{{16|32}} 0, i{{16|32}} 0]
+
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index 4046765fa97ed..b0b57fa289149 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -1,8 +1,9 @@
-/* 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
+/* RUN: %clang_cc1 -std=c89 -verify=expected,c89only -pedantic -Wno-declaration-after-statement -Wno-c11-extensions %s
+ RUN: %clang_cc1 -std=c89 -verify=expected,c89only -pedantic -Wno-declaration-after-statement -Wno-c11-extensions -fno-signed-char %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
*/
/* The following are DRs which do not require tests to demonstrate
@@ -28,6 +29,34 @@
* WG14 DR033: yes
* Conformance questions around 'shall' violations outside of constraints
* sections
+ *
+ * WG14 DR036: yes
+ * May floating-point constants be represented with more precision than implied
+ * by its type?
+ *
+ * WG14 DR037: yes
+ * Questions about multibyte characters and Unicode
+ *
+ * WG14 DR051: yes
+ * Question on pointer arithmetic
+ *
+ * WG14 DR052: yes
+ * Editorial corrections
+ *
+ * WG14 DR056: yes
+ * Floating-point representation precision requirements
+ *
+ * WG14 DR057: yes
+ * Is there an integral type for every pointer?
+ *
+ * WG14 DR059: yes
+ * Do types have to be completed?
+ *
+ * WG14 DR063: dup 056
+ * Floating-point representation precision requirements
+ *
+ * WG14 DR067: yes
+ * Integer and integral type confusion
*/
@@ -49,11 +78,16 @@ struct dr007_a;
struct dr007_b {int a;};
struct dr007_b;
+
/* WG14 DR009: no
* Use of typedef names in parameter declarations
+ *
+ * FIXME: This should be diagnosed as expecting a declaration specifier instead
+ * of treated as declaring a parameter of type 'int (*)(dr009_t);'
*/
typedef int dr009_t;
-void dr009_f(int dr009_t);
+void dr009_f((dr009_t)); /* c99untilc2x-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
+ c2xandup-error {{a type specifier is required for all declarations}} */
/* WG14 DR010:
* Is a typedef to an incomplete type legal?
@@ -67,6 +101,12 @@ int dr010_c = sizeof(dr010_t); /* expected-error {{invalid application of 'sizeo
* Merging of declarations for linked identifier
*
* Note: more of this DR is tested in dr011.c
+ *
+ * WG14 DR034: yes
+ * External declarations in
diff erent scopes
+ *
+ * Note: DR034 has a question resolved by DR011 and another question where the
+ * result is UB.
*/
static int dr011_a[]; /* expected-warning {{tentative array definition assumed to have one element}} */
void dr011(void) {
@@ -96,7 +136,7 @@ void dr011(void) {
*/
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'}} */
+ (void)&*p; /* c89only-warning {{ISO C forbids taking the address of an expression of type 'void'}} */
}
/* WG14 DR013: yes
@@ -158,10 +198,150 @@ void dr031(int i) {
}
}
-/* WG21 DR032: no
+/* WG14 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); /* expected-warning {{left operand of comma operator has no effect}} */
+
+#if __STDC_VERSION__ < 202000L
+/* WG14 DR035: partial
+ * Questions about definition of functions without a prototype
+ */
+void dr035_1(a, b) /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}} */
+ int a(enum b {x, y}); /* expected-warning {{declaration of 'enum b' will not be visible outside of this function}} */
+ int b; {
+ int test = x; /* expected-error {{use of undeclared identifier 'x'}} */
+}
+
+void dr035_2(c) /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}} */
+ enum m{q, r} c; { /* expected-warning {{declaration of 'enum m' will not be visible outside of this function}} */
+ /* FIXME: This should be accepted because the scope of m, q, and r ends at
+ * the closing brace of the function per C89 6.1.2.1.
+ */
+ int test = q; /* expected-error {{use of undeclared identifier 'q'}} */
+}
+#endif /* __STDC_VERSION__ < 202000L */
+
+/* WG14 DR038: yes
+ * Questions about argument substitution during macro expansion
+ */
+#define DR038_X 0x000E
+#define DR038_Y 0x0100
+#define DR038(a) a
+_Static_assert(DR038(DR038_X + DR038_Y) == DR038_X + DR038_Y, "fail");
+
+/* WG14 DR039: yes
+ * Questions about the "C" locale
+ */
+_Static_assert(sizeof('a') == sizeof(int), "fail");
+
+/* WG14 DR043: yes
+ * On the definition of the NULL macro
+ */
+void dr043(void) {
+ #include <stddef.h>
+ /* NULL has to be an integer constant expression with the value 0, or such an
+ * expression cast to void *. If it's an integer constant expression other
+ * than the literal 0 (such as #define NULL 4-4), this would fail to compile
+ * unless the macro replacement list is properly parenthesized as it would
+ * expand to: (void)(void *)4-4;
+ */
+ (void)(void *)NULL;
+
+ /* If the NULL macro is an integer constant expression with the value 0 and
+ * it has been cast to void *, ensure that it's also fully parenthesized. If
+ * it isn't (such as #define NULL (void *)0), this would fail to compile as
+ * would expand to (void *)0->a; which gives a diagnostic about int not being
+ * a pointer, instead of((void *)0)->a; which gives a diagnostic about the
+ * base reference being void and not a structure.
+ */
+ NULL->a; /* expected-error {{member reference base type 'void' is not a structure or union}} */
+}
+
+/* WG14 DR044: yes
+ * On the result of the offsetof macro
+ */
+void dr044(void) {
+ #include <stddef.h>
+ struct S { int a, b; };
+ /* Ensure that the result of offsetof is usable in a constant expression. */
+ _Static_assert(offsetof(struct S, b) == sizeof(int), "fail");
+}
+
+/* WG14 DR046: yes
+ * Use of typedef names in parameter declarations
+ */
+typedef int dr046_t;
+int dr046(int dr046_t) { return dr046_t; }
+
+/* WG14 DR047: yes
+ * Questions about declaration conformance
+ */
+struct dr047_t; /* expected-note 2 {{forward declaration of 'struct dr047_t'}} */
+struct dr047_t *dr047_1(struct dr047_t *p) {return p; }
+struct dr047_t *dr047_2(struct dr047_t a[]) {return a; } /* expected-error {{array has incomplete element type 'struct dr047_t'}} */
+int *dr047_3(int a2[][]) {return *a2; } /* expected-error {{array has incomplete element type 'int[]'}} */
+extern struct dr047_t es1;
+extern struct dr047_t es2[1]; /* expected-error {{array has incomplete element type 'struct dr047_t'}} */
+
+/* WG14 DR050: yes
+ * Do wide string literals implicitly include <stddef.h>?
+ */
+void dr050(void) {
+ /* The NULL macro is previously defined because we include <stddef.h> for
+ * other tests. Undefine the macro to demonstrate that use of a wide string
+ * literal doesn't magically include the header file.
+ */
+ #undef NULL
+ (void)L"huttah!";
+ (void)NULL; /* expected-error {{use of undeclared identifier 'NULL'}} */
+}
+
+#if __STDC_VERSION__ < 202000L
+/* WG14 DR053: yes
+ * Accessing a pointer to a function with a prototype through a pointer to
+ * pointer to function without a prototype
+ */
+void dr053(void) {
+ int f(int);
+ int (*fp1)(int);
+ int (*fp2)(); /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} */
+ int (**fpp)(); /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} */
+
+ fp1 = f;
+ fp2 = fp1;
+ (*fp2)(3); /* expected-warning {{passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x}} */
+ fpp = &fp1;
+ (**fpp)(3); /* expected-warning {{passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x}} */
+}
+#endif /* __STDC_VERSION__ < 202000L */
+
+/* WG14 DR064: yes
+ * Null pointer constants
+ */
+char *dr064_1(int i, int *pi) {
+ *pi = i;
+ return 0;
+}
+
+char *dr064_2(int i, int *pi) {
+ return (*pi = i, 0); /* expected-warning {{incompatible integer to pointer conversion returning 'int' from a function with result type 'char *'}} */
+}
+
+/* WG14 DR068: yes
+ * 'char' and signed vs unsigned integer types
+ */
+void dr068(void) {
+ #include <limits.h>
+
+#if CHAR_MAX == SCHAR_MAX
+ /* char is signed */
+ _Static_assert('\xFF' == -1, "fail");
+#else
+ /* char is unsigned */
+ _Static_assert('\xFF' == 0xFF, "fail");
+#endif
+}
diff --git a/clang/www/c_dr_status.html b/clang/www/c_dr_status.html
index 05d85790cb920..49783ed4b4eac 100644
--- a/clang/www/c_dr_status.html
+++ b/clang/www/c_dr_status.html
@@ -250,37 +250,42 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_034.html">34</a></td>
<td>C89</td>
<td>External declarations in
diff erent scopes</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="35">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_035.html">35</a></td>
<td>NAD</td>
<td>Questions about definition of functions without a prototype</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="partial" align="center">
+ <details><summary>Partial</summary>
+ Tags declared directly within an identifier list are incorrectly scoped
+ to the prototype rather than to the function body.
+ </details>
+ </td>
</tr>
<tr id="36">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_036.html">36</a></td>
<td>NAD</td>
<td>May floating-point constants be represented with more precision than implied by its type?</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="37">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_037.html">37</a></td>
<td>NAD</td>
<td>Questions about multibyte characters and Unicode</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="38">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_038.html">38</a></td>
<td>NAD</td>
<td>Questions about argument substitution during macro expansion</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="39">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_039.html">39</a></td>
<td>NAD</td>
<td>Questions about the "C" locale</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="40">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_040.html">40</a></td>
@@ -304,13 +309,13 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_043.html">43</a></td>
<td>C89</td>
<td>On the definition of the NULL macro</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="44">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_044.html">44</a></td>
<td>NAD</td>
<td>On the result of the offsetof macro</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="45">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_045.html">45</a></td>
@@ -322,13 +327,13 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_046.html">46</a></td>
<td>NAD</td>
<td>Use of typedef names in parameter declarations</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="47">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_047.html">47</a></td>
<td>NAD</td>
<td>Questions about declaration conformance</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="48">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_048.html">48</a></td>
@@ -346,25 +351,25 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_050.html">50</a></td>
<td>NAD</td>
<td>Do wide string literals implicitly include <stddef.h>?</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="51">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_051.html">51</a></td>
<td>NAD</td>
<td>Question on pointer arithmetic</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="52">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_052.html">52</a></td>
<td>C89</td>
<td>Editorial corrections</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="53">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_053.html">53</a></td>
<td>C89</td>
<td>Accessing a pointer to a function with a prototype through a pointer to pointer to function without a prototype</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="54">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_054.html">54</a></td>
@@ -382,13 +387,13 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_056.html">56</a></td>
<td>NAD</td>
<td>Floating-point representation precision requirements</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="57">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_057.html">57</a></td>
<td>NAD</td>
<td>Is there an integral type for every pointer?</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="58">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_058.html">58</a></td>
@@ -400,13 +405,13 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_059.html">59</a></td>
<td>NAD</td>
<td>Do types have to be completed?</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="60">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_060.html">60</a></td>
<td>C89</td>
<td>Array initialization from a string literal</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="61">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_061.html">61</a></td>
@@ -424,13 +429,13 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_063.html">63</a></td>
<td>Dup</td>
<td>Floating-point representation precision requirements</td>
- <td class="unknown" align="center">Duplicate of <a href="#56">56</a></td>
+ <td class="full" align="center">Duplicate of <a href="#56">56</a></td>
</tr>
<tr id="64">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_064.html">64</a></td>
<td>NAD</td>
<td>Null pointer constants</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="65">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_065.html">65</a></td>
@@ -442,19 +447,19 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_066.html">66</a></td>
<td>NAD</td>
<td>Another question on locales</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="na" align="center">N/A</td>
</tr>
<tr id="67">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_067.html">67</a></td>
<td>NAD</td>
<td>Integer and integral type confusion</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="68">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_068.html">68</a></td>
<td>NAD</td>
<td>'char' and signed vs unsigned integer types</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="69">
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_069.html">69</a></td>
More information about the cfe-commits
mailing list