[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / C / drs / dr335.c
blob3ce6ce5bd53ca426fb7824e3d83b62943aef4c17
1 /* RUN: %clang_cc1 -std=c89 -triple x86_64-pc-win32 -emit-llvm -o - %s | FileCheck %s
2 RUN: %clang_cc1 -std=c89 -triple i686-pc-linux -emit-llvm -o - %s | FileCheck %s
3 RUN: %clang_cc1 -std=c99 -triple x86_64-pc-win32 -emit-llvm -o - %s | FileCheck %s
4 RUN: %clang_cc1 -std=c99 -triple i686-pc-linux -emit-llvm -o - %s | FileCheck %s
5 RUN: %clang_cc1 -std=c11 -triple x86_64-pc-win32 -emit-llvm -o - %s | FileCheck %s
6 RUN: %clang_cc1 -std=c11 -triple i686-pc-linux -emit-llvm -o - %s | FileCheck %s
7 RUN: %clang_cc1 -std=c17 -triple x86_64-pc-win32 -emit-llvm -o - %s | FileCheck %s
8 RUN: %clang_cc1 -std=c17 -triple i686-pc-linux -emit-llvm -o - %s | FileCheck %s
9 RUN: %clang_cc1 -std=c2x -triple x86_64-pc-win32 -emit-llvm -o - %s | FileCheck %s
10 RUN: %clang_cc1 -std=c2x -triple i686-pc-linux -emit-llvm -o - %s | FileCheck %s
13 /* WG14 DR335: yes
14 * _Bool bit-fields
16 * This validates the runtime behavior from the DR, see dr3xx.c for the compile
17 * time enforcement portion.
19 void dr335(void) {
20 struct bits_ {
21 _Bool bbf1 : 1;
22 } bits = { 1 };
24 bits.bbf1 = ~bits.bbf1;
26 // First, load the value from bits.bbf1 and truncate it down to one-bit.
28 // CHECK: %[[LOAD1:.+]] = load i8, ptr {{.+}}, align 1
29 // CHECK-NEXT: %[[CLEAR1:.+]] = and i8 %[[LOAD1]], 1
30 // CHECK-NEXT: %[[CAST:.+]] = trunc i8 %[[CLEAR1]] to i1
31 // CHECK-NEXT: %[[CONV:.+]] = zext i1 %[[CAST]] to i32
33 // Second, perform the unary complement.
35 // CHECK-NEXT: %[[NOT:.+]] = xor i32 %[[CONV]], -1
37 // Finally, test the new value against 0. If it's nonzero, then assign one
38 // into the bit-field, otherwise assign zero into the bit-field. Note, this
39 // does not perform the operation on the promoted value, so this matches the
40 // requirements in C99 6.3.1.2, so a bit-field of type _Bool behaves like a
41 // _Bool and not like an [unsigned] int.
42 // CHECK-NEXT: %[[TOBOOL:.+]] = icmp ne i32 %[[NOT]], 0
43 // CHECK-NEXT: %[[ZERO:.+]] = zext i1 %[[TOBOOL]] to i8
44 // CHECK-NEXT: %[[LOAD2:.+]] = load i8, ptr {{.+}}, align 1
45 // CHECK-NEXT: %[[CLEAR2:.+]] = and i8 %[[LOAD2]], -2
46 // CHECK-NEXT: %[[SET:.+]] = or i8 %[[CLEAR2]], %[[ZERO]]
47 // CHECK-NEXT: store i8 %[[SET]], ptr {{.+}}, align 1
48 // CHECK-NEXT: {{.+}} = trunc i8 %[[ZERO]] to i1