1 // RUN: %clang_cc1 -disable-noundef-analysis -triple x86_64-gnu-linux -O3 -disable-llvm-passes -I%S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LIN,LIN64,NoNewStructPathTBAA
2 // RUN: %clang_cc1 -disable-noundef-analysis -triple x86_64-gnu-linux -O3 -disable-llvm-passes -I%S -new-struct-path-tbaa -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LIN,LIN64,NewStructPathTBAA
3 
4 // RUN: %clang_cc1 -disable-noundef-analysis -triple x86_64-windows-pc -O3 -disable-llvm-passes -I%S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,WIN,WIN64,NoNewStructPathTBAA
5 // RUN: %clang_cc1 -disable-noundef-analysis -triple x86_64-windows-pc -O3 -disable-llvm-passes -I%S -new-struct-path-tbaa -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,WIN,WIN64,NewStructPathTBAA
6 
7 // RUN: %clang_cc1 -disable-noundef-analysis -triple i386-gnu-linux -O3 -disable-llvm-passes -I%S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LIN,LIN32,NoNewStructPathTBAA
8 // RUN: %clang_cc1 -disable-noundef-analysis -triple i386-gnu-linux -O3 -disable-llvm-passes -I%S -new-struct-path-tbaa -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LIN,LIN32,NewStructPathTBAA
9 
10 // RUN: %clang_cc1 -disable-noundef-analysis -triple i386-windows-pc -O3 -disable-llvm-passes -I%S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,WIN,WIN32,NoNewStructPathTBAA
11 // RUN: %clang_cc1 -disable-noundef-analysis -triple i386-windows-pc -O3 -disable-llvm-passes -I%S -new-struct-path-tbaa -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,WIN,WIN32,NewStructPathTBAA
12 
13 namespace std {
14   class type_info { public: virtual ~type_info(); private: const char * name; };
15 } // namespace std
16 
17 // Ensure that the layout for these structs is the same as the normal bitfield
18 // layouts.
19 struct BitFieldsByte {
20   _BitInt(7) A : 3;
21   _BitInt(7) B : 3;
22   _BitInt(7) C : 2;
23 };
24 // CHECK: %struct.BitFieldsByte = type { i8 }
25 
26 struct BitFieldsShort {
27   _BitInt(15) A : 3;
28   _BitInt(15) B : 3;
29   _BitInt(15) C : 2;
30 };
31 // LIN: %struct.BitFieldsShort = type { i8, i8 }
32 // WIN: %struct.BitFieldsShort = type { i16 }
33 
34 struct BitFieldsInt {
35   _BitInt(31) A : 3;
36   _BitInt(31) B : 3;
37   _BitInt(31) C : 2;
38 };
39 // LIN: %struct.BitFieldsInt = type { i8, [3 x i8] }
40 // WIN: %struct.BitFieldsInt = type { i32 }
41 
42 struct BitFieldsLong {
43   _BitInt(63) A : 3;
44   _BitInt(63) B : 3;
45   _BitInt(63) C : 2;
46 };
47 // LIN64: %struct.BitFieldsLong = type { i8, [7 x i8] }
48 // LIN32: %struct.BitFieldsLong = type { i8, [3 x i8] }
49 // WIN: %struct.BitFieldsLong = type { i64 }
50 
51 struct HasBitIntFirst {
52   _BitInt(35) A;
53   int B;
54 };
55 // CHECK: %struct.HasBitIntFirst = type { i35, i32 }
56 
57 struct HasBitIntLast {
58   int A;
59   _BitInt(35) B;
60 };
61 // CHECK: %struct.HasBitIntLast = type { i32, i35 }
62 
63 struct HasBitIntMiddle {
64   int A;
65   _BitInt(35) B;
66   int C;
67 };
68 // CHECK: %struct.HasBitIntMiddle = type { i32, i35, i32 }
69 
70 // Force emitting of the above structs.
71 void StructEmit() {
72   BitFieldsByte A;
73   BitFieldsShort B;
74   BitFieldsInt C;
75   BitFieldsLong D;
76 
77   HasBitIntFirst E;
78   HasBitIntLast F;
79   HasBitIntMiddle G;
80 }
81 
82 void BitfieldAssignment() {
83   // LIN: define{{.*}} void @_Z18BitfieldAssignmentv
84   // WIN: define dso_local void  @"?BitfieldAssignment@@YAXXZ"
85   BitFieldsByte B;
86   B.A = 3;
87   B.B = 2;
88   B.C = 1;
89   // First one is used for the lifetime start, skip that.
90   // CHECK: bitcast %struct.BitFieldsByte*
91   // CHECK: %[[BFType:.+]] = bitcast %struct.BitFieldsByte*
92   // CHECK: %[[LOADA:.+]] = load i8, i8* %[[BFType]]
93   // CHECK: %[[CLEARA:.+]] = and i8 %[[LOADA]], -8
94   // CHECK: %[[SETA:.+]] = or i8 %[[CLEARA]], 3
95   // CHECK: %[[BFType:.+]] = bitcast %struct.BitFieldsByte*
96   // CHECK: %[[LOADB:.+]] = load i8, i8* %[[BFType]]
97   // CHECK: %[[CLEARB:.+]] = and i8 %[[LOADB]], -57
98   // CHECK: %[[SETB:.+]] = or i8 %[[CLEARB]], 16
99   // CHECK: %[[BFType:.+]] = bitcast %struct.BitFieldsByte*
100   // CHECK: %[[LOADC:.+]] = load i8, i8* %[[BFType]]
101   // CHECK: %[[CLEARC:.+]] = and i8 %[[LOADC]], 63
102   // CHECK: %[[SETC:.+]] = or i8 %[[CLEARC]], 64
103 }
104 
105 enum AsEnumUnderlyingType : _BitInt(9) {
106   A,B,C
107 };
108 
109 void UnderlyingTypeUsage(AsEnumUnderlyingType Param) {
110   // LIN: define{{.*}} void @_Z19UnderlyingTypeUsage20AsEnumUnderlyingType(i9 signext %
111   // WIN64: define dso_local void @"?UnderlyingTypeUsage@@YAXW4AsEnumUnderlyingType@@@Z"(i9 %
112   // WIN32: define dso_local void @"?UnderlyingTypeUsage@@YAXW4AsEnumUnderlyingType@@@Z"(i9 signext %
113   AsEnumUnderlyingType Var;
114   // CHECK: alloca i9, align 2
115   // CHECK: store i9 %{{.*}}, align 2
116 }
117 
118 unsigned _BitInt(33) ManglingTestRetParam(unsigned _BitInt(33) Param) {
119 // LIN64: define{{.*}} i64 @_Z20ManglingTestRetParamDU33_(i64 %
120 // LIN32: define{{.*}} i33 @_Z20ManglingTestRetParamDU33_(i33 %
121 // WIN: define dso_local i33 @"?ManglingTestRetParam@@YAU?$_UBitInt@$0CB@@__clang@@U12@@Z"(i33
122   return 0;
123 }
124 
125 _BitInt(33) ManglingTestRetParam(_BitInt(33) Param) {
126 // LIN64: define{{.*}} i64 @_Z20ManglingTestRetParamDB33_(i64 %
127 // LIN32: define{{.*}} i33 @_Z20ManglingTestRetParamDB33_(i33 %
128 // WIN: define dso_local i33 @"?ManglingTestRetParam@@YAU?$_BitInt@$0CB@@__clang@@U12@@Z"(i33
129   return 0;
130 }
131 
132 template<typename T>
133 void ManglingTestTemplateParam(T&);
134 template<_BitInt(99) T>
135 void ManglingTestNTTP();
136 template <int N>
137 auto ManglingDependent() -> decltype(_BitInt(N){});
138 
139 
140 void ManglingInstantiator() {
141   // LIN: define{{.*}} void @_Z20ManglingInstantiatorv()
142   // WIN: define dso_local void @"?ManglingInstantiator@@YAXXZ"()
143   _BitInt(93) A;
144   ManglingTestTemplateParam(A);
145 // LIN: call void @_Z25ManglingTestTemplateParamIDB93_EvRT_(i93*
146 // WIN64: call void @"??$ManglingTestTemplateParam@U?$_BitInt@$0FN@@__clang@@@@YAXAEAU?$_BitInt@$0FN@@__clang@@@Z"(i93*
147 // WIN32: call void @"??$ManglingTestTemplateParam@U?$_BitInt@$0FN@@__clang@@@@YAXAAU?$_BitInt@$0FN@@__clang@@@Z"(i93*
148   constexpr _BitInt(93) B = 993;
149   ManglingTestNTTP<38>();
150   // LIN: call void @_Z16ManglingTestNTTPILDB99_38EEvv()
151   // WIN: call void @"??$ManglingTestNTTP@$0CG@@@YAXXZ"()
152   ManglingTestNTTP<B>();
153   // LIN: call void @_Z16ManglingTestNTTPILDB99_993EEvv()
154   // WIN: call void @"??$ManglingTestNTTP@$0DOB@@@YAXXZ"()
155   ManglingDependent<4>();
156   // LIN: call signext i4 @_Z17ManglingDependentILi4EEDTtlDBT__EEv()
157   // WIN64: call i4 @"??$ManglingDependent@$03@@YAU?$_BitInt@$03@__clang@@XZ"()
158   // WIN32: call signext i4 @"??$ManglingDependent@$03@@YAU?$_BitInt@$03@__clang@@XZ"()
159 }
160 
161 void TakesVarargs(int i, ...) {
162   // LIN: define{{.*}} void @_Z12TakesVarargsiz(i32 %i, ...)
163   // WIN: define dso_local void @"?TakesVarargs@@YAXHZZ"(i32 %i, ...)
164 
165   __builtin_va_list args;
166   // LIN64: %[[ARGS:.+]] = alloca [1 x %struct.__va_list_tag]
167   // LIN32: %[[ARGS:.+]] = alloca i8*
168   // WIN: %[[ARGS:.+]] = alloca i8*
169   __builtin_va_start(args, i);
170   // LIN64: %[[STARTAD:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %[[ARGS]]
171   // LIN64: %[[STARTAD1:.+]] = bitcast %struct.__va_list_tag* %[[STARTAD]] to i8*
172   // LIN64: call void @llvm.va_start(i8* %[[STARTAD1]])
173   // LIN32: %[[ARGSLLIFETIMESTART:.+]] = bitcast i8** %[[ARGS]] to i8*
174   // LIN32: %[[ARGSSTART:.+]] = bitcast i8** %[[ARGS]] to i8*
175   // LIN32: call void @llvm.va_start(i8* %[[ARGSSTART]])
176   // WIN: %[[ARGSLLIFETIMESTART:.+]] = bitcast i8** %[[ARGS]] to i8*
177   // WIN: %[[ARGSSTART:.+]] = bitcast i8** %[[ARGS]] to i8*
178   // WIN: call void @llvm.va_start(i8* %[[ARGSSTART]])
179 
180   _BitInt(92) A = __builtin_va_arg(args, _BitInt(92));
181   // LIN64: %[[AD1:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %[[ARGS]]
182   // LIN64: %[[OFA_P1:.+]] = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %[[AD1]], i32 0, i32 0
183   // LIN64: %[[GPOFFSET:.+]] = load i32, i32* %[[OFA_P1]]
184   // LIN64: %[[FITSINGP:.+]] = icmp ule i32 %[[GPOFFSET]], 32
185   // LIN64: br i1 %[[FITSINGP]]
186   // LIN64: %[[BC1:.+]] = phi i92*
187   // LIN64: %[[LOAD1:.+]] = load i92, i92* %[[BC1]]
188   // LIN64: store i92 %[[LOAD1]], i92*
189 
190   // LIN32: %[[CUR1:.+]] = load i8*, i8** %[[ARGS]]
191   // LIN32: %[[NEXT1:.+]] = getelementptr inbounds i8, i8* %[[CUR1]], i32 12
192   // LIN32: store i8* %[[NEXT1]], i8** %[[ARGS]]
193   // LIN32: %[[BC1:.+]] = bitcast i8* %[[CUR1]] to i92*
194   // LIN32: %[[LOADV1:.+]] = load i92, i92* %[[BC1]]
195   // LIN32: store i92 %[[LOADV1]], i92*
196 
197   // WIN64: %[[CUR1:.+]] = load i8*, i8** %[[ARGS]]
198   // WIN64: %[[NEXT1:.+]] = getelementptr inbounds i8, i8* %[[CUR1]], i64 8
199   // WIN64: store i8* %[[NEXT1]], i8** %[[ARGS]]
200   // WIN64: %[[BC1:.+]] = bitcast i8* %[[CUR1]] to i92**
201   // WIN64: %[[LOADP1:.+]] = load i92*, i92** %[[BC1]]
202   // WIN64: %[[LOADV1:.+]] = load i92, i92* %[[LOADP1]]
203   // WIN64: store i92 %[[LOADV1]], i92*
204 
205   // WIN32: %[[CUR1:.+]] = load i8*, i8** %[[ARGS]]
206   // WIN32: %[[NEXT1:.+]] = getelementptr inbounds i8, i8* %[[CUR1]], i32 16
207   // WIN32: store i8* %[[NEXT1]], i8** %[[ARGS]]
208   // WIN32: %[[BC1:.+]] = bitcast i8* %[[CUR1]] to i92*
209   // WIN32: %[[LOADV1:.+]] = load i92, i92* %[[BC1]]
210   // WIN32: store i92 %[[LOADV1]], i92*
211 
212 
213   _BitInt(31) B = __builtin_va_arg(args, _BitInt(31));
214   // LIN64: %[[AD2:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %[[ARGS]]
215   // LIN64: %[[OFA_P2:.+]] = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %[[AD2]], i32 0, i32 0
216   // LIN64: %[[GPOFFSET:.+]] = load i32, i32* %[[OFA_P2]]
217   // LIN64: %[[FITSINGP:.+]] = icmp ule i32 %[[GPOFFSET]], 40
218   // LIN64: br i1 %[[FITSINGP]]
219   // LIN64: %[[BC1:.+]] = phi i31*
220   // LIN64: %[[LOAD1:.+]] = load i31, i31* %[[BC1]]
221   // LIN64: store i31 %[[LOAD1]], i31*
222 
223   // LIN32: %[[CUR2:.+]] = load i8*, i8** %[[ARGS]]
224   // LIN32: %[[NEXT2:.+]] = getelementptr inbounds i8, i8* %[[CUR2]], i32 4
225   // LIN32: store i8* %[[NEXT2]], i8** %[[ARGS]]
226   // LIN32: %[[BC2:.+]] = bitcast i8* %[[CUR2]] to i31*
227   // LIN32: %[[LOADV2:.+]] = load i31, i31* %[[BC2]]
228   // LIN32: store i31 %[[LOADV2]], i31*
229 
230   // WIN64: %[[CUR2:.+]] = load i8*, i8** %[[ARGS]]
231   // WIN64: %[[NEXT2:.+]] = getelementptr inbounds i8, i8* %[[CUR2]], i64 8
232   // WIN64: store i8* %[[NEXT2]], i8** %[[ARGS]]
233   // WIN64: %[[BC2:.+]] = bitcast i8* %[[CUR2]] to i31*
234   // WIN64: %[[LOADV2:.+]] = load i31, i31* %[[BC2]]
235   // WIN64: store i31 %[[LOADV2]], i31*
236 
237   // WIN32: %[[CUR2:.+]] = load i8*, i8** %[[ARGS]]
238   // WIN32: %[[NEXT2:.+]] = getelementptr inbounds i8, i8* %[[CUR2]], i32 4
239   // WIN32: store i8* %[[NEXT2]], i8** %[[ARGS]]
240   // WIN32: %[[BC2:.+]] = bitcast i8* %[[CUR2]] to i31*
241   // WIN32: %[[LOADV2:.+]] = load i31, i31* %[[BC2]]
242   // WIN32: store i31 %[[LOADV2]], i31*
243 
244   _BitInt(16) C = __builtin_va_arg(args, _BitInt(16));
245   // LIN64: %[[AD3:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %[[ARGS]]
246   // LIN64: %[[OFA_P3:.+]] = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %[[AD3]], i32 0, i32 0
247   // LIN64: %[[GPOFFSET:.+]] = load i32, i32* %[[OFA_P3]]
248   // LIN64: %[[FITSINGP:.+]] = icmp ule i32 %[[GPOFFSET]], 40
249   // LIN64: br i1 %[[FITSINGP]]
250   // LIN64: %[[BC1:.+]] = phi i16*
251   // LIN64: %[[LOAD1:.+]] = load i16, i16* %[[BC1]]
252   // LIN64: store i16 %[[LOAD1]], i16*
253 
254   // LIN32: %[[CUR3:.+]] = load i8*, i8** %[[ARGS]]
255   // LIN32: %[[NEXT3:.+]] = getelementptr inbounds i8, i8* %[[CUR3]], i32 4
256   // LIN32: store i8* %[[NEXT3]], i8** %[[ARGS]]
257   // LIN32: %[[BC3:.+]] = bitcast i8* %[[CUR3]] to i16*
258   // LIN32: %[[LOADV3:.+]] = load i16, i16* %[[BC3]]
259   // LIN32: store i16 %[[LOADV3]], i16*
260 
261   // WIN64: %[[CUR3:.+]] = load i8*, i8** %[[ARGS]]
262   // WIN64: %[[NEXT3:.+]] = getelementptr inbounds i8, i8* %[[CUR3]], i64 8
263   // WIN64: store i8* %[[NEXT3]], i8** %[[ARGS]]
264   // WIN64: %[[BC3:.+]] = bitcast i8* %[[CUR3]] to i16*
265   // WIN64: %[[LOADV3:.+]] = load i16, i16* %[[BC3]]
266   // WIN64: store i16 %[[LOADV3]], i16*
267 
268   // WIN32: %[[CUR3:.+]] = load i8*, i8** %[[ARGS]]
269   // WIN32: %[[NEXT3:.+]] = getelementptr inbounds i8, i8* %[[CUR3]], i32 4
270   // WIN32: store i8* %[[NEXT3]], i8** %[[ARGS]]
271   // WIN32: %[[BC3:.+]] = bitcast i8* %[[CUR3]] to i16*
272   // WIN32: %[[LOADV3:.+]] = load i16, i16* %[[BC3]]
273   // WIN32: store i16 %[[LOADV3]], i16*
274 
275 
276   _BitInt(129) D = __builtin_va_arg(args, _BitInt(129));
277   // LIN64: %[[AD4:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %[[ARGS]]
278   // LIN64: %[[OFA_P4:.+]] = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %[[AD4]], i32 0, i32 2
279   // LIN64: %[[OFA4:.+]] = load i8*, i8** %[[OFA_P4]]
280   // LIN64: %[[BC4:.+]] = bitcast i8* %[[OFA4]] to i129*
281   // LIN64: %[[OFANEXT4:.+]] = getelementptr i8, i8* %[[OFA4]], i32 24
282   // LIN64: store i8* %[[OFANEXT4]], i8** %[[OFA_P4]]
283   // LIN64: %[[LOAD4:.+]] = load i129, i129* %[[BC4]]
284   // LIN64: store i129 %[[LOAD4]], i129*
285 
286   // LIN32: %[[CUR4:.+]] = load i8*, i8** %[[ARGS]]
287   // LIN32: %[[NEXT4:.+]] = getelementptr inbounds i8, i8* %[[CUR4]], i32 20
288   // LIN32: store i8* %[[NEXT4]], i8** %[[ARGS]]
289   // LIN32: %[[BC4:.+]] = bitcast i8* %[[CUR4]] to i129*
290   // LIN32: %[[LOADV4:.+]] = load i129, i129* %[[BC4]]
291   // LIN32: store i129 %[[LOADV4]], i129*
292 
293   // WIN64: %[[CUR4:.+]] = load i8*, i8** %[[ARGS]]
294   // WIN64: %[[NEXT4:.+]] = getelementptr inbounds i8, i8* %[[CUR4]], i64 8
295   // WIN64: store i8* %[[NEXT4]], i8** %[[ARGS]]
296   // WIN64: %[[BC4:.+]] = bitcast i8* %[[CUR4]] to i129**
297   // WIN64: %[[LOADP4:.+]] = load i129*, i129** %[[BC4]]
298   // WIN64: %[[LOADV4:.+]] = load i129, i129* %[[LOADP4]]
299   // WIN64: store i129 %[[LOADV4]], i129*
300 
301   // WIN32: %[[CUR4:.+]] = load i8*, i8** %[[ARGS]]
302   // WIN32: %[[NEXT4:.+]] = getelementptr inbounds i8, i8* %[[CUR4]], i32 24
303   // WIN32: store i8* %[[NEXT4]], i8** %[[ARGS]]
304   // WIN32: %[[BC4:.+]] = bitcast i8* %[[CUR4]] to i129*
305   // WIN32: %[[LOADV4:.+]] = load i129, i129* %[[BC4]]
306   // WIN32: store i129 %[[LOADV4]], i129*
307 
308   _BitInt(8388600) E = __builtin_va_arg(args, _BitInt(8388600));
309   // LIN64: %[[AD5:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %[[ARGS]]
310   // LIN64: %[[OFA_P5:.+]] = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %[[AD5]], i32 0, i32 2
311   // LIN64: %[[OFA5:.+]] = load i8*, i8** %[[OFA_P5]]
312   // LIN64: %[[BC5:.+]] = bitcast i8* %[[OFA5]] to i8388600*
313   // LIN64: %[[OFANEXT5:.+]] = getelementptr i8, i8* %[[OFA5]], i32 1048576
314   // LIN64: store i8* %[[OFANEXT5]], i8** %[[OFA_P5]]
315   // LIN64: %[[LOAD5:.+]] = load i8388600, i8388600* %[[BC5]]
316   // LIN64: store i8388600 %[[LOAD5]], i8388600*
317 
318   // LIN32: %[[CUR5:.+]] = load i8*, i8** %[[ARGS]]
319   // LIN32: %[[NEXT5:.+]] = getelementptr inbounds i8, i8* %[[CUR5]], i32 1048576
320   // LIN32: store i8* %[[NEXT5]], i8** %[[ARGS]]
321   // LIN32: %[[BC5:.+]] = bitcast i8* %[[CUR5]] to i8388600*
322   // LIN32: %[[LOADV5:.+]] = load i8388600, i8388600* %[[BC5]]
323   // LIN32: store i8388600 %[[LOADV5]], i8388600*
324 
325   // WIN64: %[[CUR5:.+]] = load i8*, i8** %[[ARGS]]
326   // WIN64: %[[NEXT5:.+]] = getelementptr inbounds i8, i8* %[[CUR5]], i64 8
327   // WIN64: store i8* %[[NEXT5]], i8** %[[ARGS]]
328   // WIN64: %[[BC5:.+]] = bitcast i8* %[[CUR5]] to i8388600**
329   // WIN64: %[[LOADP5:.+]] = load i8388600*, i8388600** %[[BC5]]
330   // WIN64: %[[LOADV5:.+]] = load i8388600, i8388600* %[[LOADP5]]
331   // WIN64: store i8388600 %[[LOADV5]], i8388600*
332 
333   // WIN32: %[[CUR5:.+]] = load i8*, i8** %[[ARGS]]
334   // WIN32: %[[NEXT5:.+]] = getelementptr inbounds i8, i8* %[[CUR5]], i32 1048576
335   // WIN32: store i8* %[[NEXT5]], i8** %[[ARGS]]
336   // WIN32: %[[BC5:.+]] = bitcast i8* %[[CUR5]] to i8388600*
337   // WIN32: %[[LOADV5:.+]] = load i8388600, i8388600* %[[BC5]]
338   // WIN32: store i8388600 %[[LOADV5]], i8388600*
339 
340   __builtin_va_end(args);
341   // LIN64: %[[ENDAD:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %[[ARGS]]
342   // LIN64: %[[ENDAD1:.+]] = bitcast %struct.__va_list_tag* %[[ENDAD]] to i8*
343   // LIN64: call void @llvm.va_end(i8* %[[ENDAD1]])
344   // LIN32: %[[ARGSEND:.+]] = bitcast i8** %[[ARGS]] to i8*
345   // LIN32: call void @llvm.va_end(i8* %[[ARGSEND]])
346   // WIN: %[[ARGSEND:.+]] = bitcast i8** %[[ARGS]] to i8*
347   // WIN: call void @llvm.va_end(i8* %[[ARGSEND]])
348 }
349 void typeid_tests() {
350   // LIN: define{{.*}} void @_Z12typeid_testsv()
351   // WIN: define dso_local void @"?typeid_tests@@YAXXZ"()
352   unsigned _BitInt(33) U33_1, U33_2;
353   _BitInt(33) S33_1, S33_2;
354   _BitInt(32) S32_1, S32_2;
355 
356  auto A = typeid(U33_1);
357  // LIN64: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast ({ i8*, i8* }* @_ZTIDU33_ to %"class.std::type_info"*))
358  // LIN32: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast ({ i8*, i8* }* @_ZTIDU33_ to %"class.std::type_info"*))
359  // WIN64: call %"class.std::type_info"* @"??0type_info@std@@QEAA@AEBV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast (%rtti.TypeDescriptor28* @"??_R0U?$_UBitInt@$0CB@@__clang@@@8" to %"class.std::type_info"*))
360  // WIN32: call x86_thiscallcc %"class.std::type_info"* @"??0type_info@std@@QAE@ABV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast (%rtti.TypeDescriptor28* @"??_R0U?$_UBitInt@$0CB@@__clang@@@8" to %"class.std::type_info"*))
361  auto B = typeid(U33_2);
362  // LIN64: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast ({ i8*, i8* }* @_ZTIDU33_ to %"class.std::type_info"*))
363  // LIN32: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast ({ i8*, i8* }* @_ZTIDU33_ to %"class.std::type_info"*))
364  // WIN64:  call %"class.std::type_info"* @"??0type_info@std@@QEAA@AEBV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast (%rtti.TypeDescriptor28* @"??_R0U?$_UBitInt@$0CB@@__clang@@@8" to %"class.std::type_info"*))
365  // WIN32:  call x86_thiscallcc %"class.std::type_info"* @"??0type_info@std@@QAE@ABV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast (%rtti.TypeDescriptor28* @"??_R0U?$_UBitInt@$0CB@@__clang@@@8" to %"class.std::type_info"*))
366  auto C = typeid(S33_1);
367  // LIN64: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast ({ i8*, i8* }* @_ZTIDB33_ to %"class.std::type_info"*))
368  // LIN32: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast ({ i8*, i8* }* @_ZTIDB33_ to %"class.std::type_info"*))
369  // WIN64:  call %"class.std::type_info"* @"??0type_info@std@@QEAA@AEBV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast (%rtti.TypeDescriptor27* @"??_R0U?$_BitInt@$0CB@@__clang@@@8" to %"class.std::type_info"*))
370  // WIN32:  call x86_thiscallcc %"class.std::type_info"* @"??0type_info@std@@QAE@ABV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast (%rtti.TypeDescriptor27* @"??_R0U?$_BitInt@$0CB@@__clang@@@8" to %"class.std::type_info"*))
371  auto D = typeid(S33_2);
372  // LIN64: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast ({ i8*, i8* }* @_ZTIDB33_ to %"class.std::type_info"*))
373  // LIN32: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast ({ i8*, i8* }* @_ZTIDB33_ to %"class.std::type_info"*))
374  // WIN64:  call %"class.std::type_info"* @"??0type_info@std@@QEAA@AEBV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast (%rtti.TypeDescriptor27* @"??_R0U?$_BitInt@$0CB@@__clang@@@8" to %"class.std::type_info"*))
375  // WIN32:  call x86_thiscallcc %"class.std::type_info"* @"??0type_info@std@@QAE@ABV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast (%rtti.TypeDescriptor27* @"??_R0U?$_BitInt@$0CB@@__clang@@@8" to %"class.std::type_info"*))
376  auto E = typeid(S32_1);
377  // LIN64: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast ({ i8*, i8* }* @_ZTIDB32_ to %"class.std::type_info"*))
378  // LIN32: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast ({ i8*, i8* }* @_ZTIDB32_ to %"class.std::type_info"*))
379  // WIN64:  call %"class.std::type_info"* @"??0type_info@std@@QEAA@AEBV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast (%rtti.TypeDescriptor27* @"??_R0U?$_BitInt@$0CA@@__clang@@@8" to %"class.std::type_info"*))
380  // WIN32:  call x86_thiscallcc %"class.std::type_info"* @"??0type_info@std@@QAE@ABV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast (%rtti.TypeDescriptor27* @"??_R0U?$_BitInt@$0CA@@__clang@@@8" to %"class.std::type_info"*))
381  auto F = typeid(S32_2);
382  // LIN64: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast ({ i8*, i8* }* @_ZTIDB32_ to %"class.std::type_info"*))
383  // LIN32: call void @_ZNSt9type_infoC1ERKS_(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast ({ i8*, i8* }* @_ZTIDB32_ to %"class.std::type_info"*))
384  // WIN64:  call %"class.std::type_info"* @"??0type_info@std@@QEAA@AEBV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 8 dereferenceable(16) bitcast (%rtti.TypeDescriptor27* @"??_R0U?$_BitInt@$0CA@@__clang@@@8" to %"class.std::type_info"*))
385  // WIN32:  call x86_thiscallcc %"class.std::type_info"* @"??0type_info@std@@QAE@ABV01@@Z"(%"class.std::type_info"* {{[^,]*}} %{{.+}}, %"class.std::type_info"* nonnull align 4 dereferenceable(8) bitcast (%rtti.TypeDescriptor27* @"??_R0U?$_BitInt@$0CA@@__clang@@@8" to %"class.std::type_info"*))
386 }
387 
388 void ExplicitCasts() {
389   // LIN: define{{.*}} void @_Z13ExplicitCastsv()
390   // WIN: define dso_local void @"?ExplicitCasts@@YAXXZ"()
391 
392   _BitInt(33) a;
393   _BitInt(31) b;
394   int i;
395 
396   a = i;
397   // CHECK: %[[CONV:.+]] = sext i32 %{{.+}} to i33
398   b = i;
399   // CHECK: %[[CONV:.+]] = trunc i32 %{{.+}} to i31
400   i = a;
401   // CHECK: %[[CONV:.+]] = trunc i33 %{{.+}} to i32
402   i = b;
403   // CHECK: %[[CONV:.+]] = sext i31 %{{.+}} to i32
404 }
405 
406 struct S {
407   _BitInt(17) A;
408   _BitInt(8388600) B;
409   _BitInt(17) C;
410 };
411 
412 void OffsetOfTest() {
413   // LIN: define{{.*}} void @_Z12OffsetOfTestv()
414   // WIN: define dso_local void @"?OffsetOfTest@@YAXXZ"()
415 
416   auto A = __builtin_offsetof(S,A);
417   // CHECK: store i{{.+}} 0, i{{.+}}* %{{.+}}
418   auto B = __builtin_offsetof(S,B);
419   // LIN64: store i{{.+}} 8, i{{.+}}* %{{.+}}
420   // LIN32: store i{{.+}} 4, i{{.+}}* %{{.+}}
421   // WIN: store i{{.+}} 8, i{{.+}}* %{{.+}}
422   auto C = __builtin_offsetof(S,C);
423   // LIN64: store i{{.+}} 1048584, i{{.+}}* %{{.+}}
424   // LIN32: store i{{.+}} 1048580, i{{.+}}* %{{.+}}
425   // WIN: store i{{.+}} 1048584, i{{.+}}* %{{.+}}
426 }
427 
428 
429 void ShiftBitIntByConstant(_BitInt(28) Ext) {
430 // LIN: define{{.*}} void @_Z21ShiftBitIntByConstantDB28_
431 // WIN: define dso_local void @"?ShiftBitIntByConstant@@YAXU?$_BitInt@$0BM@@__clang@@@Z"
432   Ext << 7;
433   // CHECK: shl i28 %{{.+}}, 7
434   Ext >> 7;
435   // CHECK: ashr i28 %{{.+}}, 7
436   Ext << -7;
437   // CHECK: shl i28 %{{.+}}, -7
438   Ext >> -7;
439   // CHECK: ashr i28 %{{.+}}, -7
440 
441   // UB in C/C++, Defined in OpenCL.
442   Ext << 29;
443   // CHECK: shl i28 %{{.+}}, 29
444   Ext >> 29;
445   // CHECK: ashr i28 %{{.+}}, 29
446 }
447 
448 void ConstantShiftByBitInt(_BitInt(28) Ext, _BitInt(65) LargeExt) {
449   // LIN: define{{.*}} void @_Z21ConstantShiftByBitIntDB28_DB65_
450   // WIN: define dso_local void @"?ConstantShiftByBitInt@@YAXU?$_BitInt@$0BM@@__clang@@U?$_BitInt@$0EB@@2@@Z"
451   10 << Ext;
452   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i32
453   // CHECK: shl i32 10, %[[PROMO]]
454   10 >> Ext;
455   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i32
456   // CHECK: ashr i32 10, %[[PROMO]]
457   10 << LargeExt;
458   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i32
459   // CHECK: shl i32 10, %[[PROMO]]
460   10 >> LargeExt;
461   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i32
462   // CHECK: ashr i32 10, %[[PROMO]]
463 }
464 
465 void Shift(_BitInt(28) Ext, _BitInt(65) LargeExt, int i) {
466   // LIN: define{{.*}} void @_Z5ShiftDB28_DB65_
467   // WIN: define dso_local void @"?Shift@@YAXU?$_BitInt@$0BM@@__clang@@U?$_BitInt@$0EB@@2@H@Z"
468   i << Ext;
469   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i32
470   // CHECK: shl i32 {{.+}}, %[[PROMO]]
471   i >> Ext;
472   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i32
473   // CHECK: ashr i32 {{.+}}, %[[PROMO]]
474 
475   i << LargeExt;
476   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i32
477   // CHECK: shl i32 {{.+}}, %[[PROMO]]
478   i >> LargeExt;
479   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i32
480   // CHECK: ashr i32 {{.+}}, %[[PROMO]]
481 
482   Ext << i;
483   // CHECK: %[[PROMO:.+]] = trunc i32 %{{.+}} to i28
484   // CHECK: shl i28 {{.+}}, %[[PROMO]]
485   Ext >> i;
486   // CHECK: %[[PROMO:.+]] = trunc i32 %{{.+}} to i28
487   // CHECK: ashr i28 {{.+}}, %[[PROMO]]
488 
489   LargeExt << i;
490   // CHECK: %[[PROMO:.+]] = zext i32 %{{.+}} to i65
491   // CHECK: shl i65 {{.+}}, %[[PROMO]]
492   LargeExt >> i;
493   // CHECK: %[[PROMO:.+]] = zext i32 %{{.+}} to i65
494   // CHECK: ashr i65 {{.+}}, %[[PROMO]]
495 
496   Ext << LargeExt;
497   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i28
498   // CHECK: shl i28 {{.+}}, %[[PROMO]]
499   Ext >> LargeExt;
500   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i28
501   // CHECK: ashr i28 {{.+}}, %[[PROMO]]
502 
503   LargeExt << Ext;
504   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i65
505   // CHECK: shl i65 {{.+}}, %[[PROMO]]
506   LargeExt >> Ext;
507   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i65
508   // CHECK: ashr i65 {{.+}}, %[[PROMO]]
509 }
510 
511 void ComplexTest(_Complex _BitInt(12) first, _Complex _BitInt(33) second) {
512   // LIN: define{{.*}} void @_Z11ComplexTestCDB12_CDB33_
513   // WIN: define dso_local void  @"?ComplexTest@@YAXU?$_Complex@U?$_BitInt@$0M@@__clang@@@__clang@@U?$_Complex@U?$_BitInt@$0CB@@__clang@@@2@@Z"
514   first + second;
515   // CHECK: %[[FIRST_REALP:.+]] = getelementptr inbounds { i12, i12 }, { i12, i12 }* %{{.+}}, i32 0, i32 0
516   // CHECK: %[[FIRST_REAL:.+]] = load i12, i12* %[[FIRST_REALP]]
517   // CHECK: %[[FIRST_IMAGP:.+]] = getelementptr inbounds { i12, i12 }, { i12, i12 }* %{{.+}}, i32 0, i32 1
518   // CHECK: %[[FIRST_IMAG:.+]] = load i12, i12* %[[FIRST_IMAGP]]
519   // CHECK: %[[FIRST_REAL_CONV:.+]] = sext i12 %[[FIRST_REAL]]
520   // CHECK: %[[FIRST_IMAG_CONV:.+]] = sext i12 %[[FIRST_IMAG]]
521   // CHECK: %[[SECOND_REALP:.+]] = getelementptr inbounds { i33, i33 }, { i33, i33 }* %{{.+}}, i32 0, i32 0
522   // CHECK: %[[SECOND_REAL:.+]] = load i33, i33* %[[SECOND_REALP]]
523   // CHECK: %[[SECOND_IMAGP:.+]] = getelementptr inbounds { i33, i33 }, { i33, i33 }* %{{.+}}, i32 0, i32 1
524   // CHECK: %[[SECOND_IMAG:.+]] = load i33, i33* %[[SECOND_IMAGP]]
525   // CHECK: %[[REAL:.+]] = add i33 %[[FIRST_REAL_CONV]], %[[SECOND_REAL]]
526   // CHECK: %[[IMAG:.+]] = add i33 %[[FIRST_IMAG_CONV]], %[[SECOND_IMAG]]
527 }
528 
529 // Ensure that these types don't alias the normal int types.
530 void TBAATest(_BitInt(sizeof(int) * 8) ExtInt,
531               unsigned _BitInt(sizeof(int) * 8) ExtUInt,
532               _BitInt(6) Other) {
533   // CHECK-DAG: store i32 %{{.+}}, i32* %{{.+}}, align 4, !tbaa ![[EXTINT_TBAA:.+]]
534   // CHECK-DAG: store i32 %{{.+}}, i32* %{{.+}}, align 4, !tbaa ![[EXTINT_TBAA]]
535   // CHECK-DAG: store i6 %{{.+}}, i6* %{{.+}}, align 1, !tbaa ![[EXTINT6_TBAA:.+]]
536   ExtInt = 5;
537   ExtUInt = 5;
538   Other = 5;
539 }
540 
541 // NoNewStructPathTBAA-DAG: ![[CHAR_TBAA_ROOT:.+]] = !{!"omnipotent char", ![[TBAA_ROOT:.+]], i64 0}
542 // NoNewStructPathTBAA-DAG: ![[TBAA_ROOT]] = !{!"Simple C++ TBAA"}
543 // NoNewStructPathTBAA-DAG: ![[EXTINT_TBAA]] = !{![[EXTINT_TBAA_ROOT:.+]], ![[EXTINT_TBAA_ROOT]], i64 0}
544 // NoNewStructPathTBAA-DAG: ![[EXTINT_TBAA_ROOT]] = !{!"_BitInt(32)", ![[CHAR_TBAA_ROOT]], i64 0}
545 // NoNewStructPathTBAA-DAG: ![[EXTINT6_TBAA]] = !{![[EXTINT6_TBAA_ROOT:.+]], ![[EXTINT6_TBAA_ROOT]], i64 0}
546 // NoNewStructPathTBAA-DAG: ![[EXTINT6_TBAA_ROOT]] = !{!"_BitInt(6)", ![[CHAR_TBAA_ROOT]], i64 0}
547 
548 // NewStructPathTBAA-DAG: ![[CHAR_TBAA_ROOT:.+]] = !{![[TBAA_ROOT:.+]], i64 1, !"omnipotent char"}
549 // NewStructPathTBAA-DAG: ![[TBAA_ROOT]] = !{!"Simple C++ TBAA"}
550 // NewStructPathTBAA-DAG: ![[EXTINT_TBAA]] = !{![[EXTINT_TBAA_ROOT:.+]], ![[EXTINT_TBAA_ROOT]], i64 0, i64 4}
551 // NewStructPathTBAA-DAG: ![[EXTINT_TBAA_ROOT]] = !{![[CHAR_TBAA_ROOT]], i64 4, !"_BitInt(32)"}
552 // NewStructPathTBAA-DAG: ![[EXTINT6_TBAA]] = !{![[EXTINT6_TBAA_ROOT:.+]], ![[EXTINT6_TBAA_ROOT]], i64 0, i64 1}
553 // NewStructPathTBAA-DAG: ![[EXTINT6_TBAA_ROOT]] = !{![[CHAR_TBAA_ROOT]], i64 1, !"_BitInt(6)"}
554