Clang Project

clang_source_code/test/CodeGen/exprs.c
1// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s
2
3// PR1895
4// sizeof function
5int zxcv(void);
6int x=sizeof(zxcv);
7int y=__alignof__(zxcv);
8
9
10void *test(int *i) {
11 short a = 1;
12 i += a;
13 i + a;
14 a + i;
15}
16
17_Bool test2b; 
18int test2() { if (test2b); return 0; }
19
20// PR1921
21int test3() {
22  const unsigned char *bp;
23  bp -= (short)1;
24}
25
26// 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
37// 'const float' promotes to double in varargs.
38int test5(const float x, float float_number) {
39  return __builtin_isless(x, float_number);
40}
41
42// this one shouldn't fold
43int ola() {
44  int a=2;
45  if ((0, (int)a) & 2) { return 1; }
46  return 2;
47}
48
49// this one shouldn't fold as well
50void eMaisUma() {
51  double t[1];
52  if (*t)
53    return;
54}
55
56// rdar://6520707
57void f0(void (*fp)(void), void (*fp2)(void)) {
58  int x = fp - fp2;
59}
60
61// noop casts as lvalues.
62struct X {
63  int Y;
64};
65struct X foo();
66int bar() {
67  return ((struct X)foo()).Y + 1;
68}
69
70// 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
82union f3_x {int x; float y;};
83int f3() {return ((union f3_x)2).x;}
84
85union 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;}
91
92// ?: in "lvalue"
93struct s6 { int f0; };
94int f6(int a0, struct s6 a1, struct s6 a2) {
95  return (a0 ? a1 : a2).f0;
96}
97
98// PR4026
99void f7() {
100  __func__;
101}
102
103// PR4067
104int f8() {
105  return ({ foo(); }).Y;
106}
107
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
119void f10() {
120  __builtin_sin(0);
121}
122
123// rdar://7530813
124// CHECK-LABEL: define i32 @f11
125int f11(long X) {
126  int A[100];
127  return A[X];
128
129// CHECK: [[Xaddr:%[^ ]+]] = alloca i64, align 8
130// CHECK: [[A:%.*]] = alloca [100 x i32], align
131// CHECK: [[X:%.*]] = load {{.*}}, {{.*}}* [[Xaddr]]
132// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [100 x i32], [100 x i32]* [[A]], i64 0, i64 [[X]]
133// CHECK-NEXT: load i32, i32* [[T0]], align 4
134}
135
136int f12() {
137  // PR3150
138  // CHECK-LABEL: define i32 @f12
139  // CHECK: ret i32 1
140  return 1||1;
141}
142
143// Make sure negate of fp uses -0.0 for proper -0 handling.
144double f13(double X) {
145  // CHECK-LABEL: define double @f13
146  // CHECK: fsub double -0.0
147  return -X;
148}
149
150// Check operations on incomplete types.
151void f14(struct s14 *a) {
152  (void) &*a;
153}
154
155// CHECK-LABEL: define void @f15
156void f15() {
157  extern void f15_start(void);
158  f15_start();
159  // CHECK: call void @f15_start()
160
161  extern void *f15_v(void);
162  extern const void *f15_cv(void);
163  extern volatile void *f15_vv(void);
164  *f15_v(); *f15_v(), *f15_v(); f15_v() ? *f15_v() : *f15_v();
165  *f15_cv(); *f15_cv(), *f15_cv(); f15_cv() ? *f15_cv() : *f15_cv();
166  *f15_vv(); *f15_vv(), *f15_vv(); f15_vv() ? *f15_vv() : *f15_vv();
167  // CHECK-NOT: load
168  // CHECK: ret void
169}
170
171// PR8967: this was crashing
172// CHECK-LABEL: define void @f16()
173void f16() {
174  __extension__({ goto lbl; });
175 lbl:
176  ;
177}
178
179// PR13704: negative increment in i128 is not preserved.
180// CHECK-LABEL: define void @f17()
181void f17() {
182  extern void extfunc(__int128);
183  __int128 x = 2;
184  x--;
185  extfunc(x);
186// CHECK: add nsw i128 %{{.}}, -1
187}
188
189// PR23597: We should evaluate union cast operands even if the cast is unused.
190typedef union u {
191    int i;
192} strct;
193int returns_int(void);
194void f18() {
195  (strct)returns_int();
196}
197// CHECK-LABEL: define void @f18()
198// CHECK: call i32 @returns_int()
199