blob: cc03be6a922a4c6bc59526876ffb5c3632e038f4 [file] [log] [blame]
Daniel Dunbar986b5d12010-06-29 18:34:40 +00001// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s
Chris Lattnerefdd1572008-01-02 21:54:09 +00002
3// PR1895
4// sizeof function
5int zxcv(void);
6int x=sizeof(zxcv);
7int y=__alignof__(zxcv);
8
Chris Lattner8f925282008-01-03 06:36:51 +00009
10void *test(int *i) {
11 short a = 1;
12 i += a;
13 i + a;
14 a + i;
15}
16
Chris Lattner01e3c9e2008-01-30 07:01:17 +000017_Bool test2b;
Mike Stumpc36541e2009-07-21 20:52:43 +000018int test2() { if (test2b); return 0; }
Chris Lattner01e3c9e2008-01-30 07:01:17 +000019
Chris Lattner6860f3c2008-01-31 04:12:50 +000020// PR1921
21int test3() {
22 const unsigned char *bp;
23 bp -= (short)1;
24}
25
Chris Lattnera269ebf2008-02-21 05:45:29 +000026// PR2080 - sizeof void
27int t1 = sizeof(void);
28int t2 = __alignof__(void);
29void test4() {
30 t1 = sizeof(void);
31 t2 = __alignof__(void);
32
33 t1 = sizeof(test4());
34 t2 = __alignof__(test4());
35}
36
Chris Lattner3cc5e5b2008-06-27 22:48:56 +000037// 'const float' promotes to double in varargs.
38int test5(const float x, float float_number) {
39 return __builtin_isless(x, float_number);
40}
41
Nuno Lopesf9ef0c62008-11-16 20:09:07 +000042// this one shouldn't fold
43int ola() {
44 int a=2;
45 if ((0, (int)a) & 2) { return 1; }
46 return 2;
47}
Nuno Lopesa468d342008-11-19 17:44:31 +000048
49// this one shouldn't fold as well
50void eMaisUma() {
Mike Stump1eb44332009-09-09 15:08:12 +000051 double t[1];
52 if (*t)
53 return;
Nuno Lopesa468d342008-11-19 17:44:31 +000054}
Chris Lattnere5ed1512009-02-11 07:21:43 +000055
56// rdar://6520707
57void f0(void (*fp)(void), void (*fp2)(void)) {
58 int x = fp - fp2;
59}
60
Chris Lattnerc3953a62009-03-18 04:02:57 +000061// noop casts as lvalues.
62struct X {
63 int Y;
64};
65struct X foo();
66int bar() {
67 return ((struct X)foo()).Y + 1;
68}
Chris Lattnere5ed1512009-02-11 07:21:43 +000069
Chris Lattner8cc9d082009-03-18 04:25:13 +000070// PR3809: INC/DEC of function pointers.
71void f2(void);
72unsigned f1(void) {
73 void (*fp)(void) = f2;
74
75 ++fp;
76 fp++;
77 --fp;
78 fp--;
79 return (unsigned) fp;
80}
81
Chris Lattner75dfeda2009-03-18 18:28:57 +000082union f3_x {int x; float y;};
83int f3() {return ((union f3_x)2).x;}
84
Chris Lattner40f92922009-03-18 18:30:44 +000085union f4_y {int x; _Complex float y;};
86_Complex float f4() {return ((union f4_y)(_Complex float)2.0).y;}
87
88struct f5_a { int a; } f5_a;
89union f5_z {int x; struct f5_a y;};
90struct f5_a f5() {return ((union f5_z)f5_a).y;}
Daniel Dunbar90345582009-03-24 02:38:23 +000091
92// ?: in "lvalue"
93struct s6 { int f0; };
94int f6(int a0, struct s6 a1, struct s6 a2) {
95 return (a0 ? a1 : a2).f0;
96}
Chris Lattnerf0a990c2009-04-21 23:00:09 +000097
98// PR4026
99void f7() {
100 __func__;
101}
Chris Lattner65459942009-04-25 19:35:26 +0000102
103// PR4067
104int f8() {
105 return ({ foo(); }).Y;
106}
Chris Lattner7a574cc2009-05-12 21:28:12 +0000107
108// rdar://6880558
109struct S;
110struct C {
111 int i;
112 struct S *tab[];
113};
114struct S { struct C c; };
115void f9(struct S *x) {
116 foo(((void)1, x->c).tab[0]);
117}
118
Chris Lattnerc08582b2009-12-07 02:09:14 +0000119void f10() {
120 __builtin_sin(0);
121}
Chris Lattner9269d5c2010-06-26 23:03:20 +0000122
123// rdar://7530813
124// CHECK: define i32 @f11
125int f11(long X) {
126 int A[100];
127 return A[X];
128
Daniel Dunbar986b5d12010-06-29 18:34:40 +0000129// CHECK: [[Xaddr:%[^ ]+]] = alloca i64, align 8
130// CHECK: load {{.*}}* [[Xaddr]]
Chris Lattner9269d5c2010-06-26 23:03:20 +0000131// CHECK-NEXT: getelementptr inbounds [100 x i32]* %A, i32 0,
132// CHECK-NEXT: load i32*
133}
134
Chris Lattnerf70d8572010-06-27 01:08:03 +0000135int f12() {
136 // PR3150
137 // CHECK: define i32 @f12
138 // CHECK: ret i32 1
139 return 1||1;
140}
Chris Lattner4ac0d832010-06-28 17:12:37 +0000141
142// Make sure negate of fp uses -0.0 for proper -0 handling.
143double f13(double X) {
144 // CHECK: define double @f13
Chris Lattnerce88d0f2010-06-28 18:29:14 +0000145 // CHECK: fsub double -0.0
Chris Lattner4ac0d832010-06-28 17:12:37 +0000146 return -X;
147}
Daniel Dunbarf52697a2010-08-21 02:46:28 +0000148
149// Check operations on incomplete types.
John McCall85515d62010-12-04 12:29:11 +0000150void f14(struct s14 *a) {
Daniel Dunbarf52697a2010-08-21 02:46:28 +0000151 (void) &*a;
152}
153
John McCall85515d62010-12-04 12:29:11 +0000154// CHECK: define void @f15
John McCallfd569002010-12-04 12:43:24 +0000155void 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 McCall85515d62010-12-04 12:29:11 +0000167 // CHECK: ret void
168}
John McCall8d3d6c92011-01-13 02:03:06 +0000169
170// PR8967: this was crashing
171// CHECK: define void @f16()
172void f16() {
173 __extension__({ goto lbl; });
174 lbl:
175 ;
176}