xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/volatile-1.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -Wno-return-type -Wno-unused-value -emit-llvm %s -o - | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // CHECK: @i = common global [[INT:i[0-9]+]] 0
4*f4a2713aSLionel Sambuc volatile int i, j, k;
5*f4a2713aSLionel Sambuc volatile int ar[5];
6*f4a2713aSLionel Sambuc volatile char c;
7*f4a2713aSLionel Sambuc // CHECK: @ci = common global [[CINT:.*]] zeroinitializer
8*f4a2713aSLionel Sambuc volatile _Complex int ci;
9*f4a2713aSLionel Sambuc volatile struct S {
10*f4a2713aSLionel Sambuc #ifdef __cplusplus
11*f4a2713aSLionel Sambuc   void operator =(volatile struct S&o) volatile;
12*f4a2713aSLionel Sambuc #endif
13*f4a2713aSLionel Sambuc   int i;
14*f4a2713aSLionel Sambuc } a, b;
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc //void operator =(volatile struct S&o1, volatile struct S&o2) volatile;
17*f4a2713aSLionel Sambuc int printf(const char *, ...);
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc // Note that these test results are very much specific to C!
21*f4a2713aSLionel Sambuc // Assignments in C++ yield l-values, not r-values, and the situations
22*f4a2713aSLionel Sambuc // that do implicit lvalue-to-rvalue conversion are substantially
23*f4a2713aSLionel Sambuc // reduced.
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test()
test()26*f4a2713aSLionel Sambuc void test() {
27*f4a2713aSLionel Sambuc   // CHECK: load volatile [[INT]]* @i
28*f4a2713aSLionel Sambuc   i;
29*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0), align 4
30*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1), align 4
31*f4a2713aSLionel Sambuc   // CHECK-NEXT: sitofp [[INT]]
32*f4a2713aSLionel Sambuc   (float)(ci);
33*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0), align 4
34*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1), align 4
35*f4a2713aSLionel Sambuc   (void)ci;
36*f4a2713aSLionel Sambuc   // CHECK-NEXT: bitcast
37*f4a2713aSLionel Sambuc   // CHECK-NEXT: memcpy
38*f4a2713aSLionel Sambuc   (void)a;
39*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[R:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0), align 4
40*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[I:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1), align 4
41*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0), align 4
42*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1), align 4
43*f4a2713aSLionel Sambuc   (void)(ci=ci);
44*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[T:%.*]] = load volatile [[INT]]* @j
45*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile [[INT]] [[T]], [[INT]]* @i
46*f4a2713aSLionel Sambuc   (void)(i=j);
47*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[R1:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0), align 4
48*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[I1:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1), align 4
49*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[R2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0), align 4
50*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[I2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1), align 4
51*f4a2713aSLionel Sambuc   // Not sure why they're ordered this way.
52*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[R:%.*]] = add [[INT]] [[R2]], [[R1]]
53*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[I:%.*]] = add [[INT]] [[I2]], [[I1]]
54*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0), align 4
55*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1), align 4
56*f4a2713aSLionel Sambuc   ci+=ci;
57*f4a2713aSLionel Sambuc 
58*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[R1:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0), align 4
59*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[I1:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1), align 4
60*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[R2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0), align 4
61*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[I2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1), align 4
62*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[R:%.*]] = add [[INT]] [[R2]], [[R1]]
63*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[I:%.*]] = add [[INT]] [[I2]], [[I1]]
64*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0), align 4
65*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1), align 4
66*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[R2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0), align 4
67*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[I2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1), align 4
68*f4a2713aSLionel Sambuc   // These additions can be elided
69*f4a2713aSLionel Sambuc   // CHECK-NEXT: add [[INT]] [[R]], [[R2]]
70*f4a2713aSLionel Sambuc   // CHECK-NEXT: add [[INT]] [[I]], [[I2]]
71*f4a2713aSLionel Sambuc   (ci += ci) + ci;
72*f4a2713aSLionel Sambuc   // CHECK-NEXT: call void asm
73*f4a2713aSLionel Sambuc   asm("nop");
74*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
75*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
76*f4a2713aSLionel Sambuc   // CHECK-NEXT: add nsw [[INT]]
77*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
78*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
79*f4a2713aSLionel Sambuc   // CHECK-NEXT: add nsw [[INT]]
80*f4a2713aSLionel Sambuc   (i += j) + k;
81*f4a2713aSLionel Sambuc   // CHECK-NEXT: call void asm
82*f4a2713aSLionel Sambuc   asm("nop");
83*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
84*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
85*f4a2713aSLionel Sambuc   // CHECK-NEXT: add nsw [[INT]]
86*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
87*f4a2713aSLionel Sambuc   // CHECK-NEXT: add nsw [[INT]]
88*f4a2713aSLionel Sambuc   (i += j) + 1;
89*f4a2713aSLionel Sambuc   // CHECK-NEXT: call void asm
90*f4a2713aSLionel Sambuc   asm("nop");
91*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
92*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
93*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
94*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
95*f4a2713aSLionel Sambuc   // CHECK-NEXT: add [[INT]]
96*f4a2713aSLionel Sambuc   // CHECK-NEXT: add [[INT]]
97*f4a2713aSLionel Sambuc   ci+ci;
98*f4a2713aSLionel Sambuc 
99*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
100*f4a2713aSLionel Sambuc   __real i;
101*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
102*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
103*f4a2713aSLionel Sambuc   +ci;
104*f4a2713aSLionel Sambuc   // CHECK-NEXT: call void asm
105*f4a2713aSLionel Sambuc   asm("nop");
106*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
107*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
108*f4a2713aSLionel Sambuc   (void)(i=i);
109*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
110*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
111*f4a2713aSLionel Sambuc   // CHECK-NEXT: sitofp
112*f4a2713aSLionel Sambuc   (float)(i=i);
113*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
114*f4a2713aSLionel Sambuc   (void)i;
115*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
116*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
117*f4a2713aSLionel Sambuc   i=i;
118*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
119*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
120*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
121*f4a2713aSLionel Sambuc   i=i=i;
122*f4a2713aSLionel Sambuc #ifndef __cplusplus
123*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
124*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
125*f4a2713aSLionel Sambuc   (void)__builtin_choose_expr(0, i=i, j=j);
126*f4a2713aSLionel Sambuc #endif
127*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
128*f4a2713aSLionel Sambuc   // CHECK-NEXT: icmp
129*f4a2713aSLionel Sambuc   // CHECK-NEXT: br i1
130*f4a2713aSLionel Sambuc   // CHECK: load volatile
131*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
132*f4a2713aSLionel Sambuc   // CHECK-NEXT: br label
133*f4a2713aSLionel Sambuc   // CHECK: load volatile
134*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
135*f4a2713aSLionel Sambuc   // CHECK-NEXT: br label
136*f4a2713aSLionel Sambuc   k ? (i=i) : (j=j);
137*f4a2713aSLionel Sambuc   // CHECK: phi
138*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
139*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
140*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
141*f4a2713aSLionel Sambuc   (void)(i,(i=i));
142*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
143*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
144*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
145*f4a2713aSLionel Sambuc   i=i,i;
146*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
147*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
148*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
149*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
150*f4a2713aSLionel Sambuc   (i=j,k=j);
151*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
152*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
153*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
154*f4a2713aSLionel Sambuc   (i=j,k);
155*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
156*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
157*f4a2713aSLionel Sambuc   (i,j);
158*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
159*f4a2713aSLionel Sambuc   // CHECK-NEXT: trunc
160*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
161*f4a2713aSLionel Sambuc   // CHECK-NEXT: sext
162*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
163*f4a2713aSLionel Sambuc   i=c=k;
164*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
165*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
166*f4a2713aSLionel Sambuc   // CHECK-NEXT: add nsw [[INT]]
167*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
168*f4a2713aSLionel Sambuc   i+=k;
169*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
170*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
171*f4a2713aSLionel Sambuc   ci;
172*f4a2713aSLionel Sambuc #ifndef __cplusplus
173*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
174*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
175*f4a2713aSLionel Sambuc   (int)ci;
176*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
177*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
178*f4a2713aSLionel Sambuc   // CHECK-NEXT: icmp ne
179*f4a2713aSLionel Sambuc   // CHECK-NEXT: icmp ne
180*f4a2713aSLionel Sambuc   // CHECK-NEXT: or i1
181*f4a2713aSLionel Sambuc   (_Bool)ci;
182*f4a2713aSLionel Sambuc #endif
183*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
184*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
185*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
186*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
187*f4a2713aSLionel Sambuc   ci=ci;
188*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
189*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
190*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
191*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
192*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
193*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
194*f4a2713aSLionel Sambuc   ci=ci=ci;
195*f4a2713aSLionel Sambuc   // CHECK-NEXT: [[T:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1)
196*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile [[INT]] [[T]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1)
197*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile [[INT]] [[T]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1)
198*f4a2713aSLionel Sambuc   __imag ci = __imag ci = __imag ci;
199*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
200*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
201*f4a2713aSLionel Sambuc   __real (i = j);
202*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
203*f4a2713aSLionel Sambuc   __imag i;
204*f4a2713aSLionel Sambuc 
205*f4a2713aSLionel Sambuc   // ============================================================
206*f4a2713aSLionel Sambuc   // FIXME: Test cases we get wrong.
207*f4a2713aSLionel Sambuc 
208*f4a2713aSLionel Sambuc   // A use.  We load all of a into a copy of a, then load i.  gcc forgets to do
209*f4a2713aSLionel Sambuc   // the assignment.
210*f4a2713aSLionel Sambuc   // (a = a).i;
211*f4a2713aSLionel Sambuc 
212*f4a2713aSLionel Sambuc   // ============================================================
213*f4a2713aSLionel Sambuc   // Test cases where we intentionally differ from gcc, due to suspected bugs in
214*f4a2713aSLionel Sambuc   // gcc.
215*f4a2713aSLionel Sambuc 
216*f4a2713aSLionel Sambuc   // Not a use.  gcc forgets to do the assignment.
217*f4a2713aSLionel Sambuc   // CHECK-NEXT: call void @llvm.memcpy{{.*}}, i1 true
218*f4a2713aSLionel Sambuc   // CHECK-NEXT: bitcast
219*f4a2713aSLionel Sambuc   // CHECK-NEXT: call void @llvm.memcpy{{.*}}, i1 true
220*f4a2713aSLionel Sambuc   ((a=a),a);
221*f4a2713aSLionel Sambuc 
222*f4a2713aSLionel Sambuc   // Not a use.  gcc gets this wrong, it doesn't emit the copy!
223*f4a2713aSLionel Sambuc   // (void)(a=a);
224*f4a2713aSLionel Sambuc 
225*f4a2713aSLionel Sambuc   // Not a use.  gcc got this wrong in 4.2 and omitted the side effects
226*f4a2713aSLionel Sambuc   // entirely, but it is fixed in 4.4.0.
227*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
228*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
229*f4a2713aSLionel Sambuc   __imag (i = j);
230*f4a2713aSLionel Sambuc 
231*f4a2713aSLionel Sambuc #ifndef __cplusplus
232*f4a2713aSLionel Sambuc   // A use of the real part
233*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
234*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
235*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
236*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
237*f4a2713aSLionel Sambuc   // CHECK-NEXT: sitofp
238*f4a2713aSLionel Sambuc   (float)(ci=ci);
239*f4a2713aSLionel Sambuc   // Not a use, bug?  gcc treats this as not a use, that's probably a bug due to
240*f4a2713aSLionel Sambuc   // tree folding ignoring volatile.
241*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
242*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
243*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
244*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
245*f4a2713aSLionel Sambuc   (int)(ci=ci);
246*f4a2713aSLionel Sambuc #endif
247*f4a2713aSLionel Sambuc 
248*f4a2713aSLionel Sambuc   // A use.
249*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
250*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
251*f4a2713aSLionel Sambuc   // CHECK-NEXT: sitofp
252*f4a2713aSLionel Sambuc   (float)(i=i);
253*f4a2713aSLionel Sambuc   // A use.  gcc treats this as not a use, that's probably a bug due to tree
254*f4a2713aSLionel Sambuc   // folding ignoring volatile.
255*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
256*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
257*f4a2713aSLionel Sambuc   (int)(i=i);
258*f4a2713aSLionel Sambuc 
259*f4a2713aSLionel Sambuc   // A use.
260*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
261*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
262*f4a2713aSLionel Sambuc   // CHECK-NEXT: sub
263*f4a2713aSLionel Sambuc   -(i=j);
264*f4a2713aSLionel Sambuc   // A use.  gcc treats this a not a use, that's probably a bug due to tree
265*f4a2713aSLionel Sambuc   // folding ignoring volatile.
266*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
267*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
268*f4a2713aSLionel Sambuc   +(i=k);
269*f4a2713aSLionel Sambuc 
270*f4a2713aSLionel Sambuc   // A use. gcc treats this a not a use, that's probably a bug due to tree
271*f4a2713aSLionel Sambuc   // folding ignoring volatile.
272*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
273*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
274*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
275*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
276*f4a2713aSLionel Sambuc   __real (ci=ci);
277*f4a2713aSLionel Sambuc 
278*f4a2713aSLionel Sambuc   // A use.
279*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
280*f4a2713aSLionel Sambuc   // CHECK-NEXT: add
281*f4a2713aSLionel Sambuc   i + 0;
282*f4a2713aSLionel Sambuc   // A use.
283*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
284*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
285*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
286*f4a2713aSLionel Sambuc   // CHECK-NEXT: add
287*f4a2713aSLionel Sambuc   (i=j) + i;
288*f4a2713aSLionel Sambuc   // A use.  gcc treats this as not a use, that's probably a bug due to tree
289*f4a2713aSLionel Sambuc   // folding ignoring volatile.
290*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile
291*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile
292*f4a2713aSLionel Sambuc   // CHECK-NEXT: add
293*f4a2713aSLionel Sambuc   (i=j) + 0;
294*f4a2713aSLionel Sambuc 
295*f4a2713aSLionel Sambuc #ifdef __cplusplus
296*f4a2713aSLionel Sambuc   (i,j)=k;
297*f4a2713aSLionel Sambuc   (j=k,i)=i;
298*f4a2713aSLionel Sambuc   struct { int x; } s, s1;
299*f4a2713aSLionel Sambuc   printf("s is at %p\n", &s);
300*f4a2713aSLionel Sambuc   printf("s is at %p\n", &(s = s1));
301*f4a2713aSLionel Sambuc   printf("s.x is at %p\n", &((s = s1).x));
302*f4a2713aSLionel Sambuc #endif
303*f4a2713aSLionel Sambuc }
304*f4a2713aSLionel Sambuc 
305*f4a2713aSLionel Sambuc extern volatile enum X x;
306*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test1()
test1()307*f4a2713aSLionel Sambuc void test1() {
308*f4a2713aSLionel Sambuc   extern void test1_helper(void);
309*f4a2713aSLionel Sambuc   test1_helper();
310*f4a2713aSLionel Sambuc   // CHECK: call void @test1_helper()
311*f4a2713aSLionel Sambuc   // CHECK-NEXT: ret void
312*f4a2713aSLionel Sambuc   x;
313*f4a2713aSLionel Sambuc   (void) x;
314*f4a2713aSLionel Sambuc   return x;
315*f4a2713aSLionel Sambuc }
316*f4a2713aSLionel Sambuc 
317*f4a2713aSLionel Sambuc // CHECK: define {{.*}} @test2()
test2()318*f4a2713aSLionel Sambuc int test2() {
319*f4a2713aSLionel Sambuc   // CHECK: load volatile i32*
320*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile i32*
321*f4a2713aSLionel Sambuc   // CHECK-NEXT: load volatile i32*
322*f4a2713aSLionel Sambuc   // CHECK-NEXT: add i32
323*f4a2713aSLionel Sambuc   // CHECK-NEXT: add i32
324*f4a2713aSLionel Sambuc   // CHECK-NEXT: store volatile i32
325*f4a2713aSLionel Sambuc   // CHECK-NEXT: ret i32
326*f4a2713aSLionel Sambuc   return i += ci;
327*f4a2713aSLionel Sambuc }
328