[InstCombine] Preserve NSW flags for `lshr (mul nuw X, C1), C2 -> mul nuw nsw X,...
[llvm-project.git] / clang / test / CodeGenCXX / type-metadata.cpp
blob4ddfc3c2e3a8fff66a07e86778362829d6efa141
1 // A meta comment on the prefixes:
2 // ITANIUM-COMMON-MD prefix is common when the options are either non-relative vtable or relative vtables.
3 // ITANIUM-NO-RV-MD prefix is used when the options specify non-relative vtables, and RV-MD is used when the options specify relative vtables.
5 // Tests for the cfi-vcall feature:
6 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-COMMON-MD --check-prefix=ITANIUM-NO-RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG %s
7 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-COMMON-MD --check-prefix=ITANIUM-NO-RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-NO-RV-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s
8 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-COMMON-MD --check-prefix=ITANIUM-NO-RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-NO-RV-MD-DIAG --check-prefix=ITANIUM-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s
9 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT-NO-RV --check-prefix=MS --check-prefix=MS-TYPEMETADATA --check-prefix=TT-MS --check-prefix=NDIAG %s
11 // Tests for the whole-program-vtables feature:
12 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-COMMON-MD --check-prefix=ITANIUM-NO-RV-MD --check-prefix=TT-ITANIUM-HIDDEN %s
13 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-DEFAULTVIS --check-prefix=TT-ITANIUM-DEFAULT %s
14 // RUN: %clang_cc1 -O2 -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=ITANIUM-OPT --check-prefix=ITANIUM-OPT-LAYOUT %s
15 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=MS-TYPEMETADATA --check-prefix=TT-MS %s
17 // Tests for cfi + whole-program-vtables:
18 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-COMMON-MD --check-prefix=TC-ITANIUM --check-prefix=ITANIUM-NO-RV-MD %s
19 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=MS --check-prefix=MS-TYPEMETADATA --check-prefix=TC-MS %s
21 // Equivalent tests for above, but with relative-vtables.
22 // Tests for the cfi-vcall feature:
23 // RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=RV-MD --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-COMMON-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=NDIAG --check-prefix=CFI-NVT-RV %s
24 // RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=CFI-NVT-RV --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-COMMON-MD --check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-DIAG --check-prefix=RV-MD-DIAG --check-prefix=DIAG --check-prefix=DIAG-ABORT %s
25 // RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-recover=cfi-vcall -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-NVT --check-prefix=CFI-NVT-RV --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-COMMON-MD --check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN --check-prefix=ITANIUM-DIAG --check-prefix=RV-MD-DIAG --check-prefix=DIAG --check-prefix=DIAG-RECOVER %s
27 // Tests for the whole-program-vtables feature:
28 // RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-COMMON-MD -check-prefix=RV-MD --check-prefix=TT-ITANIUM-HIDDEN %s
29 // RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-DEFAULTVIS --check-prefix=TT-ITANIUM-DEFAULT %s
30 // RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -O2 -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=ITANIUM-OPT --check-prefix=RV-OPT-LAYOUT %s
32 // Tests for cfi + whole-program-vtables:
33 // RUN: %clang_cc1 -fexperimental-relative-c++-abi-vtables -flto -flto-unit -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CFI --check-prefix=CFI-VT --check-prefix=ITANIUM-HIDDEN --check-prefix=ITANIUM-COMMON-MD --check-prefix=RV-MD --check-prefix=TC-ITANIUM %s
35 // Tests that type metadata are annotated on vtables with `-profile-instrument=llvm` (which is equivalent to clang driver option `-fprofile-generate` without `-fcs-profile-generate`):
36 // - In clang driver, `-fprofile-instrument` cc1 option is set to 'llvm' iff clang driver option `-fprofile-generate{,=}` is taking effect.
37 // RUN: %clang_cc1 -fprofile-instrument=llvm -fno-lto -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefix=ITANIUM-COMMON-MD
38 // RUN: %clang_cc1 -fprofile-instrument=llvm -fno-lto -triple x86_64-pc-windows-msvc -emit-llvm %s -o - | FileCheck %s --check-prefix=MS-TYPEMETADATA
40 // Tests type metadata are not annotated on vtables if `-fno-lto` is specified and `-fprofile-instrument` is any of {none, clang, csllvm}.
41 // This is mainly for test coverage; there isn't a fundamental reason type metadata couldn't be annotated with those options.
43 // RUN: %clang_cc1 -fprofile-instrument=none -fno-lto -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --implicit-check-not="!type"
44 // RUN: %clang_cc1 -fprofile-instrument=clang -fno-lto -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --implicit-check-not="!type"
45 // RUN: %clang_cc1 -fprofile-instrument=csllvm -fno-lto -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --implicit-check-not="!type"
47 // RUN: %clang_cc1 -fprofile-instrument=none -fno-lto -triple x86_64-pc-windows-msvc -emit-llvm %s -o - | FileCheck %s --implicit-check-not="!type"
48 // RUN: %clang_cc1 -fprofile-instrument=clang -fno-lto -triple x86_64-pc-windows-msvc -emit-llvm %s -o - | FileCheck %s --implicit-check-not="!type"
49 // RUN: %clang_cc1 -fprofile-instrument=csllvm -fno-lto -triple x86_64-pc-windows-msvc -emit-llvm %s -o - | FileCheck %s --implicit-check-not="!type"
51 // ITANIUM-COMMON-MD: @_ZTV1A = {{[^!]*}}, !type [[A16:![0-9]+]]
52 // ITANIUM-DIAG-SAME: !type [[ALL16:![0-9]+]]
53 // ITANIUM-COMMON-MD-SAME: !type [[AF16:![0-9]+]]
55 // ITANIUM-COMMON-MD: @_ZTV1B = {{[^!]*}}, !type [[A32:![0-9]+]]
56 // ITANIUM-DIAG-SAME: !type [[ALL32:![0-9]+]]
57 // ITANIUM-COMMON-MD-SAME: !type [[AF32:![0-9]+]]
58 // ITANIUM-COMMON-MD-SAME: !type [[AF40:![0-9]+]]
59 // ITANIUM-COMMON-MD-SAME: !type [[AF48:![0-9]+]]
60 // ITANIUM-COMMON-MD-SAME: !type [[B32:![0-9]+]]
61 // ITANIUM-DIAG-SAME: !type [[ALL32]]
62 // ITANIUM-COMMON-MD-SAME: !type [[BF32:![0-9]+]]
63 // ITANIUM-COMMON-MD-SAME: !type [[BF40:![0-9]+]]
64 // ITANIUM-COMMON-MD-SAME: !type [[BF48:![0-9]+]]
66 // ITANIUM-COMMON-MD: @_ZTV1C = {{[^!]*}}, !type [[A32]]
67 // ITANIUM-DIAG-SAME: !type [[ALL32]]
68 // ITANIUM-COMMON-MD-SAME: !type [[AF32]]
69 // ITANIUM-COMMON-MD-SAME: !type [[C32:![0-9]+]]
70 // ITANIUM-DIAG-SAME: !type [[ALL32]]
71 // ITANIUM-COMMON-MD-SAME: !type [[CF32:![0-9]+]]
73 // DIAG: @[[SRC:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}type-metadata.cpp\00", align 1
74 // DIAG: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" }
75 // DIAG: @[[BADTYPESTATIC:.*]] = private unnamed_addr global { i8, { ptr, i32, i32 }, ptr } { i8 0, { ptr, i32, i32 } { ptr @[[SRC]], i32 123, i32 3 }, ptr @[[TYPE]] }
77 // ITANIUM-COMMON-MD: @_ZTVN12_GLOBAL__N_11DE = {{[^!]*}}, !type [[A32]]
78 // ITANIUM-DIAG-SAME: !type [[ALL32]]
79 // ITANIUM-COMMON-MD-SAME: !type [[AF32]]
80 // ITANIUM-COMMON-MD-SAME: !type [[AF40]]
81 // ITANIUM-COMMON-MD-SAME: !type [[AF48]]
82 // ITANIUM-COMMON-MD-SAME: !type [[B32]]
83 // ITANIUM-DIAG-SAME: !type [[ALL32]]
84 // ITANIUM-COMMON-MD-SAME: !type [[BF32]]
85 // ITANIUM-COMMON-MD-SAME: !type [[BF40]]
86 // ITANIUM-COMMON-MD-SAME: !type [[BF48]]
87 // ITANIUM-COMMON-MD-SAME: !type [[C88:![0-9]+]]
88 // ITANIUM-DIAG-SAME: !type [[ALL88:![0-9]+]]
89 // ITANIUM-COMMON-MD-SAME: !type [[CF32]]
90 // ITANIUM-COMMON-MD-SAME: !type [[CF40:![0-9]+]]
91 // ITANIUM-COMMON-MD-SAME: !type [[CF48:![0-9]+]]
92 // ITANIUM-COMMON-MD-SAME: !type [[D32:![0-9]+]]
93 // ITANIUM-DIAG-SAME: !type [[ALL32]]
94 // ITANIUM-COMMON-MD-SAME: !type [[DF32:![0-9]+]]
95 // ITANIUM-COMMON-MD-SAME: !type [[DF40:![0-9]+]]
96 // ITANIUM-COMMON-MD-SAME: !type [[DF48:![0-9]+]]
98 // ITANIUM-COMMON-MD: @_ZTCN12_GLOBAL__N_11DE0_1B = {{[^!]*}}, !type [[A32]]
99 // ITANIUM-DIAG-SAME: !type [[ALL32]]
100 // ITANIUM-COMMON-MD-SAME: !type [[B32]]
101 // ITANIUM-DIAG-SAME: !type [[ALL32]]
103 // ITANIUM-COMMON-MD: @_ZTCN12_GLOBAL__N_11DE8_1C = {{[^!]*}}, !type [[A64:![0-9]+]]
104 // ITANIUM-DIAG-SAME: !type [[ALL64:![0-9]+]]
105 // ITANIUM-COMMON-MD-SAME: !type [[AF64:![0-9]+]]
106 // ITANIUM-COMMON-MD-SAME: !type [[C32]]
107 // ITANIUM-DIAG-SAME: !type [[ALL32]]
108 // ITANIUM-COMMON-MD-SAME: !type [[CF64:![0-9]+]]
110 // ITANIUM-COMMON-MD: @_ZTVZ3foovE2FA = {{[^!]*}}, !type [[A16]]
111 // ITANIUM-DIAG-SAME: !type [[ALL16]]
112 // ITANIUM-COMMON-MD-SAME: !type [[AF16]]
113 // ITANIUM-COMMON-MD-SAME: !type [[FA16:![0-9]+]]
114 // ITANIUM-DIAG-SAME: !type [[ALL16]]
115 // ITANIUM-COMMON-MD-SAME: !type [[FAF16:![0-9]+]]
117 // ITANIUM-COMMON-MD: @_ZTVN5test31EE = external unnamed_addr constant
118 // ITANIUM-DEFAULTVIS: @_ZTVN5test31EE = external unnamed_addr constant
119 // ITANIUM-OPT: @_ZTVN5test31EE = available_externally unnamed_addr constant {{[^!]*}},
120 // ITANIUM-OPT-SAME: !type [[E16:![0-9]+]],
121 // ITANIUM-OPT-SAME: !type [[EF16:![0-9]+]]
122 // ITANIUM-OPT: @llvm.compiler.used = appending global [1 x ptr] [ptr @_ZTVN5test31EE]
124 // MS-TYPEMETADATA: comdat($"??_7A@@6B@"), !type [[A8:![0-9]+]]
125 // MS-TYPEMETADATA: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]]
126 // MS-TYPEMETADATA: comdat($"??_7B@@6BA@@@"), !type [[A8]]
127 // MS-TYPEMETADATA: comdat($"??_7C@@6B@"), !type [[A8]]
128 // MS-TYPEMETADATA: private unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr @"??_R4D@?{{.*}}@@6BB@@@", ptr @"?g@B@@UEAAXXZ", ptr @"?h@D@?{{.*}}@@UEAAXXZ"] }, !type [[B8]], !type [[D8:![0-9]+]]
129 // MS-TYPEMETADATA: private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4D@?{{.*}}@@6BA@@@", ptr @"?f@D@?{{.*}}@@$4PPPPPPPM@A@EAAXXZ"] }, !type !0
130 // MS: private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4FA@?1??foo@@YAXXZ@6B@", ptr @"?f@FA@?1??foo@@YAXXZ@UEAAXXZ"] }, !type !0, !type [[FA8:![0-9]+]]
132 struct A {
133 A();
134 virtual void f();
137 struct B : virtual A {
138 B();
139 virtual void g();
140 virtual void h();
143 struct C : virtual A {
144 C();
147 namespace {
149 struct D : B, C {
150 D();
151 virtual void f();
152 virtual void h();
157 A::A() {}
158 B::B() {}
159 C::C() {}
160 D::D() {}
162 void A::f() {
165 void B::g() {
168 void D::f() {
171 void D::h() {
174 // ITANIUM-HIDDEN: define hidden void @_Z2afP1A
175 // ITANIUM-DEFAULTVIS: define{{.*}} void @_Z2afP1A
176 // MS: define dso_local void @"?af@@YAXPEAUA@@@Z"
177 void af(A *a) {
178 // TT-ITANIUM-HIDDEN: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr [[VT:%[^ ]*]], metadata !"_ZTS1A")
179 // TT-ITANIUM-DEFAULT: [[P:%[^ ]*]] = call i1 @llvm.public.type.test(ptr [[VT:%[^ ]*]], metadata !"_ZTS1A")
180 // TT-MS: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr [[VT:%[^ ]*]], metadata !"?AUA@@")
181 // TC-ITANIUM: [[PAIR:%[^ ]*]] = call { ptr, i1 } @llvm.type.checked.load(ptr {{%[^ ]*}}, i32 0, metadata !"_ZTS1A")
182 // TC-MS: [[PAIR:%[^ ]*]] = call { ptr, i1 } @llvm.type.checked.load(ptr {{%[^ ]*}}, i32 0, metadata !"?AUA@@")
183 // CFI-VT: [[P:%[^ ]*]] = extractvalue { ptr, i1 } [[PAIR]], 1
184 // DIAG-NEXT: [[VTVALID0:%[^ ]*]] = call i1 @llvm.type.test(ptr [[VT]], metadata !"all-vtables")
185 // VTABLE-OPT: call void @llvm.assume(i1 [[P]])
186 // CFI-NEXT: br i1 [[P]], label %[[CONTBB:[^ ,]*]], label %[[TRAPBB:[^ ,]*]]
187 // CFI-NEXT: {{^$}}
189 // CFI: [[TRAPBB]]
190 // NDIAG-NEXT: call void @llvm.ubsantrap(i8 2)
191 // NDIAG-NEXT: unreachable
192 // DIAG-NEXT: [[VTINT:%[^ ]*]] = ptrtoint ptr [[VT]] to i64
193 // DIAG-NEXT: [[VTVALID:%[^ ]*]] = zext i1 [[VTVALID0]] to i64
194 // DIAG-ABORT-NEXT: call void @__ubsan_handle_cfi_check_fail_abort(ptr @[[BADTYPESTATIC]], i64 [[VTINT]], i64 [[VTVALID]])
195 // DIAG-ABORT-NEXT: unreachable
196 // DIAG-RECOVER-NEXT: call void @__ubsan_handle_cfi_check_fail(ptr @[[BADTYPESTATIC]], i64 [[VTINT]], i64 [[VTVALID]])
197 // DIAG-RECOVER-NEXT: br label %[[CONTBB]]
199 // CFI: [[CONTBB]]
200 // CFI-NVT-NO-RV: [[PTR:%[^ ]*]] = load
201 // CFI-NVT-RV: [[PTR:%[^ ]*]] = call ptr @llvm.load.relative.i32
202 // CFI-VT: [[PTR:%[^ ]*]] = extractvalue { ptr, i1 } [[PAIR]], 0
203 // CFI: call void [[PTR]]
204 #line 123
205 a->f();
208 // ITANIUM-HIDDEN: define internal void @_Z3df1PN12_GLOBAL__N_11DE
209 // MS: define internal void @"?df1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z"
210 void df1(D *d) {
211 // TT-ITANIUM-HIDDEN: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata ![[DTYPE:[0-9]+]])
212 // TT-ITANIUM-DEFAULT: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata ![[DTYPE:[0-9]+]])
213 // TT-MS: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"?AUA@@")
214 // TC-ITANIUM: {{%[^ ]*}} = call { ptr, i1 } @llvm.type.checked.load(ptr {{%[^ ]*}}, i32 0, metadata ![[DTYPE:[0-9]+]])
215 // TC-MS: {{%[^ ]*}} = call { ptr, i1 } @llvm.type.checked.load(ptr {{%[^ ]*}}, i32 0, metadata !"?AUA@@")
216 d->f();
219 // ITANIUM-HIDDEN: define internal void @_Z3dg1PN12_GLOBAL__N_11DE
220 // MS: define internal void @"?dg1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z"
221 void dg1(D *d) {
222 // TT-ITANIUM-HIDDEN: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1B")
223 // TT-ITANIUM-DEFAULT: {{%[^ ]*}} = call i1 @llvm.public.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1B")
224 // TT-MS: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"?AUB@@")
225 // TC-ITANIUM: {{%[^ ]*}} = call { ptr, i1 } @llvm.type.checked.load(ptr {{%[^ ]*}}, i32 8, metadata !"_ZTS1B")
226 // TC-MS: {{%[^ ]*}} = call { ptr, i1 } @llvm.type.checked.load(ptr {{%[^ ]*}}, i32 0, metadata !"?AUB@@")
227 d->g();
230 // ITANIUM-HIDDEN: define internal void @_Z3dh1PN12_GLOBAL__N_11DE
231 // MS: define internal void @"?dh1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z"
232 void dh1(D *d) {
233 // TT-ITANIUM-HIDDEN: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata ![[DTYPE]])
234 // TT-ITANIUM-DEFAULT: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata ![[DTYPE]])
235 // TT-MS: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata ![[DTYPE:[0-9]+]])
236 // TC-ITANIUM: {{%[^ ]*}} = call { ptr, i1 } @llvm.type.checked.load(ptr {{%[^ ]*}}, i32 16, metadata ![[DTYPE]])
237 // TC-MS: {{%[^ ]*}} = call { ptr, i1 } @llvm.type.checked.load(ptr {{%[^ ]*}}, i32 8, metadata ![[DTYPE:[0-9]+]])
238 d->h();
241 // ITANIUM-HIDDEN: define internal void @_Z3df2PN12_GLOBAL__N_11DE
242 // MS: define internal void @"?df2@@YAXPEAUD@?A0x{{[^@]*}}@@@Z"
243 __attribute__((no_sanitize("cfi")))
244 void df2(D *d) {
245 // CFI-NVT-NOT: call i1 @llvm.type.test
246 // CFI-VT: [[P:%[^ ]*]] = call i1 @llvm.type.test
247 // CFI-VT: call void @llvm.assume(i1 [[P]])
248 d->f();
251 // ITANIUM-HIDDEN: define internal void @_Z3df3PN12_GLOBAL__N_11DE
252 // MS: define internal void @"?df3@@YAXPEAUD@?A0x{{[^@]*}}@@@Z"
253 __attribute__((no_sanitize("address"))) __attribute__((no_sanitize("cfi-vcall")))
254 void df3(D *d) {
255 // CFI-NVT-NOT: call i1 @llvm.type.test
256 // CFI-VT: [[P:%[^ ]*]] = call i1 @llvm.type.test
257 // CFI-VT: call void @llvm.assume(i1 [[P]])
258 d->f();
261 D d;
263 void foo() {
264 df1(&d);
265 dg1(&d);
266 dh1(&d);
267 df2(&d);
268 df3(&d);
270 struct FA : A {
271 void f() {}
272 } fa;
273 af(&fa);
276 namespace test2 {
278 struct A {
279 virtual void m_fn1();
281 struct B {
282 virtual void m_fn2();
284 struct C : B, A {};
285 struct D : C {
286 void m_fn1();
289 // ITANIUM-HIDDEN: define hidden void @_ZN5test21fEPNS_1DE
290 // ITANIUM-DEFAULTVIS: define{{.*}} void @_ZN5test21fEPNS_1DE
291 // MS: define dso_local void @"?f@test2@@YAXPEAUD@1@@Z"
292 void f(D *d) {
293 // TT-ITANIUM-HIDDEN: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTSN5test21DE")
294 // TT-ITANIUM-DEFAULT: {{%[^ ]*}} = call i1 @llvm.public.type.test(ptr {{%[^ ]*}}, metadata !"_ZTSN5test21DE")
295 // TT-MS: {{%[^ ]*}} = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"?AUA@test2@@")
296 // TC-ITANIUM: {{%[^ ]*}} = call { ptr, i1 } @llvm.type.checked.load(ptr {{%[^ ]*}}, i32 8, metadata !"_ZTSN5test21DE")
297 // TC-MS: {{%[^ ]*}} = call { ptr, i1 } @llvm.type.checked.load(ptr {{%[^ ]*}}, i32 0, metadata !"?AUA@test2@@")
298 d->m_fn1();
303 namespace test3 {
304 // All virtual functions are outline, so we can assume that it will
305 // be generated in translation unit where foo is defined.
306 struct E {
307 virtual void foo();
310 void g() {
311 E e;
312 e.foo();
315 } // Test9
317 // RV-MD: [[A16]] = !{i64 8, !"_ZTS1A"}
318 // RV-MD-DIAG: [[ALL16]] = !{i64 8, !"all-vtables"}
319 // RV-MD: [[AF16]] = !{i64 8, !"_ZTSM1AFvvE.virtual"}
320 // RV-MD: [[A32]] = !{i64 16, !"_ZTS1A"}
321 // RV-MD-DIAG: [[ALL32]] = !{i64 16, !"all-vtables"}
322 // RV-MD: [[AF32]] = !{i64 16, !"_ZTSM1AFvvE.virtual"}
323 // RV-MD: [[AF40]] = !{i64 20, !"_ZTSM1AFvvE.virtual"}
324 // RV-MD: [[AF48]] = !{i64 24, !"_ZTSM1AFvvE.virtual"}
325 // RV-MD: [[B32]] = !{i64 16, !"_ZTS1B"}
326 // RV-MD: [[BF32]] = !{i64 16, !"_ZTSM1BFvvE.virtual"}
327 // RV-MD: [[BF40]] = !{i64 20, !"_ZTSM1BFvvE.virtual"}
328 // RV-MD: [[BF48]] = !{i64 24, !"_ZTSM1BFvvE.virtual"}
329 // RV-MD: [[C32]] = !{i64 16, !"_ZTS1C"}
330 // RV-MD: [[CF32]] = !{i64 16, !"_ZTSM1CFvvE.virtual"}
331 // RV-MD: [[C88]] = !{i64 44, !"_ZTS1C"}
332 // RV-MD-DIAG: [[ALL88]] = !{i64 44, !"all-vtables"}
333 // RV-MD: [[CF40]] = !{i64 20, !"_ZTSM1CFvvE.virtual"}
334 // RV-MD: [[CF48]] = !{i64 24, !"_ZTSM1CFvvE.virtual"}
335 // RV-MD: [[D32]] = !{i64 16, [[D_ID:![0-9]+]]}
336 // RV-MD: [[D_ID]] = distinct !{}
337 // RV-MD: [[DF32]] = !{i64 16, [[DF_ID:![0-9]+]]}
338 // RV-MD: [[DF_ID]] = distinct !{}
339 // RV-MD: [[DF40]] = !{i64 20, [[DF_ID]]}
340 // RV-MD: [[DF48]] = !{i64 24, [[DF_ID]]}
341 // RV-MD: [[A64]] = !{i64 32, !"_ZTS1A"}
342 // RV-MD-DIAG: [[ALL64]] = !{i64 32, !"all-vtables"}
343 // RV-MD: [[AF64]] = !{i64 32, !"_ZTSM1AFvvE.virtual"}
344 // RV-MD: [[CF64]] = !{i64 32, !"_ZTSM1CFvvE.virtual"}
345 // RV-MD: [[FA16]] = !{i64 8, [[FA_ID:![0-9]+]]}
346 // RV-MD: [[FA_ID]] = distinct !{}
347 // RV-MD: [[FAF16]] = !{i64 8, [[FAF_ID:![0-9]+]]}
348 // RV-MD: [[FAF_ID]] = distinct !{}
350 // ITANIUM-NO-RV-MD: [[A16]] = !{i64 16, !"_ZTS1A"}
351 // ITANIUM-NO-RV-MD-DIAG: [[ALL16]] = !{i64 16, !"all-vtables"}
352 // ITANIUM-NO-RV-MD: [[AF16]] = !{i64 16, !"_ZTSM1AFvvE.virtual"}
353 // ITANIUM-NO-RV-MD: [[A32]] = !{i64 32, !"_ZTS1A"}
354 // ITANIUM-NO-RV-MD-DIAG: [[ALL32]] = !{i64 32, !"all-vtables"}
355 // ITANIUM-NO-RV-MD: [[AF32]] = !{i64 32, !"_ZTSM1AFvvE.virtual"}
356 // ITANIUM-NO-RV-MD: [[AF40]] = !{i64 40, !"_ZTSM1AFvvE.virtual"}
357 // ITANIUM-NO-RV-MD: [[AF48]] = !{i64 48, !"_ZTSM1AFvvE.virtual"}
358 // ITANIUM-NO-RV-MD: [[B32]] = !{i64 32, !"_ZTS1B"}
359 // ITANIUM-NO-RV-MD: [[BF32]] = !{i64 32, !"_ZTSM1BFvvE.virtual"}
360 // ITANIUM-NO-RV-MD: [[BF40]] = !{i64 40, !"_ZTSM1BFvvE.virtual"}
361 // ITANIUM-NO-RV-MD: [[BF48]] = !{i64 48, !"_ZTSM1BFvvE.virtual"}
362 // ITANIUM-NO-RV-MD: [[C32]] = !{i64 32, !"_ZTS1C"}
363 // ITANIUM-NO-RV-MD: [[CF32]] = !{i64 32, !"_ZTSM1CFvvE.virtual"}
364 // ITANIUM-NO-RV-MD: [[C88]] = !{i64 88, !"_ZTS1C"}
365 // ITANIUM-NO-RV-MD-DIAG: [[ALL88]] = !{i64 88, !"all-vtables"}
366 // ITANIUM-NO-RV-MD: [[CF40]] = !{i64 40, !"_ZTSM1CFvvE.virtual"}
367 // ITANIUM-NO-RV-MD: [[CF48]] = !{i64 48, !"_ZTSM1CFvvE.virtual"}
368 // ITANIUM-NO-RV-MD: [[D32]] = !{i64 32, [[D_ID:![0-9]+]]}
369 // ITANIUM-NO-RV-MD: [[D_ID]] = distinct !{}
370 // ITANIUM-NO-RV-MD: [[DF32]] = !{i64 32, [[DF_ID:![0-9]+]]}
371 // ITANIUM-NO-RV-MD: [[DF_ID]] = distinct !{}
372 // ITANIUM-NO-RV-MD: [[DF40]] = !{i64 40, [[DF_ID]]}
373 // ITANIUM-NO-RV-MD: [[DF48]] = !{i64 48, [[DF_ID]]}
374 // ITANIUM-NO-RV-MD: [[A64]] = !{i64 64, !"_ZTS1A"}
375 // ITANIUM-NO-RV-MD-DIAG: [[ALL64]] = !{i64 64, !"all-vtables"}
376 // ITANIUM-NO-RV-MD: [[AF64]] = !{i64 64, !"_ZTSM1AFvvE.virtual"}
377 // ITANIUM-NO-RV-MD: [[CF64]] = !{i64 64, !"_ZTSM1CFvvE.virtual"}
378 // ITANIUM-NO-RV-MD: [[FA16]] = !{i64 16, [[FA_ID:![0-9]+]]}
379 // ITANIUM-NO-RV-MD: [[FA_ID]] = distinct !{}
380 // ITANIUM-NO-RV-MD: [[FAF16]] = !{i64 16, [[FAF_ID:![0-9]+]]}
381 // ITANIUM-NO-RV-MD: [[FAF_ID]] = distinct !{}
383 // ITANIUM-OPT-LAYOUT: [[E16]] = !{i64 16, !"_ZTSN5test31EE"}
384 // ITANIUM-OPT-LAYOUT: [[EF16]] = !{i64 16, !"_ZTSMN5test31EEFvvE.virtual"}
385 // RV-OPT-LAYOUT: [[E16]] = !{i64 8, !"_ZTSN5test31EE"}
386 // RV-OPT-LAYOUT: [[EF16]] = !{i64 8, !"_ZTSMN5test31EEFvvE.virtual"}
388 // MS: [[A8]] = !{i64 8, !"?AUA@@"}
389 // MS: [[B8]] = !{i64 8, !"?AUB@@"}
390 // MS: [[D8]] = !{i64 8, [[D_ID:![0-9]+]]}
391 // MS: [[D_ID]] = distinct !{}
392 // MS: [[FA8]] = !{i64 8, [[FA_ID:![0-9]+]]}
393 // MS: [[FA_ID]] = distinct !{}