1 // RUN: %clang_cc1 -no-opaque-pointers -no-enable-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 -no-opaque-pointers -no-enable-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 -no-opaque-pointers -no-enable-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 -no-opaque-pointers -no-enable-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 -no-opaque-pointers -no-enable-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 -no-opaque-pointers -no-enable-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 -no-opaque-pointers -no-enable-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 -no-opaque-pointers -no-enable-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.
StructEmit()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 
BitfieldAssignment()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 
UnderlyingTypeUsage(AsEnumUnderlyingType Param)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 
ManglingInstantiator()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 
TakesVarargs(int i,...)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   __builtin_va_end(args);
276   // LIN64: %[[ENDAD:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %[[ARGS]]
277   // LIN64: %[[ENDAD1:.+]] = bitcast %struct.__va_list_tag* %[[ENDAD]] to i8*
278   // LIN64: call void @llvm.va_end(i8* %[[ENDAD1]])
279   // LIN32: %[[ARGSEND:.+]] = bitcast i8** %[[ARGS]] to i8*
280   // LIN32: call void @llvm.va_end(i8* %[[ARGSEND]])
281   // WIN: %[[ARGSEND:.+]] = bitcast i8** %[[ARGS]] to i8*
282   // WIN: call void @llvm.va_end(i8* %[[ARGSEND]])
283 }
typeid_tests()284 void typeid_tests() {
285   // LIN: define{{.*}} void @_Z12typeid_testsv()
286   // WIN: define dso_local void @"?typeid_tests@@YAXXZ"()
287   unsigned _BitInt(33) U33_1, U33_2;
288   _BitInt(33) S33_1, S33_2;
289   _BitInt(32) S32_1, S32_2;
290 
291  auto A = typeid(U33_1);
292  // 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"*))
293  // 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"*))
294  // 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"*))
295  // 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"*))
296  auto B = typeid(U33_2);
297  // 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"*))
298  // 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"*))
299  // 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"*))
300  // 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"*))
301  auto C = typeid(S33_1);
302  // 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"*))
303  // 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"*))
304  // 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"*))
305  // 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"*))
306  auto D = typeid(S33_2);
307  // 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"*))
308  // 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"*))
309  // 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"*))
310  // 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"*))
311  auto E = typeid(S32_1);
312  // 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"*))
313  // 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"*))
314  // 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"*))
315  // 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"*))
316  auto F = typeid(S32_2);
317  // 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"*))
318  // 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"*))
319  // 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"*))
320  // 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"*))
321 }
322 
ExplicitCasts()323 void ExplicitCasts() {
324   // LIN: define{{.*}} void @_Z13ExplicitCastsv()
325   // WIN: define dso_local void @"?ExplicitCasts@@YAXXZ"()
326 
327   _BitInt(33) a;
328   _BitInt(31) b;
329   int i;
330 
331   a = i;
332   // CHECK: %[[CONV:.+]] = sext i32 %{{.+}} to i33
333   b = i;
334   // CHECK: %[[CONV:.+]] = trunc i32 %{{.+}} to i31
335   i = a;
336   // CHECK: %[[CONV:.+]] = trunc i33 %{{.+}} to i32
337   i = b;
338   // CHECK: %[[CONV:.+]] = sext i31 %{{.+}} to i32
339 }
340 
341 struct S {
342   _BitInt(17) A;
343   _BitInt(128) B;
344   _BitInt(17) C;
345 };
346 
OffsetOfTest()347 void OffsetOfTest() {
348   // LIN: define{{.*}} void @_Z12OffsetOfTestv()
349   // WIN: define dso_local void @"?OffsetOfTest@@YAXXZ"()
350 
351   auto A = __builtin_offsetof(S,A);
352   // CHECK: store i{{.+}} 0, i{{.+}}* %{{.+}}
353   auto B = __builtin_offsetof(S,B);
354   // LIN64: store i{{.+}} 8, i{{.+}}* %{{.+}}
355   // LIN32: store i{{.+}} 4, i{{.+}}* %{{.+}}
356   // WIN: store i{{.+}} 8, i{{.+}}* %{{.+}}
357   auto C = __builtin_offsetof(S,C);
358   // LIN64: store i{{.+}} 24, i{{.+}}* %{{.+}}
359   // LIN32: store i{{.+}} 20, i{{.+}}* %{{.+}}
360   // WIN: store i{{.+}} 24, i{{.+}}* %{{.+}}
361 }
362 
363 
364 void ShiftBitIntByConstant(_BitInt(28) Ext) {
365 // LIN: define{{.*}} void @_Z21ShiftBitIntByConstantDB28_
366 // WIN: define dso_local void @"?ShiftBitIntByConstant@@YAXU?$_BitInt@$0BM@@__clang@@@Z"
367   Ext << 7;
368   // CHECK: shl i28 %{{.+}}, 7
369   Ext >> 7;
370   // CHECK: ashr i28 %{{.+}}, 7
371   Ext << -7;
372   // CHECK: shl i28 %{{.+}}, -7
373   Ext >> -7;
374   // CHECK: ashr i28 %{{.+}}, -7
375 
376   // UB in C/C++, Defined in OpenCL.
377   Ext << 29;
378   // CHECK: shl i28 %{{.+}}, 29
379   Ext >> 29;
380   // CHECK: ashr i28 %{{.+}}, 29
381 }
382 
383 void ConstantShiftByBitInt(_BitInt(28) Ext, _BitInt(65) LargeExt) {
384   // LIN: define{{.*}} void @_Z21ConstantShiftByBitIntDB28_DB65_
385   // WIN: define dso_local void @"?ConstantShiftByBitInt@@YAXU?$_BitInt@$0BM@@__clang@@U?$_BitInt@$0EB@@2@@Z"
386   10 << Ext;
387   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i32
388   // CHECK: shl i32 10, %[[PROMO]]
389   10 >> Ext;
390   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i32
391   // CHECK: ashr i32 10, %[[PROMO]]
392   10 << LargeExt;
393   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i32
394   // CHECK: shl i32 10, %[[PROMO]]
395   10 >> LargeExt;
396   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i32
397   // CHECK: ashr i32 10, %[[PROMO]]
398 }
399 
400 void Shift(_BitInt(28) Ext, _BitInt(65) LargeExt, int i) {
401   // LIN: define{{.*}} void @_Z5ShiftDB28_DB65_
402   // WIN: define dso_local void @"?Shift@@YAXU?$_BitInt@$0BM@@__clang@@U?$_BitInt@$0EB@@2@H@Z"
403   i << Ext;
404   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i32
405   // CHECK: shl i32 {{.+}}, %[[PROMO]]
406   i >> Ext;
407   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i32
408   // CHECK: ashr i32 {{.+}}, %[[PROMO]]
409 
410   i << LargeExt;
411   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i32
412   // CHECK: shl i32 {{.+}}, %[[PROMO]]
413   i >> LargeExt;
414   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i32
415   // CHECK: ashr i32 {{.+}}, %[[PROMO]]
416 
417   Ext << i;
418   // CHECK: %[[PROMO:.+]] = trunc i32 %{{.+}} to i28
419   // CHECK: shl i28 {{.+}}, %[[PROMO]]
420   Ext >> i;
421   // CHECK: %[[PROMO:.+]] = trunc i32 %{{.+}} to i28
422   // CHECK: ashr i28 {{.+}}, %[[PROMO]]
423 
424   LargeExt << i;
425   // CHECK: %[[PROMO:.+]] = zext i32 %{{.+}} to i65
426   // CHECK: shl i65 {{.+}}, %[[PROMO]]
427   LargeExt >> i;
428   // CHECK: %[[PROMO:.+]] = zext i32 %{{.+}} to i65
429   // CHECK: ashr i65 {{.+}}, %[[PROMO]]
430 
431   Ext << LargeExt;
432   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i28
433   // CHECK: shl i28 {{.+}}, %[[PROMO]]
434   Ext >> LargeExt;
435   // CHECK: %[[PROMO:.+]] = trunc i65 %{{.+}} to i28
436   // CHECK: ashr i28 {{.+}}, %[[PROMO]]
437 
438   LargeExt << Ext;
439   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i65
440   // CHECK: shl i65 {{.+}}, %[[PROMO]]
441   LargeExt >> Ext;
442   // CHECK: %[[PROMO:.+]] = zext i28 %{{.+}} to i65
443   // CHECK: ashr i65 {{.+}}, %[[PROMO]]
444 }
445 
446 void ComplexTest(_Complex _BitInt(12) first, _Complex _BitInt(33) second) {
447   // LIN: define{{.*}} void @_Z11ComplexTestCDB12_CDB33_
448   // WIN: define dso_local void  @"?ComplexTest@@YAXU?$_Complex@U?$_BitInt@$0M@@__clang@@@__clang@@U?$_Complex@U?$_BitInt@$0CB@@__clang@@@2@@Z"
449   first + second;
450   // CHECK: %[[FIRST_REALP:.+]] = getelementptr inbounds { i12, i12 }, { i12, i12 }* %{{.+}}, i32 0, i32 0
451   // CHECK: %[[FIRST_REAL:.+]] = load i12, i12* %[[FIRST_REALP]]
452   // CHECK: %[[FIRST_IMAGP:.+]] = getelementptr inbounds { i12, i12 }, { i12, i12 }* %{{.+}}, i32 0, i32 1
453   // CHECK: %[[FIRST_IMAG:.+]] = load i12, i12* %[[FIRST_IMAGP]]
454   // CHECK: %[[FIRST_REAL_CONV:.+]] = sext i12 %[[FIRST_REAL]]
455   // CHECK: %[[FIRST_IMAG_CONV:.+]] = sext i12 %[[FIRST_IMAG]]
456   // CHECK: %[[SECOND_REALP:.+]] = getelementptr inbounds { i33, i33 }, { i33, i33 }* %{{.+}}, i32 0, i32 0
457   // CHECK: %[[SECOND_REAL:.+]] = load i33, i33* %[[SECOND_REALP]]
458   // CHECK: %[[SECOND_IMAGP:.+]] = getelementptr inbounds { i33, i33 }, { i33, i33 }* %{{.+}}, i32 0, i32 1
459   // CHECK: %[[SECOND_IMAG:.+]] = load i33, i33* %[[SECOND_IMAGP]]
460   // CHECK: %[[REAL:.+]] = add i33 %[[FIRST_REAL_CONV]], %[[SECOND_REAL]]
461   // CHECK: %[[IMAG:.+]] = add i33 %[[FIRST_IMAG_CONV]], %[[SECOND_IMAG]]
462 }
463 
464 // Ensure that these types don't alias the normal int types.
465 void TBAATest(_BitInt(sizeof(int) * 8) ExtInt,
466               unsigned _BitInt(sizeof(int) * 8) ExtUInt,
467               _BitInt(6) Other) {
468   // CHECK-DAG: store i32 %{{.+}}, i32* %{{.+}}, align 4, !tbaa ![[EXTINT_TBAA:.+]]
469   // CHECK-DAG: store i32 %{{.+}}, i32* %{{.+}}, align 4, !tbaa ![[EXTINT_TBAA]]
470   // CHECK-DAG: store i6 %{{.+}}, i6* %{{.+}}, align 1, !tbaa ![[EXTINT6_TBAA:.+]]
471   ExtInt = 5;
472   ExtUInt = 5;
473   Other = 5;
474 }
475 
476 // NoNewStructPathTBAA-DAG: ![[CHAR_TBAA_ROOT:.+]] = !{!"omnipotent char", ![[TBAA_ROOT:.+]], i64 0}
477 // NoNewStructPathTBAA-DAG: ![[TBAA_ROOT]] = !{!"Simple C++ TBAA"}
478 // NoNewStructPathTBAA-DAG: ![[EXTINT_TBAA]] = !{![[EXTINT_TBAA_ROOT:.+]], ![[EXTINT_TBAA_ROOT]], i64 0}
479 // NoNewStructPathTBAA-DAG: ![[EXTINT_TBAA_ROOT]] = !{!"_BitInt(32)", ![[CHAR_TBAA_ROOT]], i64 0}
480 // NoNewStructPathTBAA-DAG: ![[EXTINT6_TBAA]] = !{![[EXTINT6_TBAA_ROOT:.+]], ![[EXTINT6_TBAA_ROOT]], i64 0}
481 // NoNewStructPathTBAA-DAG: ![[EXTINT6_TBAA_ROOT]] = !{!"_BitInt(6)", ![[CHAR_TBAA_ROOT]], i64 0}
482 
483 // NewStructPathTBAA-DAG: ![[CHAR_TBAA_ROOT:.+]] = !{![[TBAA_ROOT:.+]], i64 1, !"omnipotent char"}
484 // NewStructPathTBAA-DAG: ![[TBAA_ROOT]] = !{!"Simple C++ TBAA"}
485 // NewStructPathTBAA-DAG: ![[EXTINT_TBAA]] = !{![[EXTINT_TBAA_ROOT:.+]], ![[EXTINT_TBAA_ROOT]], i64 0, i64 4}
486 // NewStructPathTBAA-DAG: ![[EXTINT_TBAA_ROOT]] = !{![[CHAR_TBAA_ROOT]], i64 4, !"_BitInt(32)"}
487 // NewStructPathTBAA-DAG: ![[EXTINT6_TBAA]] = !{![[EXTINT6_TBAA_ROOT:.+]], ![[EXTINT6_TBAA_ROOT]], i64 0, i64 1}
488 // NewStructPathTBAA-DAG: ![[EXTINT6_TBAA_ROOT]] = !{![[CHAR_TBAA_ROOT]], i64 1, !"_BitInt(6)"}
489