1 ; RUN: opt < %s -passes=globaldce -S | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
17 ; int A::foo() { return 42; }
18 ; int B::foo() { return 1337; }
20 ; extern "C" int test(A *p) { return p->foo(); }
22 ; The virtual call in test could be dispatched to either A::foo or B::foo, so
23 ; both must be retained.
25 %struct.A = type { ptr }
26 %struct.B = type { %struct.A }
28 ; CHECK: @_ZTV1A = internal unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv] }
29 @_ZTV1A = internal unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv] }, align 8, !type !0, !type !1, !vcall_visibility !2
31 ; CHECK: @_ZTV1B = internal unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEv] }
32 @_ZTV1B = internal unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEv] }, align 8, !type !0, !type !1, !type !3, !type !4, !vcall_visibility !2
34 ; CHECK: define internal i32 @_ZN1A3fooEv(
35 define internal i32 @_ZN1A3fooEv(ptr nocapture readnone %this) {
40 ; CHECK: define internal i32 @_ZN1B3fooEv(
41 define internal i32 @_ZN1B3fooEv(ptr nocapture readnone %this) {
46 define hidden void @_ZN1AC2Ev(ptr nocapture %this) {
48 store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), ptr %this, align 8
52 define hidden void @_ZN1BC2Ev(ptr nocapture %this) {
54 store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1B, i64 0, inrange i32 0, i64 2), ptr %this, align 8
58 define hidden i32 @test(ptr %p) {
60 %vtable1 = load ptr, ptr %p, align 8
61 %0 = tail call { ptr, i1 } @llvm.type.checked.load(ptr %vtable1, i32 0, metadata !"_ZTS1A"), !nosanitize !10
62 %1 = extractvalue { ptr, i1 } %0, 0, !nosanitize !10
63 %call = tail call i32 %1(ptr %p)
67 declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata) #2
69 !llvm.module.flags = !{!5}
71 !0 = !{i64 16, !"_ZTS1A"}
72 !1 = !{i64 16, !"_ZTSM1AFivE.virtual"}
74 !3 = !{i64 16, !"_ZTS1B"}
75 !4 = !{i64 16, !"_ZTSM1BFivE.virtual"}
76 !5 = !{i32 1, !"Virtual Function Elim", i32 1}