Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds test coverage and updates the related entries for five more C99 DRs.
- Loading branch information
1 parent
6eaad74
commit f43ef6b
Showing
4 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters