blob: 02f2de79f6bc40506575a5f3addb05d420715c8f [file] [log] [blame]
Eli Friedmanc13f9f02009-06-01 08:55:08 +00001// RUN: clang-cc -triple i386-unknown-unknown %s -emit-llvm -o %t -O3 &&
Daniel Dunbarc4aa96f2008-08-06 16:07:39 +00002// RUN: grep "ret i32" %t | count 4 &&
3// RUN: grep "ret i32 1" %t | count 4
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +00004
Daniel Dunbarc4aa96f2008-08-06 16:07:39 +00005static int f0(int n) {
6 struct s0 {
7 int a : 30;
8 int b : 2;
9 long long c : 31;
10 } x = { 0xdeadbeef, 0xdeadbeef, 0xdeadbeef };
11
12 x.a += n;
13 x.b += n;
14 x.c += n;
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +000015
Daniel Dunbarc4aa96f2008-08-06 16:07:39 +000016 return x.a + x.b + x.c;
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +000017}
Lauro Ramos Venancioa0c5d0e2008-01-22 22:36:45 +000018
Daniel Dunbarc4aa96f2008-08-06 16:07:39 +000019int g0(void) {
20 return f0(-1) + 44335655;
Lauro Ramos Venancioa0c5d0e2008-01-22 22:36:45 +000021}
Lauro Ramos Venanciod957aa02008-02-07 19:29:53 +000022
Daniel Dunbarc4aa96f2008-08-06 16:07:39 +000023static int f1(void) {
24 struct s1 {
25 int a:13;
26 char b;
27 unsigned short c:7;
28 } x;
29
30 x.a = -40;
31 x.b = 10;
32 x.c = 15;
33
34 return x.a + x.b + x.c;
Lauro Ramos Venanciod957aa02008-02-07 19:29:53 +000035}
36
Daniel Dunbarc4aa96f2008-08-06 16:07:39 +000037int g1(void) {
38 return f1() + 16;
39}
40
41static int f2(void) {
42 struct s2 {
43 short a[3];
44 int b : 15;
45 } x;
46
47 x.a[0] = x.a[1] = x.a[2] = -40;
48 x.b = 10;
49
50 return x.b;
51}
52
53int g2(void) {
54 return f2() - 9;
55}
56
57static int f3(int n) {
58 struct s3 {
59 unsigned a:16;
60 unsigned b:28 __attribute__ ((packed));
61 } x = { 0xdeadbeef, 0xdeadbeef };
62 struct s4 {
63 signed a:16;
64 signed b:28 __attribute__ ((packed));
65 } y;
66 y.a = -0x56789abcL;
67 y.b = -0x56789abcL;
68 return ((y.a += x.a += n) +
69 (y.b += x.b += n));
70}
71
72int g3(void) {
73 return f3(20) + 130725747;
Lauro Ramos Venanciod957aa02008-02-07 19:29:53 +000074}