xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/volatile.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple=%itanium_abi_triple -emit-llvm < %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-IT
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple=%ms_abi_triple -emit-llvm < %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-MS
3f4a2713aSLionel Sambuc 
4f4a2713aSLionel Sambuc int S;
5f4a2713aSLionel Sambuc volatile int vS;
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc int* pS;
8f4a2713aSLionel Sambuc volatile int* pvS;
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc int A[10];
11f4a2713aSLionel Sambuc volatile int vA[10];
12f4a2713aSLionel Sambuc 
13f4a2713aSLionel Sambuc struct { int x; } F;
14f4a2713aSLionel Sambuc struct { volatile int x; } vF;
15f4a2713aSLionel Sambuc 
16f4a2713aSLionel Sambuc struct { int x; } F2;
17f4a2713aSLionel Sambuc volatile struct { int x; } vF2;
18f4a2713aSLionel Sambuc volatile struct { int x; } *vpF2;
19f4a2713aSLionel Sambuc 
20f4a2713aSLionel Sambuc struct { struct { int y; } x; } F3;
21f4a2713aSLionel Sambuc volatile struct { struct { int y; } x; } vF3;
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc struct { int x:3; } BF;
24f4a2713aSLionel Sambuc struct { volatile int x:3; } vBF;
25f4a2713aSLionel Sambuc 
26f4a2713aSLionel Sambuc typedef int v4si __attribute__ ((vector_size (16)));
27f4a2713aSLionel Sambuc v4si V;
28f4a2713aSLionel Sambuc volatile v4si vV;
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc typedef __attribute__(( ext_vector_type(4) )) int extv4;
31f4a2713aSLionel Sambuc extv4 VE;
32f4a2713aSLionel Sambuc volatile extv4 vVE;
33f4a2713aSLionel Sambuc 
34f4a2713aSLionel Sambuc volatile struct {int x;} aggFct(void);
35f4a2713aSLionel Sambuc 
36f4a2713aSLionel Sambuc typedef volatile int volatile_int;
37f4a2713aSLionel Sambuc volatile_int vtS;
38f4a2713aSLionel Sambuc 
main()39f4a2713aSLionel Sambuc int main() {
40f4a2713aSLionel Sambuc   int i;
41f4a2713aSLionel Sambuc // CHECK: [[I:%[a-zA-Z0-9_.]+]] = alloca i32
42f4a2713aSLionel Sambuc   // load
43f4a2713aSLionel Sambuc   i=S;
44f4a2713aSLionel Sambuc // CHECK: load i32* @S
45f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
46f4a2713aSLionel Sambuc   i=vS;
47f4a2713aSLionel Sambuc // CHECK: load volatile i32* @vS
48f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
49f4a2713aSLionel Sambuc   i=*pS;
50f4a2713aSLionel Sambuc // CHECK: [[PS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pS
51f4a2713aSLionel Sambuc // CHECK: load i32* [[PS_VAL]]
52f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
53f4a2713aSLionel Sambuc   i=*pvS;
54f4a2713aSLionel Sambuc // CHECK: [[PVS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pvS
55f4a2713aSLionel Sambuc // CHECK: load volatile i32* [[PVS_VAL]]
56f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
57f4a2713aSLionel Sambuc   i=A[2];
58f4a2713aSLionel Sambuc // CHECK: load i32* getelementptr {{.*}} @A
59f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
60f4a2713aSLionel Sambuc   i=vA[2];
61f4a2713aSLionel Sambuc // CHECK: load volatile i32* getelementptr {{.*}} @vA
62f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
63f4a2713aSLionel Sambuc   i=F.x;
64f4a2713aSLionel Sambuc // CHECK: load i32* getelementptr {{.*}} @F
65f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
66f4a2713aSLionel Sambuc   i=vF.x;
67f4a2713aSLionel Sambuc // CHECK: load volatile i32* getelementptr {{.*}} @vF
68f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
69f4a2713aSLionel Sambuc   i=F2.x;
70f4a2713aSLionel Sambuc // CHECK: load i32* getelementptr {{.*}} @F2
71f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
72f4a2713aSLionel Sambuc   i=vF2.x;
73f4a2713aSLionel Sambuc // CHECK: load volatile i32* getelementptr {{.*}} @vF2
74f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
75f4a2713aSLionel Sambuc   i=vpF2->x;
76f4a2713aSLionel Sambuc // CHECK: [[VPF2_VAL:%[a-zA-Z0-9_.]+]] = load {{%[a-zA-Z0-9_.]+}}** @vpF2
77f4a2713aSLionel Sambuc // CHECK: [[ELT:%[a-zA-Z0-9_.]+]] = getelementptr {{.*}} [[VPF2_VAL]]
78f4a2713aSLionel Sambuc // CHECK: load volatile i32* [[ELT]]
79f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
80f4a2713aSLionel Sambuc   i=F3.x.y;
81f4a2713aSLionel Sambuc // CHECK: load i32* getelementptr {{.*}} @F3
82f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
83f4a2713aSLionel Sambuc   i=vF3.x.y;
84f4a2713aSLionel Sambuc // CHECK: load volatile i32* getelementptr {{.*}} @vF3
85f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
86f4a2713aSLionel Sambuc   i=BF.x;
87*0a6a1f1dSLionel Sambuc // CHECK-IT: load i8* getelementptr {{.*}} @BF
88*0a6a1f1dSLionel Sambuc // CHECK-MS: load i32* getelementptr {{.*}} @BF
89f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
90f4a2713aSLionel Sambuc   i=vBF.x;
91*0a6a1f1dSLionel Sambuc // CHECK-IT: load volatile i8* getelementptr {{.*}} @vBF
92*0a6a1f1dSLionel Sambuc // CHECK-MS: load volatile i32* getelementptr {{.*}} @vBF
93f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
94f4a2713aSLionel Sambuc   i=V[3];
95f4a2713aSLionel Sambuc // CHECK: load <4 x i32>* @V
96f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
97f4a2713aSLionel Sambuc   i=vV[3];
98f4a2713aSLionel Sambuc // CHECK: load volatile <4 x i32>* @vV
99f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
100f4a2713aSLionel Sambuc   i=VE.yx[1];
101f4a2713aSLionel Sambuc // CHECK: load <4 x i32>* @VE
102f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
103f4a2713aSLionel Sambuc   i=vVE.zy[1];
104f4a2713aSLionel Sambuc // CHECK: load volatile <4 x i32>* @vVE
105f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
106f4a2713aSLionel Sambuc   i = aggFct().x; // Note: not volatile
107f4a2713aSLionel Sambuc   // N.b. Aggregate return is extremely target specific, all we can
108f4a2713aSLionel Sambuc   // really say here is that there probably shouldn't be a volatile
109f4a2713aSLionel Sambuc   // load.
110f4a2713aSLionel Sambuc // CHECK-NOT: load volatile
111f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
112f4a2713aSLionel Sambuc   i=vtS;
113f4a2713aSLionel Sambuc // CHECK: load volatile i32* @vtS
114f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
115f4a2713aSLionel Sambuc 
116f4a2713aSLionel Sambuc 
117f4a2713aSLionel Sambuc   // store
118f4a2713aSLionel Sambuc   S=i;
119f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
120f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* @S
121f4a2713aSLionel Sambuc   vS=i;
122f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
123f4a2713aSLionel Sambuc // CHECK: store volatile i32 {{.*}}, i32* @vS
124f4a2713aSLionel Sambuc   *pS=i;
125f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
126f4a2713aSLionel Sambuc // CHECK: [[PS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pS
127f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[PS_VAL]]
128f4a2713aSLionel Sambuc   *pvS=i;
129f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
130f4a2713aSLionel Sambuc // CHECK: [[PVS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pvS
131f4a2713aSLionel Sambuc // CHECK: store volatile i32 {{.*}}, i32* [[PVS_VAL]]
132f4a2713aSLionel Sambuc   A[2]=i;
133f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
134f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* getelementptr {{.*}} @A
135f4a2713aSLionel Sambuc   vA[2]=i;
136f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
137f4a2713aSLionel Sambuc // CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vA
138f4a2713aSLionel Sambuc   F.x=i;
139f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
140f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* getelementptr {{.*}} @F
141f4a2713aSLionel Sambuc   vF.x=i;
142f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
143f4a2713aSLionel Sambuc // CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vF
144f4a2713aSLionel Sambuc   F2.x=i;
145f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
146f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* getelementptr {{.*}} @F2
147f4a2713aSLionel Sambuc   vF2.x=i;
148f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
149f4a2713aSLionel Sambuc // CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vF2
150f4a2713aSLionel Sambuc   vpF2->x=i;
151f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
152f4a2713aSLionel Sambuc // CHECK: [[VPF2_VAL:%[a-zA-Z0-9_.]+]] = load {{%[a-zA-Z0-9._]+}}** @vpF2
153f4a2713aSLionel Sambuc // CHECK: [[ELT:%[a-zA-Z0-9_.]+]] = getelementptr {{.*}} [[VPF2_VAL]]
154f4a2713aSLionel Sambuc // CHECK: store volatile i32 {{.*}}, i32* [[ELT]]
155f4a2713aSLionel Sambuc   vF3.x.y=i;
156f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
157f4a2713aSLionel Sambuc // CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vF3
158f4a2713aSLionel Sambuc   BF.x=i;
159f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
160*0a6a1f1dSLionel Sambuc // CHECK-IT: load i8* getelementptr {{.*}} @BF
161*0a6a1f1dSLionel Sambuc // CHECK-MS: load i32* getelementptr {{.*}} @BF
162*0a6a1f1dSLionel Sambuc // CHECK-IT: store i8 {{.*}}, i8* getelementptr {{.*}} @BF
163*0a6a1f1dSLionel Sambuc // CHECK-MS: store i32 {{.*}}, i32* getelementptr {{.*}} @BF
164f4a2713aSLionel Sambuc   vBF.x=i;
165f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
166*0a6a1f1dSLionel Sambuc // CHECK-IT: load volatile i8* getelementptr {{.*}} @vBF
167*0a6a1f1dSLionel Sambuc // CHECK-MS: load volatile i32* getelementptr {{.*}} @vBF
168*0a6a1f1dSLionel Sambuc // CHECK-IT: store volatile i8 {{.*}}, i8* getelementptr {{.*}} @vBF
169*0a6a1f1dSLionel Sambuc // CHECK-MS: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vBF
170f4a2713aSLionel Sambuc   V[3]=i;
171f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
172f4a2713aSLionel Sambuc // CHECK: load <4 x i32>* @V
173f4a2713aSLionel Sambuc // CHECK: store <4 x i32> {{.*}}, <4 x i32>* @V
174f4a2713aSLionel Sambuc   vV[3]=i;
175f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
176f4a2713aSLionel Sambuc // CHECK: load volatile <4 x i32>* @vV
177f4a2713aSLionel Sambuc // CHECK: store volatile <4 x i32> {{.*}}, <4 x i32>* @vV
178f4a2713aSLionel Sambuc   vtS=i;
179f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
180f4a2713aSLionel Sambuc // CHECK: store volatile i32 {{.*}}, i32* @vtS
181f4a2713aSLionel Sambuc 
182f4a2713aSLionel Sambuc   // other ops:
183f4a2713aSLionel Sambuc   ++S;
184f4a2713aSLionel Sambuc // CHECK: load i32* @S
185f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* @S
186f4a2713aSLionel Sambuc   ++vS;
187f4a2713aSLionel Sambuc // CHECK: load volatile i32* @vS
188f4a2713aSLionel Sambuc // CHECK: store volatile i32 {{.*}}, i32* @vS
189f4a2713aSLionel Sambuc   i+=S;
190f4a2713aSLionel Sambuc // CHECK: load i32* @S
191f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
192f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
193f4a2713aSLionel Sambuc   i+=vS;
194f4a2713aSLionel Sambuc // CHECK: load volatile i32* @vS
195f4a2713aSLionel Sambuc // CHECK: load i32* [[I]]
196f4a2713aSLionel Sambuc // CHECK: store i32 {{.*}}, i32* [[I]]
197f4a2713aSLionel Sambuc   ++vtS;
198f4a2713aSLionel Sambuc // CHECK: load volatile i32* @vtS
199f4a2713aSLionel Sambuc // CHECK: store volatile i32 {{.*}}, i32* @vtS
200f4a2713aSLionel Sambuc   (void)vF2;
201f4a2713aSLionel Sambuc   // From vF2 to a temporary
202f4a2713aSLionel Sambuc // CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* {{.*}} @vF2 {{.*}}, i1 true)
203f4a2713aSLionel Sambuc   vF2 = vF2;
204f4a2713aSLionel Sambuc   // vF2 to itself
205f4a2713aSLionel Sambuc // CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true)
206f4a2713aSLionel Sambuc   vF2 = vF2 = vF2;
207f4a2713aSLionel Sambuc   // vF2 to itself twice
208f4a2713aSLionel Sambuc // CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true)
209f4a2713aSLionel Sambuc // CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true)
210f4a2713aSLionel Sambuc   vF2 = (vF2, vF2);
211f4a2713aSLionel Sambuc   // vF2 to a temporary, then vF2 to itself
212f4a2713aSLionel Sambuc // CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* {{.*@vF2.*}}, i1 true)
213f4a2713aSLionel Sambuc // CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true)
214f4a2713aSLionel Sambuc }
215