[clang] cce06da - Test and document some C99 DRs

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 30 12:46:53 PDT 2022


Author: Aaron Ballman
Date: 2022-06-30T15:46:47-04:00
New Revision: cce06da1ecf789658551ca5f3b255c361f063abf

URL: https://github.com/llvm/llvm-project/commit/cce06da1ecf789658551ca5f3b255c361f063abf
DIFF: https://github.com/llvm/llvm-project/commit/cce06da1ecf789658551ca5f3b255c361f063abf.diff

LOG: Test and document some C99 DRs

This captures the first 15 or so DRs in C99

Added: 
    clang/test/C/drs/dr206.c
    clang/test/C/drs/dr208.c
    clang/test/C/drs/dr209.c
    clang/test/C/drs/dr2xx.c

Modified: 
    clang/www/c_dr_status.html

Removed: 
    


################################################################################
diff  --git a/clang/test/C/drs/dr206.c b/clang/test/C/drs/dr206.c
new file mode 100644
index 0000000000000..d5686a43b3304
--- /dev/null
+++ b/clang/test/C/drs/dr206.c
@@ -0,0 +1,23 @@
+/* RUN: %clang_cc1 -std=c89 -Wno-deprecated-non-prototype -ast-dump -o -  %s | FileCheck %s
+   RUN: %clang_cc1 -std=c99 -Wno-deprecated-non-prototype -ast-dump -o -  %s | FileCheck %s
+   RUN: %clang_cc1 -std=c11 -Wno-deprecated-non-prototype -ast-dump -o -  %s | FileCheck %s
+   RUN: %clang_cc1 -std=c17 -Wno-deprecated-non-prototype -ast-dump -o -  %s | FileCheck %s
+ */
+
+/* WG14 DR206: yes
+ * Default argument conversion of float _Complex
+ */
+void dr206_unprototyped();
+void dr206(void) {
+  /* Ensure that _Complex float is not promoted to _Complex double but is
+   * instead passed directly without a type conversion.
+   */
+  _Complex float f = 1.2f;
+  dr206_unprototyped(f);
+  // CHECK: CallExpr 0x{{.*}} <line:16:3, col:23> 'void'
+  // CHECK-NEXT: ImplicitCastExpr 0x{{.*}} <col:3> 'void (*)()' <FunctionToPointerDecay>
+  // CHECK-NEXT: DeclRefExpr 0x{{.*}} <col:3> 'void ()' Function 0x{{.*}} 'dr206_unprototyped' 'void ()'
+  // CHECK-NEXT: ImplicitCastExpr 0x{{.*}} <col:22> '_Complex float' <LValueToRValue>
+  // CHECK-NEXT: DeclRefExpr 0x{{.*}} <col:22> '_Complex float' lvalue Var 0x{{.*}} 'f' '_Complex float'
+}
+

diff  --git a/clang/test/C/drs/dr208.c b/clang/test/C/drs/dr208.c
new file mode 100644
index 0000000000000..aac27e7c1ad31
--- /dev/null
+++ b/clang/test/C/drs/dr208.c
@@ -0,0 +1,24 @@
+/* RUN: %clang_cc1 -std=c99 -verify -emit-llvm -o -  %s | FileCheck %s
+   RUN: %clang_cc1 -std=c11 -verify -emit-llvm -o -  %s | FileCheck %s
+   RUN: %clang_cc1 -std=c17 -verify -emit-llvm -o -  %s | FileCheck %s
+   RUN: %clang_cc1 -std=c2x -verify -emit-llvm -o -  %s | FileCheck %s
+ */
+
+/* WG14 DR208: yes
+ * Ambiguity in initialization
+ */
+int dr208_init(int);
+void dr208(void) {
+  int a[2] = {
+    dr208_init(0),      /* expected-note {{previous initialization with side effects is here (side effects will not occur at run time)}} */
+    dr208_init(1),
+    [0] = dr208_init(2) /* expected-warning {{initializer overrides prior initialization of this subobject}} */
+  };
+
+  /* CHECK-NOT: call i32 @dr208_init(i32 noundef 0)
+     CHECK-DAG: call i32 @dr208_init(i32 noundef 1)
+     CHECK-DAG: call i32 @dr208_init(i32 noundef 2)
+     CHECK-NOT: call i32 @dr208_init(i32 noundef 0)
+   */
+}
+

