1; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
2
3target datalayout = "e-p:64:64"
4target triple = "x86_64-unknown-linux-gnu"
5
6%vtTy = type { [2 x void (i8*)*], [2 x void (i8*)*] }
7
8@vt = constant %vtTy { [2 x void (i8*)*] [void (i8*)* null, void (i8*)* @vf1], [2 x void (i8*)*] [void (i8*)* null, void (i8*)* @vf2] }, !type !0, !type !1
9
10define void @vf1(i8* %this) {
11  ret void
12}
13
14define void @vf2(i8* %this) {
15  ret void
16}
17
18; CHECK: define void @call1
19define void @call1(i8* %obj) {
20  %vtableptr = bitcast i8* %obj to [1 x i8*]**
21  %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
22  %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
23  %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid1")
24  call void @llvm.assume(i1 %p)
25  %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
26  %fptr = load i8*, i8** %fptrptr
27  %fptr_casted = bitcast i8* %fptr to void (i8*)*
28  ; CHECK: call void @vf1(
29  call void %fptr_casted(i8* %obj)
30  ret void
31}
32
33; CHECK: define void @call2
34define void @call2(i8* %obj) {
35  %vtableptr = bitcast i8* %obj to [1 x i8*]**
36  %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
37  %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
38  %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid2")
39  call void @llvm.assume(i1 %p)
40  %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
41  %fptr = load i8*, i8** %fptrptr
42  %fptr_casted = bitcast i8* %fptr to void (i8*)*
43  ; CHECK: call void @vf2(
44  call void %fptr_casted(i8* %obj)
45  ret void
46}
47
48declare i1 @llvm.type.test(i8*, metadata)
49declare void @llvm.assume(i1)
50
51!0 = !{i32 8, !"typeid1"}
52!1 = !{i32 24, !"typeid2"}
53