[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGen / bitfield.c
blob4845d7c478429a741c5ae9e3125e36e67f93a744
1 // RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - -O3 -no-struct-path-tbaa | FileCheck %s
2 // RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - -O3 | FileCheck %s --check-prefix=PATH
4 static int f0(int n) {
5 struct s0 {
6 int a : 30;
7 int b : 2;
8 long long c : 31;
9 } x = { 0xdeadbeef, 0xdeadbeef, 0xdeadbeef };
11 x.a += n;
12 x.b += n;
13 x.c += n;
15 return x.a + x.b + x.c;
18 int g0(void) {
19 // CHECK-LABEL: @g0()
20 // CHECK: ret i32 1
21 // PATH-LABEL: @g0()
22 // PATH: ret i32 1
23 return f0(-1) + 44335655;
26 static int f1(void) {
27 struct s1 {
28 int a:13;
29 char b;
30 unsigned short c:7;
31 } x;
33 x.a = -40;
34 x.b = 10;
35 x.c = 15;
37 return x.a + x.b + x.c;
40 int g1(void) {
41 // CHECK-LABEL: @g1()
42 // CHECK: ret i32 1
43 // PATH-LABEL: @g1()
44 // PATH: ret i32 1
45 return f1() + 16;
48 static int f2(void) {
49 struct s2 {
50 short a[3];
51 int b : 15;
52 } x;
54 x.a[0] = x.a[1] = x.a[2] = -40;
55 x.b = 10;
57 return x.b;
60 int g2(void) {
61 // CHECK-LABEL: @g2()
62 // CHECK: ret i32 1
63 // PATH-LABEL: @g2()
64 // PATH: ret i32 1
65 return f2() - 9;
68 static int f3(int n) {
69 struct s3 {
70 unsigned a:16;
71 unsigned b:28 __attribute__ ((packed));
72 } x = { 0xdeadbeef, 0xdeadbeef };
73 struct s4 {
74 signed a:16;
75 signed b:28 __attribute__ ((packed));
76 } y;
77 y.a = -0x56789abcL;
78 y.b = -0x56789abcL;
79 return ((y.a += x.a += n) +
80 (y.b += x.b += n));
83 int g3(void) {
84 // CHECK-LABEL: @g3()
85 // CHECK: ret i32 1
86 // PATH-LABEL: @g3()
87 // PATH: ret i32 1
88 return f3(20) + 130725747;
91 static int f4(void) {
92 struct s5 {
93 int b:1;
94 } x;
95 x.b = 1;
96 return x.b;
99 int g4(void) {
100 // CHECK-LABEL: @g4()
101 // CHECK: ret i32 1
102 // PATH-LABEL: @g4()
103 // PATH: ret i32 1
104 return f4() + 2;