diff  --git a/clang/test/C/drs/dr209.c b/clang/test/C/drs/dr209.c
new file mode 100644
index 0000000000000..6cd6093a4b918
--- /dev/null
+++ b/clang/test/C/drs/dr209.c
@@ -0,0 +1,61 @@
+/* RUN: %clang_cc1 -std=c99 -ffreestanding -triple x86_64-unknown-linux -fsyntax-only -verify -pedantic -Wno-c11-extensions %s
+   RUN: %clang_cc1 -std=c99 -ffreestanding -triple x86_64-unknown-win32 -fms-compatibility -fsyntax-only -verify -pedantic -Wno-c11-extensions %s
+   RUN: %clang_cc1 -std=c11 -ffreestanding -fsyntax-only -verify -pedantic %s
+   RUN: %clang_cc1 -std=c17 -ffreestanding -fsyntax-only -verify -pedantic %s
+   RUN: %clang_cc1 -std=c2x -ffreestanding -fsyntax-only -verify -pedantic %s
+ */
+
+/* WG14 DR209: partial
+ * Problem implementing INTN_C macros
+ */
+#include <stdint.h>
+
+#if INT8_C(0) != 0
+#error "uh oh"
+#elif INT16_C(0) != 0
+#error "uh oh"
+#elif INT32_C(0) != 0
+#error "uh oh"
+#elif INT64_C(0) != 0LL
+#error "uh oh"
+#elif UINT8_C(0) != 0U
+#error "uh oh"
+#elif UINT16_C(0) != 0U
+#error "uh oh"
+#elif UINT32_C(0) != 0U
+#error "uh oh"
+#elif UINT64_C(0) != 0ULL
+#error "uh oh"
+#endif
+
+void dr209(void) {
+  (void)_Generic(INT8_C(0), __typeof__(+(int_least8_t){0}) : 1);
+  (void)_Generic(INT16_C(0), __typeof__(+(int_least16_t){0}) : 1);
+  (void)_Generic(INT32_C(0), __typeof__(+(int_least32_t){0}) : 1);
+  (void)_Generic(INT64_C(0), __typeof__(+(int_least64_t){0}) : 1);
+  (void)_Generic(UINT8_C(0), __typeof__(+(uint_least8_t){0}) : 1);
+  (void)_Generic(UINT16_C(0), __typeof__(+(uint_least16_t){0}) : 1);
+  // FIXME: This is not the expected behavior; the type of the expanded value
+  // in both of these cases should be 'int',
+  //
+  // C99 7.18.4p3: The type of the expression shall have the same type as would
+  // an expression of the corresponding type converted according to the integer
+  // promotions.
+  //
+  // C99 7.18.4.1p1: The macro UINTN_C(value) shall expand to an integer
+  // constant expression corresponding to the type uint_leastN_t.
+  //
+  // C99 7.18.1.2p2: The typedef name uint_leastN_t designates an unsigned
+  // integer type with a width of at least N, ...
+  //
+  // So the value's type is the same underlying type as uint_leastN_t, which is
+  // unsigned char for uint_least8_t, and unsigned short for uint_least16_t,
+  // but then the value undergoes integer promotions which would convert both
+  // of those types to int.
+  //
+  // expected-error at -2 {{controlling expression type 'unsigned int' not compatible with any generic association type}}
+  // expected-error at -2 {{controlling expression type 'unsigned int' not compatible with any generic association type}}
+  (void)_Generic(UINT32_C(0), __typeof__(+(uint_least32_t){0}) : 1);
+  (void)_Generic(UINT64_C(0), __typeof__(+(uint_least64_t){0}) : 1);
+}
+

