Skip to content

Commit

Permalink
Update the status of more C99 DRs
Browse files Browse the repository at this point in the history
This adds test coverage and updates the related entries for five more
C99 DRs.
  • Loading branch information
AaronBallman committed Oct 24, 2022
1 parent 6eaad74 commit f43ef6b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 7 deletions.
45 changes: 45 additions & 0 deletions clang/test/C/drs/dr335.c
@@ -0,0 +1,45 @@
/* 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
}

17 changes: 17 additions & 0 deletions clang/test/C/drs/dr338.c
@@ -0,0 +1,17 @@
/* 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}} */
}
34 changes: 33 additions & 1 deletion clang/test/C/drs/dr3xx.c
Expand Up @@ -28,6 +28,9 @@
*
* WG14 DR312: yes
* Meaning of "known constant size"
*
* WG14 DR333: yes
* Missing Predefined Macro Name
*/


Expand Down Expand Up @@ -189,10 +192,39 @@ _Static_assert(!DR321, "__STDC_MB_MIGHT_NEQ_WC__ but all basic source characters
_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 };
19 changes: 13 additions & 6 deletions clang/www/c_dr_status.html
Expand Up @@ -1921,7 +1921,14 @@ <h2 id="cdr">C defect report implementation status</h2>
<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>
Expand Down Expand Up @@ -1951,7 +1958,7 @@ <h2 id="cdr">C defect report implementation status</h2>
<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>
Expand All @@ -1963,7 +1970,7 @@ <h2 id="cdr">C defect report implementation status</h2>
<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>
Expand All @@ -1979,15 +1986,15 @@ <h2 id="cdr">C defect report implementation status</h2>
</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>
Expand Down

0 comments on commit f43ef6b

Please sign in to comment.