1 // RUN: %clang_cc1 -emit-llvm -o - -triple=i386-pc-win32 -std=c++11 %s -fcxx-exceptions -fms-extensions | FileCheck %s
2 // RUN: %clang_cc1 -emit-llvm -o - -triple=i386-pc-win32 -std=c++11 %s -fcxx-exceptions -fms-extensions -DSTD | FileCheck %s
3 
4 // CHECK-DAG: @"??_R0?AUY@@@8" = linkonce_odr global %rtti.TypeDescriptor7 { i8** @"??_7type_info@@6B@", i8* null, [8 x i8] c".?AUY@@\00" }, comdat
5 // CHECK-DAG: @"_CT??_R0?AUY@@@8??0Y@@QAE@ABU0@@Z8" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 4, i8* bitcast (%rtti.TypeDescriptor7* @"??_R0?AUY@@@8" to i8*), i32 0, i32 -1, i32 0, i32 8, i8* bitcast (%struct.Y* (%struct.Y*, %struct.Y*, i32)* @"??0Y@@QAE@ABU0@@Z" to i8*) }, section ".xdata", comdat
6 // CHECK-DAG: @"??_R0?AUZ@@@8" = linkonce_odr global %rtti.TypeDescriptor7 { i8** @"??_7type_info@@6B@", i8* null, [8 x i8] c".?AUZ@@\00" }, comdat
7 // CHECK-DAG: @"_CT??_R0?AUZ@@@81" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 0, i8* bitcast (%rtti.TypeDescriptor7* @"??_R0?AUZ@@@8" to i8*), i32 0, i32 -1, i32 0, i32 1, i8* null }, section ".xdata", comdat
8 // CHECK-DAG: @"??_R0?AUW@@@8" = linkonce_odr global %rtti.TypeDescriptor7 { i8** @"??_7type_info@@6B@", i8* null, [8 x i8] c".?AUW@@\00" }, comdat
9 // CHECK-DAG: @"_CT??_R0?AUW@@@8??0W@@QAE@ABU0@@Z44" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 4, i8* bitcast (%rtti.TypeDescriptor7* @"??_R0?AUW@@@8" to i8*), i32 4, i32 -1, i32 0, i32 4, i8* bitcast (%struct.W* (%struct.W*, %struct.W*, i32)* @"??0W@@QAE@ABU0@@Z" to i8*) }, section ".xdata", comdat
10 // CHECK-DAG: @"??_R0?AUM@@@8" = linkonce_odr global %rtti.TypeDescriptor7 { i8** @"??_7type_info@@6B@", i8* null, [8 x i8] c".?AUM@@\00" }, comdat
11 // CHECK-DAG: @"_CT??_R0?AUM@@@818" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 0, i8* bitcast (%rtti.TypeDescriptor7* @"??_R0?AUM@@@8" to i8*), i32 8, i32 -1, i32 0, i32 1, i8* null }, section ".xdata", comdat
12 // CHECK-DAG: @"??_R0?AUV@@@8" = linkonce_odr global %rtti.TypeDescriptor7 { i8** @"??_7type_info@@6B@", i8* null, [8 x i8] c".?AUV@@\00" }, comdat
13 // CHECK-DAG: @"_CT??_R0?AUV@@@81044" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 0, i8* bitcast (%rtti.TypeDescriptor7* @"??_R0?AUV@@@8" to i8*), i32 0, i32 4, i32 4, i32 1, i8* null }, section ".xdata", comdat
14 // CHECK-DAG: @"_CTA5?AUY@@" = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.5 { i32 5, [5 x %eh.CatchableType*] [%eh.CatchableType* @"_CT??_R0?AUY@@@8??0Y@@QAE@ABU0@@Z8", %eh.CatchableType* @"_CT??_R0?AUZ@@@81", %eh.CatchableType* @"_CT??_R0?AUW@@@8??0W@@QAE@ABU0@@Z44", %eh.CatchableType* @"_CT??_R0?AUM@@@818", %eh.CatchableType* @"_CT??_R0?AUV@@@81044"] }, section ".xdata", comdat
15 // CHECK-DAG: @"_TI5?AUY@@" = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i8* bitcast (void (%struct.Y*)* @"??_DY@@QAEXXZ" to i8*), i8* null, i8* bitcast (%eh.CatchableTypeArray.5* @"_CTA5?AUY@@" to i8*) }, section ".xdata", comdat
16 // CHECK-DAG: @"_CT??_R0?AUDefault@@@8??_ODefault@@QAEXAAU0@@Z1" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 0, i8* bitcast (%rtti.TypeDescriptor13* @"??_R0?AUDefault@@@8" to i8*), i32 0, i32 -1, i32 0, i32 1, i8* bitcast (void (%struct.Default*, %struct.Default*)* @"??_ODefault@@QAEXAAU0@@Z" to i8*) }, section ".xdata", comdat
17 // CHECK-DAG: @"_CT??_R0?AUDeletedCopy@@@81" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 0, i8* bitcast (%rtti.TypeDescriptor17* @"??_R0?AUDeletedCopy@@@8" to i8*), i32 0, i32 -1, i32 0, i32 1, i8* null }, section ".xdata", comdat
18 // CHECk-DAG: @"_CT??_R0?AUMoveOnly@@@84" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 0, i8* bitcast (%rtti.TypeDescriptor14* @"??_R0?AUMoveOnly@@@8" to i8*), i32 0, i321-1, i32 0, i32 4, i8* null }, section ".xdata", comda
19 // CHECK-DAG: @"_CT??_R0?AUVariadic@@@8??_OVariadic@@QAEXAAU0@@Z1" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 0, i8* bitcast (%rtti.TypeDescriptor14* @"??_R0?AUVariadic@@@8" to i8*), i32 0, i32 -1, i32 0, i32 1, i8* bitcast (void (%struct.Variadic*, %struct.Variadic*)* @"??_OVariadic@@QAEXAAU0@@Z" to i8*) }, section ".xdata", comdat
20 // CHECK-DAG: @"_CT??_R0?AUTemplateWithDefault@@@8??$?_OH@TemplateWithDefault@@QAEXAAU0@@Z1" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 0, i8* bitcast (%rtti.TypeDescriptor25* @"??_R0?AUTemplateWithDefault@@@8" to i8*), i32 0, i32 -1, i32 0, i32 1, i8* bitcast (void (%struct.TemplateWithDefault*, %struct.TemplateWithDefault*)* @"??$?_OH@TemplateWithDefault@@QAEXAAU0@@Z" to i8*) }, section ".xdata", comdat
21 // CHECK-DAG: @"_CTA2$$T" = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.2 { i32 2, [2 x %eh.CatchableType*] [%eh.CatchableType* @"_CT??_R0$$T@84", %eh.CatchableType* @"_CT??_R0PAX@84"] }, section ".xdata", comdat
22 // CHECK-DAG: @"_CT??_R0P6AXXZ@84" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 1, i8* bitcast (%rtti.TypeDescriptor7* @"??_R0P6AXXZ@8" to i8*), i32 0, i32 -1, i32 0, i32 4, i8* null }, section ".xdata", comdat
23 // CHECK-DAG: @_CTA1P6AXXZ = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x %eh.CatchableType*] [%eh.CatchableType* @"_CT??_R0P6AXXZ@84"] }, section ".xdata", comdat
24 // CHECK-DAG: @_TI1P6AXXZ = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i8* null, i8* null, i8* bitcast (%eh.CatchableTypeArray.1* @_CTA1P6AXXZ to i8*) }, section ".xdata", comdat
25 // CHECK-DAG: @_TIU2PAPFAH = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 4, i8* null, i8* null, i8* bitcast (%eh.CatchableTypeArray.2* @_CTA2PAPFAH to i8*) }, section ".xdata", comdat
26 // CHECK-DAG: @_CTA2PAPFAH = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.2 { i32 2, [2 x %eh.CatchableType*] [%eh.CatchableType* @"_CT??_R0PAPFAH@84", %eh.CatchableType* @"_CT??_R0PAX@84"] }, section ".xdata", comdat
27 // CHECK-DAG: @"_TI1?AUFoo@?A0x{{[^@]*}}@@" = internal unnamed_addr constant %eh.ThrowInfo { i32 0, i8* null, i8* null, i8* bitcast (%eh.CatchableTypeArray.1* @"_CTA1?AUFoo@?A0x{{[^@]*}}@@" to i8*) }, section ".xdata"
28 
29 
30 struct N { ~N(); };
31 struct M : private N {};
32 struct X {};
33 struct Z {};
34 struct V : private X {};
35 struct W : M, virtual V {};
36 struct Y : Z, W, virtual V {};
37 
f(const Y & y)38 void f(const Y &y) {
39   // CHECK-LABEL: @"?f@@YAXABUY@@@Z"
40   // CHECK: call x86_thiscallcc %struct.Y* @"??0Y@@QAE@ABU0@@Z"(%struct.Y* %[[mem:.*]], %struct.Y*
41   // CHECK: %[[cast:.*]] = bitcast %struct.Y* %[[mem]] to i8*
42   // CHECK: call void @_CxxThrowException(i8* %[[cast]], %eh.ThrowInfo* @"_TI5?AUY@@")
43   throw y;
44 }
45 
g(const int * const * y)46 void g(const int *const *y) {
47   // CHECK-LABEL: @"?g@@YAXPBQBH@Z"
48   // CHECK: call void @_CxxThrowException(i8* %{{.*}}, %eh.ThrowInfo* @_TIC2PAPBH)
49   throw y;
50 }
51 
h(__unaligned int * __unaligned * y)52 void h(__unaligned int * __unaligned *y) {
53   // CHECK-LABEL: @"?h@@YAXPFAPFAH@Z"
54   // CHECK: call void @_CxxThrowException(i8* %{{.*}}, %eh.ThrowInfo* @_TIU2PAPFAH)
55   throw y;
56 }
57 
58 struct Default {
59   Default(Default &, int = 42);
60 };
61 
62 // CHECK-LABEL: @"??_ODefault@@QAEXAAU0@@Z"
63 // CHECK: %[[src_addr:.*]] = alloca
64 // CHECK: %[[this_addr:.*]] = alloca
65 // CHECK: store {{.*}} %src, {{.*}} %[[src_addr]], align 4
66 // CHECK: store {{.*}} %this, {{.*}} %[[this_addr]], align 4
67 // CHECK: %[[this:.*]] = load {{.*}} %[[this_addr]]
68 // CHECK: %[[src:.*]] = load {{.*}} %[[src_addr]]
69 // CHECK: call x86_thiscallcc {{.*}} @"??0Default@@QAE@AAU0@H@Z"({{.*}} %[[this]], {{.*}} %[[src]], i32 42)
70 // CHECK: ret void
71 
h(Default & d)72 void h(Default &d) {
73   throw d;
74 }
75 
76 struct DeletedCopy {
77   DeletedCopy();
78   DeletedCopy(DeletedCopy &&);
79   DeletedCopy(const DeletedCopy &) = delete;
80 };
throwDeletedCopy()81 void throwDeletedCopy() { throw DeletedCopy(); }
82 
83 
84 struct MoveOnly {
85   MoveOnly();
86   MoveOnly(MoveOnly &&);
87   ~MoveOnly();
88   MoveOnly(const MoveOnly &) = delete;
89 
90   // For some reason this subobject was important for reproducing PR43680
91   struct HasCopy {
92     HasCopy();
93     HasCopy(const HasCopy &o);
94     ~HasCopy();
95     int x;
96   } sub;
97 };
98 
throwMoveOnly()99 void throwMoveOnly() { throw MoveOnly(); }
100 
101 struct Variadic {
102   Variadic(Variadic &, ...);
103 };
104 
i(Variadic & v)105 void i(Variadic &v) {
106   throw v;
107 }
108 
109 // CHECK-LABEL: @"??_OVariadic@@QAEXAAU0@@Z"
110 // CHECK:  %[[src_addr:.*]] = alloca
111 // CHECK:  %[[this_addr:.*]] = alloca
112 // CHECK:  store {{.*}} %src, {{.*}} %[[src_addr:.*]], align
113 // CHECK:  store {{.*}} %this, {{.*}} %[[this_addr:.*]], align
114 // CHECK:  %[[this:.*]] = load {{.*}} %[[this_addr]]
115 // CHECK:  %[[src:.*]] = load {{.*}} %[[src_addr]]
116 // CHECK:  call {{.*}} @"??0Variadic@@QAA@AAU0@ZZ"({{.*}} %[[this]], {{.*}} %[[src]])
117 // CHECK:  ret void
118 
119 struct TemplateWithDefault {
120   template <typename T>
fTemplateWithDefault121   static int f() {
122     return 0;
123   }
124   template <typename T = int>
125   TemplateWithDefault(TemplateWithDefault &, T = f<T>());
126 };
127 
j(TemplateWithDefault & twd)128 void j(TemplateWithDefault &twd) {
129   throw twd;
130 }
131 
132 
h()133 void h() {
134   throw nullptr;
135 }
136 
137 #ifdef STD
138 namespace std {
139 template <typename T>
140 void *__GetExceptionInfo(T);
141 }
142 #else
143 template <typename T>
144 void *__GetExceptionInfo(T);
145 #endif
146 using namespace std;
147 
GetExceptionInfo_test0()148 void *GetExceptionInfo_test0() {
149 // CHECK-LABEL: @"?GetExceptionInfo_test0@@YAPAXXZ"
150 // CHECK:  ret i8* bitcast (%eh.ThrowInfo* @_TI1H to i8*)
151   return __GetExceptionInfo(0);
152 }
153 
GetExceptionInfo_test1()154 void *GetExceptionInfo_test1() {
155 // CHECK-LABEL: @"?GetExceptionInfo_test1@@YAPAXXZ"
156 // CHECK:  ret i8* bitcast (%eh.ThrowInfo* @_TI1P6AXXZ to i8*)
157   return __GetExceptionInfo<void (*)()>(&h);
158 }
159 
160 // PR36327: Try an exception type with no linkage.
161 namespace { struct Foo { } foo_exc; }
162 
GetExceptionInfo_test2()163 void *GetExceptionInfo_test2() {
164 // CHECK-LABEL: @"?GetExceptionInfo_test2@@YAPAXXZ"
165 // CHECK:  ret i8* bitcast (%eh.ThrowInfo* @"_TI1?AUFoo@?A0x{{[^@]*}}@@" to i8*)
166   return __GetExceptionInfo(foo_exc);
167 }
168