diff  --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
new file mode 100644
index 0000000000000..0fa0f97858197
--- /dev/null
+++ b/clang/test/C/drs/dr2xx.c
@@ -0,0 +1,82 @@
+/* RUN: %clang_cc1 -std=c89 -fsyntax-only -verify=expected,c89only -pedantic -Wno-c11-extensions %s
+   RUN: %clang_cc1 -std=c99 -triple x86_64-unknown-linux -fsyntax-only -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions %s
+   RUN: %clang_cc1 -std=c99 -triple x86_64-unknown-win32 -fms-compatibility -fsyntax-only -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions %s
+   RUN: %clang_cc1 -std=c11 -fsyntax-only -verify=expected,c99untilc2x -pedantic %s
+   RUN: %clang_cc1 -std=c17 -fsyntax-only -verify=expected,c99untilc2x -pedantic %s
+   RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=expected,c2xandup -pedantic %s
+ */
+
+/* The following are DRs which do not require tests to demonstrate
+ * conformance or nonconformance.
+ *
+ * WG14 DR201: yes
+ * Integer types longer than long
+ *
+ * WG14 DR211: yes
+ * Accuracy of decimal string to/from "binary" (non-decimal) floating-point conversions
+ *
+ * WG14 DR215: yes
+ * Equality operators
+ */
+
+
+/* WG14 DR204: yes
+ * size_t and ptr
diff _t as a long long type
+ */
+void dr204(void) {
+  __typeof__(sizeof(0)) s;
+  __typeof__((int *)0 - (int *)0) p;
+  signed long sl;
+#if __LLONG_WIDTH__ > __LONG_WIDTH__
+  /* If the implementation supports a standard integer type larger than signed
+   * long, it's okay for size_t and ptr
diff _t to have a greater integer
+   * conversion rank than signed long.
+   */
+   (void)_Generic(s + sl, __typeof__(s) : 1);
+   (void)_Generic(p + sl, __typeof__(p) : 1);
+#elif __LLONG_WIDTH__ == __LONG_WIDTH__
+  /* But if the implementation doesn't support a larger standard integer type
+   * than signed long, the conversion rank should prefer signed long if the type
+   * is signed (ptr
diff _t) or unsigned long if the type is unsigned (size_t).
+   */
+   (void)_Generic(s + sl, unsigned long : 1);
+   (void)_Generic(p + sl, signed long : 1);
+#else
+#error "Something has gone off the rails"
+#endif
+}
+
+/* WG14 DR207: partial
+ * Handling of imaginary types
+ *
+ * FIXME: Clang recognizes the _Imaginary keyword but does not support the data
+ * type.
+ */
+void dr207(void) {
+  _Imaginary float f; /* expected-error {{imaginary types are not supported}}
+                         c89only-warning {{'_Imaginary' is a C99 extension}}
+                       */
+}
+
+/* WG14 DR216: yes
+ * Source character encodings
+ */
+void dr216(void) {
+#define A(x) _Static_assert((char)x >= 0, "no")
+  A('A'); A('B'); A('C'); A('D'); A('E'); A('F'); A('G'); A('H'); A('I');
+  A('J'); A('K'); A('L'); A('M'); A('N'); A('O'); A('P'); A('Q'); A('R');
+  A('S'); A('T'); A('U'); A('V'); A('W'); A('X'); A('Y'); A('Z');
+
+  A('a'); A('b'); A('c'); A('d'); A('e'); A('f'); A('g'); A('h'); A('i');
+  A('j'); A('k'); A('l'); A('m'); A('n'); A('o'); A('p'); A('q'); A('r');
+  A('s'); A('t'); A('u'); A('v'); A('w'); A('x'); A('y'); A('z');
+
+  A('0'); A('1'); A('2'); A('3'); A('4');
+  A('5'); A('6'); A('7'); A('8'); A('9');
+
+  A('!'); A('"'); A('#'); A('%'); A('&'); A('\''); A('('); A(')'); A('*');
+  A('+'); A(','); A('-'); A('.'); A('/'); A(':'); A(';'); A('<'); A('=');
+  A('>'); A('?'); A('['); A('\\'); A(']'); A('^'); A('_'); A('{'); A('|');
+  A('}'); A('~');
+#undef A
+}

diff  --git a/clang/www/c_dr_status.html b/clang/www/c_dr_status.html
index e6e339d5f18ce..ea604b498a539 100644
--- a/clang/www/c_dr_status.html
+++ b/clang/www/c_dr_status.html
@@ -1129,7 +1129,7 @@ <h2 id="cdr">C defect report implementation status</h2>
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_201.htm">201</a></td>
     <td>NAD</td>
     <td>Integer types longer than long</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr id="202">
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_202.htm">202</a></td>
@@ -1147,7 +1147,7 @@ <h2 id="cdr">C defect report implementation status</h2>
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_204.htm">204</a></td>
     <td>C99</td>
     <td>size_t and ptr
diff _t as a long long type</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr id="205">
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_205.htm">205</a></td>
@@ -1159,25 +1159,36 @@ <h2 id="cdr">C defect report implementation status</h2>
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_206.htm">206</a></td>
     <td>NAD</td>
     <td>Default argument conversion of float _Complex</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr id="207">
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_207.htm">207</a></td>
     <td>C99</td>
     <td>Handling of imaginary types</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="partial" align="center">
+      <details><summary>Partial</summary>
+        Clang detects use of the _Imaginary keyword but does not otherwise
+        support the type yet.
+      </details>
+    </td>
   </tr>
   <tr id="208">
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_208.htm">208</a></td>
     <td>C99</td>
     <td>Ambiguity in initialization</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr id="209">
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_209.htm">209</a></td>
     <td>C99</td>
     <td>Problem implementing INTN_C macros</td>
-    <td class="na" align="center">N/A</td>
+    <td class="partial" align="center">
+      <details><summary>Partial</summary>
+        Clang provides these definitions in a freestanding compilation, but the
+        type of the value produced by <code>UINT8_C</code> and <code>UINT16_C</code>
+        is not the type after integer promotion per C99 7.18.4p3.
+      </details>
+    </td>
   </tr>
   <tr id="210">
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_210.htm">210</a></td>
@@ -1189,7 +1200,7 @@ <h2 id="cdr">C defect report implementation status</h2>
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_211.htm">211</a></td>
     <td>C99</td>
     <td>Accuracy of decimal string to/from "binary" (non-decimal) floating-point conversions</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr id="212">
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_212.htm">212</a></td>
@@ -1213,13 +1224,13 @@ <h2 id="cdr">C defect report implementation status</h2>
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_215.htm">215</a></td>
     <td>C99</td>
     <td>Equality operators</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr id="216">
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_216.htm">216</a></td>
     <td>C99</td>
     <td>Source character encodings</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr id="217">
     <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_217.htm">217</a></td>


        


More information about the cfe-commits mailing list