blob: f80ee4195803fd821d6ab320ee8468142ad6a179 [file] [log] [blame]
Daniel Dunbara45cf5b2009-03-24 02:24:46 +00001// RUN: clang-cc %s -emit-llvm -o -
Chris Lattner7977cca2008-01-02 21:54:09 +00002
3// PR1895
4// sizeof function
5int zxcv(void);
6int x=sizeof(zxcv);
7int y=__alignof__(zxcv);
8
Chris Lattner20455f22008-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 Lattner05ba4cb2008-01-30 07:01:17 +000017_Bool test2b;
18int test2() {if (test2b);}
19
Chris Lattnera94035b2008-01-31 04:12:50 +000020// PR1921
21int test3() {
22 const unsigned char *bp;
23 bp -= (short)1;
24}
25
Chris Lattner3b418d82008-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 Lattnere6c693d2008-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 Lopese236a482008-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 Lopes0e33c682008-11-19 17:44:31 +000048
49// this one shouldn't fold as well
50void eMaisUma() {
51 double t[1];
52 if (*t)
53 return;
54}
Chris Lattner60dcdc72009-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 Lattner63d06ab2009-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 Lattner60dcdc72009-02-11 07:21:43 +000069
Chris Lattnerc2a0b972009-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 Lattner28bcf1a2009-03-18 18:28:57 +000082union f3_x {int x; float y;};
83int f3() {return ((union f3_x)2).x;}
84
Chris Lattnerab17fb22009-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 Dunbarbf1fe8c2009-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 Lattner2f343dd2009-04-21 23:00:09 +000097
98// PR4026
99void f7() {
100 __func__;
101}