--- /dev/null
+/* 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 DR335: yes
+ * _Bool bit-fields
+ *
+ * This validates the runtime behavior from the DR, see dr3xx.c for the compile
+ * time enforcement portion.
+ */
+void dr335(void) {
+ struct bits_ {
+ _Bool bbf1 : 1;
+ } bits = { 1 };
+
+ bits.bbf1 = ~bits.bbf1;
+
+ // First, load the value from bits.bbf1 and truncate it down to one-bit.
+
+ // CHECK: %[[LOAD1:.+]] = load i8, ptr {{.+}}, align 1
+ // CHECK-NEXT: %[[CLEAR1:.+]] = and i8 %[[LOAD1]], 1
+ // CHECK-NEXT: %[[CAST:.+]] = trunc i8 %[[CLEAR1]] to i1
+ // CHECK-NEXT: %[[CONV:.+]] = zext i1 %[[CAST]] to i32
+
+ // Second, perform the unary complement.
+
+ // CHECK-NEXT: %[[NOT:.+]] = xor i32 %[[CONV]], -1
+
+ // Finally, test the new value against 0. If it's nonzero, then assign one
+ // into the bit-field, otherwise assign zero into the bit-field. Note, this
+ // does not perform the operation on the promoted value, so this matches the
+ // requirements in C99 6.3.1.2, so a bit-field of type _Bool behaves like a
+ // _Bool and not like an [unsigned] int.
+ // CHECK-NEXT: %[[TOBOOL:.+]] = icmp ne i32 %[[NOT]], 0
+ // CHECK-NEXT: %[[ZERO:.+]] = zext i1 %[[TOBOOL]] to i8
+ // CHECK-NEXT: %[[LOAD2:.+]] = load i8, ptr {{.+}}, align 1
+ // CHECK-NEXT: %[[CLEAR2:.+]] = and i8 %[[LOAD2]], -2
+ // CHECK-NEXT: %[[SET:.+]] = or i8 %[[CLEAR2]], %[[ZERO]]
+ // CHECK-NEXT: store i8 %[[SET]], ptr {{.+}}, align 1
+ // CHECK-NEXT: {{.+}} = trunc i8 %[[ZERO]] to i1
+}
+
--- /dev/null
+/* RUN: %clang_cc1 -std=c89 -fsyntax-only -Wuninitialized -verify %s
+ RUN: %clang_cc1 -std=c99 -fsyntax-only -Wuninitialized -verify %s
+ RUN: %clang_cc1 -std=c11 -fsyntax-only -Wuninitialized -verify %s
+ RUN: %clang_cc1 -std=c17 -fsyntax-only -Wuninitialized -verify %s
+ RUN: %clang_cc1 -std=c2x -fsyntax-only -Wuninitialized -verify %s
+ */
+
+/* WG14 DR338: yes
+ * C99 seems to exclude indeterminate value from being an uninitialized register
+ *
+ * Note, because we're relying on -Wuninitialized, this test has to live in its
+ * own file. That analysis will not run if the file has other errors in it.
+ */
+int dr338(void) {
+ unsigned char uc; /* expected-note {{initialize the variable 'uc' to silence this warning}} */
+ return uc + 1 >= 0; /* expected-warning {{variable 'uc' is uninitialized when used here}} */
+}
*
* WG14 DR312: yes
* Meaning of "known constant size"
+ *
+ * WG14 DR333: yes
+ * Missing Predefined Macro Name
*/
_Static_assert(DR321, "!__STDC_MB_MIGHT_NEQ_WC__ but some character differs");
#endif
-/* WG14 DR328: yes
+/* WG14 DR328: partial
* String literals in compound literal initialization
+ *
+ * DR328 is implemented properly in terms of allowing string literals, but is
+ * not implemented. See DR339 (marked as a duplicate of this one) for details.
*/
const char *dr328_v = (const char *){"this is a string literal"}; /* c89only-warning {{compound literals are a C99-specific feature}} */
void dr328(void) {
const char *val = (const char *){"also a string literal"}; /* c89only-warning {{compound literals are a C99-specific feature}} */
}
+
+/* WG14 DR335: yes
+ * _Bool bit-fields
+ *
+ * See dr335.c also, which tests the runtime behavior of the part of the DR
+ * which will compile.
+ */
+void dr335(void) {
+ struct bits_ {
+ _Bool bbf3 : 3; /* expected-error {{width of bit-field 'bbf3' (3 bits) exceeds the width of its type (1 bit)}}
+ c89only-warning {{'_Bool' is a C99 extension}}
+ */
+ };
+}
+
+/* WG14 DR339: partial
+ * Variably modified compound literals
+ *
+ * This DR is marked as a duplicate of DR328, see that DR for further
+ * details.
+ *
+ * FIXME: we should be diagnosing this compound literal as creating a variably-
+ * modified type at file scope, as we would do for a file scope variable.
+ */
+extern int dr339_v;
+void *dr339 = &(int (*)[dr339_v]){ 0 };
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_328.htm">328</a></td>
<td>C99</td>
<td>String literals in compound literal initialization</td>
- <td class="full" align="center">Yes</td>
+ <td class="partial" align="center">
+ <details><summary>Partial</summary>
+ Clang properly implements the use of string literals in a compound
+ literal initializer, but fails to diagnose use of a variably-modified
+ type at file scope. DR339 (about variably-modified types) is marked as
+ a duplicate of DR328.
+ </details>
+ </td>
</tr>
<tr id="329">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_329.htm">329</a></td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_333.htm">333</a></td>
<td>C99</td>
<td>Missing Predefined Macro Name</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr class="open" id="334">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_334.htm">334</a></td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_335.htm">335</a></td>
<td>NAD</td>
<td>_Bool bit-fields</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="336">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_336.htm">336</a></td>
</tr>
<tr id="338">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_338.htm">338</a></td>
- <td>C11</td>
+ <td>C99</td>
<td>C99 seems to exclude indeterminate value from being an uninitialized register</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr id="339">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_339.htm">339</a></td>
<td>Dup</td>
<td>Variably modified compound literal</td>
- <td class="unknown" align="center">Duplicate of <a href="#328">328</a></td>
+ <td class="partial" align="center">Duplicate of <a href="#328">328</a></td>
</tr>
<tr id="340">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_340.htm">340</a></td>