1 ; RUN: opt < %s -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(B *p) { return p->foo(); }
22 ; The virtual call in test can only be dispatched to B::foo (or a more-derived
23 ; class, if there was one), so A::foo can be removed.
25 %struct.A = type { i32 (...)** }
26 %struct.B = type { %struct.A }
28 ; CHECK: @_ZTV1A = internal unnamed_addr constant { [3 x i8*] } zeroinitializer
29 @_ZTV1A = internal unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*)* @_ZN1A3fooEv to i8*)] }, align 8, !type !0, !type !1, !vcall_visibility !2
31 ; CHECK: @_ZTV1B = internal unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.B*)* @_ZN1B3fooEv to i8*)] }
32 @_ZTV1B = internal unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.B*)* @_ZN1B3fooEv to i8*)] }, align 8, !type !0, !type !1, !type !3, !type !4, !vcall_visibility !2
34 ; CHECK-NOT: define internal i32 @_ZN1A3fooEv(
35 define internal i32 @_ZN1A3fooEv(%struct.A* nocapture readnone %this) {
40 ; CHECK: define internal i32 @_ZN1B3fooEv(
41 define internal i32 @_ZN1B3fooEv(%struct.B* nocapture readnone %this) {
46 define hidden void @_ZN1AC2Ev(%struct.A* nocapture %this) {
48 %0 = getelementptr inbounds %struct.A, %struct.A* %this, i64 0, i32 0
49 store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
53 define hidden void @_ZN1BC2Ev(%struct.B* nocapture %this) {
55 %0 = getelementptr inbounds %struct.B, %struct.B* %this, i64 0, i32 0, i32 0
56 store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1B, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
60 define hidden i32 @test(%struct.B* %p) {
62 %0 = bitcast %struct.B* %p to i8**
63 %vtable1 = load i8*, i8** %0, align 8
64 %1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable1, i32 0, metadata !"_ZTS1B"), !nosanitize !10
65 %2 = extractvalue { i8*, i1 } %1, 0, !nosanitize !10
66 %3 = bitcast i8* %2 to i32 (%struct.B*)*, !nosanitize !10
67 %call = tail call i32 %3(%struct.B* %p)
71 declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata) #2
73 !0 = !{i64 16, !"_ZTS1A"}
74 !1 = !{i64 16, !"_ZTSM1AFivE.virtual"}
76 !3 = !{i64 16, !"_ZTS1B"}
77 !4 = !{i64 16, !"_ZTSM1BFivE.virtual"}