Eli Friedman | c13f9f0 | 2009-06-01 08:55:08 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -triple i386-unknown-unknown %s -emit-llvm -o %t -O3 && |
Daniel Dunbar | c4aa96f | 2008-08-06 16:07:39 +0000 | [diff] [blame] | 2 | // RUN: grep "ret i32" %t | count 4 && |
| 3 | // RUN: grep "ret i32 1" %t | count 4 |
Lauro Ramos Venancio | 3b8c22d | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 4 | |
Daniel Dunbar | c4aa96f | 2008-08-06 16:07:39 +0000 | [diff] [blame] | 5 | static 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 Venancio | 3b8c22d | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 15 | |
Daniel Dunbar | c4aa96f | 2008-08-06 16:07:39 +0000 | [diff] [blame] | 16 | return x.a + x.b + x.c; |
Lauro Ramos Venancio | 3b8c22d | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 17 | } |
Lauro Ramos Venancio | a0c5d0e | 2008-01-22 22:36:45 +0000 | [diff] [blame] | 18 | |
Daniel Dunbar | c4aa96f | 2008-08-06 16:07:39 +0000 | [diff] [blame] | 19 | int g0(void) { |
| 20 | return f0(-1) + 44335655; |
Lauro Ramos Venancio | a0c5d0e | 2008-01-22 22:36:45 +0000 | [diff] [blame] | 21 | } |
Lauro Ramos Venancio | d957aa0 | 2008-02-07 19:29:53 +0000 | [diff] [blame] | 22 | |
Daniel Dunbar | c4aa96f | 2008-08-06 16:07:39 +0000 | [diff] [blame] | 23 | static 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 Venancio | d957aa0 | 2008-02-07 19:29:53 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Daniel Dunbar | c4aa96f | 2008-08-06 16:07:39 +0000 | [diff] [blame] | 37 | int g1(void) { |
| 38 | return f1() + 16; |
| 39 | } |
| 40 | |
| 41 | static 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 | |
| 53 | int g2(void) { |
| 54 | return f2() - 9; |
| 55 | } |
| 56 | |
| 57 | static 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 | |
| 72 | int g3(void) { |
| 73 | return f3(20) + 130725747; |
Lauro Ramos Venancio | d957aa0 | 2008-02-07 19:29:53 +0000 | [diff] [blame] | 74 | } |