Daniel Dunbar | 986b5d1 | 2010-06-29 18:34:40 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s |
Chris Lattner | efdd157 | 2008-01-02 21:54:09 +0000 | [diff] [blame] | 2 | |
| 3 | // PR1895 |
| 4 | // sizeof function |
| 5 | int zxcv(void); |
| 6 | int x=sizeof(zxcv); |
| 7 | int y=__alignof__(zxcv); |
| 8 | |
Chris Lattner | 8f92528 | 2008-01-03 06:36:51 +0000 | [diff] [blame] | 9 | |
| 10 | void *test(int *i) { |
| 11 | short a = 1; |
| 12 | i += a; |
| 13 | i + a; |
| 14 | a + i; |
| 15 | } |
| 16 | |
Chris Lattner | 01e3c9e | 2008-01-30 07:01:17 +0000 | [diff] [blame] | 17 | _Bool test2b; |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 18 | int test2() { if (test2b); return 0; } |
Chris Lattner | 01e3c9e | 2008-01-30 07:01:17 +0000 | [diff] [blame] | 19 | |
Chris Lattner | 6860f3c | 2008-01-31 04:12:50 +0000 | [diff] [blame] | 20 | // PR1921 |
| 21 | int test3() { |
| 22 | const unsigned char *bp; |
| 23 | bp -= (short)1; |
| 24 | } |
| 25 | |
Chris Lattner | a269ebf | 2008-02-21 05:45:29 +0000 | [diff] [blame] | 26 | // PR2080 - sizeof void |
| 27 | int t1 = sizeof(void); |
| 28 | int t2 = __alignof__(void); |
| 29 | void test4() { |
| 30 | t1 = sizeof(void); |
| 31 | t2 = __alignof__(void); |
| 32 | |
| 33 | t1 = sizeof(test4()); |
| 34 | t2 = __alignof__(test4()); |
| 35 | } |
| 36 | |
Chris Lattner | 3cc5e5b | 2008-06-27 22:48:56 +0000 | [diff] [blame] | 37 | // 'const float' promotes to double in varargs. |
| 38 | int test5(const float x, float float_number) { |
| 39 | return __builtin_isless(x, float_number); |
| 40 | } |
| 41 | |
Nuno Lopes | f9ef0c6 | 2008-11-16 20:09:07 +0000 | [diff] [blame] | 42 | // this one shouldn't fold |
| 43 | int ola() { |
| 44 | int a=2; |
| 45 | if ((0, (int)a) & 2) { return 1; } |
| 46 | return 2; |
| 47 | } |
Nuno Lopes | a468d34 | 2008-11-19 17:44:31 +0000 | [diff] [blame] | 48 | |
| 49 | // this one shouldn't fold as well |
| 50 | void eMaisUma() { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 51 | double t[1]; |
| 52 | if (*t) |
| 53 | return; |
Nuno Lopes | a468d34 | 2008-11-19 17:44:31 +0000 | [diff] [blame] | 54 | } |
Chris Lattner | e5ed151 | 2009-02-11 07:21:43 +0000 | [diff] [blame] | 55 | |
| 56 | // rdar://6520707 |
| 57 | void f0(void (*fp)(void), void (*fp2)(void)) { |
| 58 | int x = fp - fp2; |
| 59 | } |
| 60 | |
Chris Lattner | c3953a6 | 2009-03-18 04:02:57 +0000 | [diff] [blame] | 61 | // noop casts as lvalues. |
| 62 | struct X { |
| 63 | int Y; |
| 64 | }; |
| 65 | struct X foo(); |
| 66 | int bar() { |
| 67 | return ((struct X)foo()).Y + 1; |
| 68 | } |
Chris Lattner | e5ed151 | 2009-02-11 07:21:43 +0000 | [diff] [blame] | 69 | |
Chris Lattner | 8cc9d08 | 2009-03-18 04:25:13 +0000 | [diff] [blame] | 70 | // PR3809: INC/DEC of function pointers. |
| 71 | void f2(void); |
| 72 | unsigned f1(void) { |
| 73 | void (*fp)(void) = f2; |
| 74 | |
| 75 | ++fp; |
| 76 | fp++; |
| 77 | --fp; |
| 78 | fp--; |
| 79 | return (unsigned) fp; |
| 80 | } |
| 81 | |
Chris Lattner | 75dfeda | 2009-03-18 18:28:57 +0000 | [diff] [blame] | 82 | union f3_x {int x; float y;}; |
| 83 | int f3() {return ((union f3_x)2).x;} |
| 84 | |
Chris Lattner | 40f9292 | 2009-03-18 18:30:44 +0000 | [diff] [blame] | 85 | union f4_y {int x; _Complex float y;}; |
| 86 | _Complex float f4() {return ((union f4_y)(_Complex float)2.0).y;} |
| 87 | |
| 88 | struct f5_a { int a; } f5_a; |
| 89 | union f5_z {int x; struct f5_a y;}; |
| 90 | struct f5_a f5() {return ((union f5_z)f5_a).y;} |
Daniel Dunbar | 9034558 | 2009-03-24 02:38:23 +0000 | [diff] [blame] | 91 | |
| 92 | // ?: in "lvalue" |
| 93 | struct s6 { int f0; }; |
| 94 | int f6(int a0, struct s6 a1, struct s6 a2) { |
| 95 | return (a0 ? a1 : a2).f0; |
| 96 | } |
Chris Lattner | f0a990c | 2009-04-21 23:00:09 +0000 | [diff] [blame] | 97 | |
| 98 | // PR4026 |
| 99 | void f7() { |
| 100 | __func__; |
| 101 | } |
Chris Lattner | 6545994 | 2009-04-25 19:35:26 +0000 | [diff] [blame] | 102 | |
| 103 | // PR4067 |
| 104 | int f8() { |
| 105 | return ({ foo(); }).Y; |
| 106 | } |
Chris Lattner | 7a574cc | 2009-05-12 21:28:12 +0000 | [diff] [blame] | 107 | |
| 108 | // rdar://6880558 |
| 109 | struct S; |
| 110 | struct C { |
| 111 | int i; |
| 112 | struct S *tab[]; |
| 113 | }; |
| 114 | struct S { struct C c; }; |
| 115 | void f9(struct S *x) { |
| 116 | foo(((void)1, x->c).tab[0]); |
| 117 | } |
| 118 | |
Chris Lattner | c08582b | 2009-12-07 02:09:14 +0000 | [diff] [blame] | 119 | void f10() { |
| 120 | __builtin_sin(0); |
| 121 | } |
Chris Lattner | 9269d5c | 2010-06-26 23:03:20 +0000 | [diff] [blame] | 122 | |
| 123 | // rdar://7530813 |
| 124 | // CHECK: define i32 @f11 |
| 125 | int f11(long X) { |
| 126 | int A[100]; |
| 127 | return A[X]; |
| 128 | |
Daniel Dunbar | 986b5d1 | 2010-06-29 18:34:40 +0000 | [diff] [blame] | 129 | // CHECK: [[Xaddr:%[^ ]+]] = alloca i64, align 8 |
| 130 | // CHECK: load {{.*}}* [[Xaddr]] |
Chris Lattner | 9269d5c | 2010-06-26 23:03:20 +0000 | [diff] [blame] | 131 | // CHECK-NEXT: getelementptr inbounds [100 x i32]* %A, i32 0, |
| 132 | // CHECK-NEXT: load i32* |
| 133 | } |
| 134 | |
Chris Lattner | f70d857 | 2010-06-27 01:08:03 +0000 | [diff] [blame] | 135 | int f12() { |
| 136 | // PR3150 |
| 137 | // CHECK: define i32 @f12 |
| 138 | // CHECK: ret i32 1 |
| 139 | return 1||1; |
| 140 | } |
Chris Lattner | 4ac0d83 | 2010-06-28 17:12:37 +0000 | [diff] [blame] | 141 | |
| 142 | // Make sure negate of fp uses -0.0 for proper -0 handling. |
| 143 | double f13(double X) { |
| 144 | // CHECK: define double @f13 |
Chris Lattner | ce88d0f | 2010-06-28 18:29:14 +0000 | [diff] [blame] | 145 | // CHECK: fsub double -0.0 |
Chris Lattner | 4ac0d83 | 2010-06-28 17:12:37 +0000 | [diff] [blame] | 146 | return -X; |
| 147 | } |
Daniel Dunbar | f52697a | 2010-08-21 02:46:28 +0000 | [diff] [blame] | 148 | |
| 149 | // Check operations on incomplete types. |
John McCall | 85515d6 | 2010-12-04 12:29:11 +0000 | [diff] [blame] | 150 | void f14(struct s14 *a) { |
Daniel Dunbar | f52697a | 2010-08-21 02:46:28 +0000 | [diff] [blame] | 151 | (void) &*a; |
| 152 | } |
| 153 | |
John McCall | 85515d6 | 2010-12-04 12:29:11 +0000 | [diff] [blame] | 154 | // CHECK: define void @f15 |
John McCall | fd56900 | 2010-12-04 12:43:24 +0000 | [diff] [blame] | 155 | void f15() { |
| 156 | extern void f15_start(void); |
| 157 | f15_start(); |
| 158 | // CHECK: call void @f15_start() |
| 159 | |
| 160 | extern void *f15_v(void); |
| 161 | extern const void *f15_cv(void); |
| 162 | extern volatile void *f15_vv(void); |
| 163 | *f15_v(); *f15_v(), *f15_v(); f15_v() ? *f15_v() : *f15_v(); |
| 164 | *f15_cv(); *f15_cv(), *f15_cv(); f15_cv() ? *f15_cv() : *f15_cv(); |
| 165 | *f15_vv(); *f15_vv(), *f15_vv(); f15_vv() ? *f15_vv() : *f15_vv(); |
| 166 | // CHECK-NOT: load |
John McCall | 85515d6 | 2010-12-04 12:29:11 +0000 | [diff] [blame] | 167 | // CHECK: ret void |
| 168 | } |
John McCall | 8d3d6c9 | 2011-01-13 02:03:06 +0000 | [diff] [blame] | 169 | |
| 170 | // PR8967: this was crashing |
| 171 | // CHECK: define void @f16() |
| 172 | void f16() { |
| 173 | __extension__({ goto lbl; }); |
| 174 | lbl: |
| 175 | ; |
| 176 | } |
Michael Liao | 212f80d | 2012-08-28 17:46:11 +0000 | [diff] [blame] | 177 | |
| 178 | // PR13704: negative increment in i128 is not preserved. |
| 179 | // CHECK: define void @f17() |
| 180 | void f17() { |
| 181 | extern void extfunc(__int128); |
| 182 | __int128 x = 2; |
| 183 | x--; |
| 184 | extfunc(x); |
Benjamin Kramer | 47f5a06 | 2012-08-28 18:11:31 +0000 | [diff] [blame] | 185 | // CHECK: add nsw i128 %{{.}}, -1 |
Michael Liao | 212f80d | 2012-08-28 17:46:11 +0000 | [diff] [blame] | 186 | } |