1; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
2
3target datalayout = "e-p:64:64"
4target triple = "x86_64-unknown-linux-gnu"
5
6@vt1 = constant [1 x i8*] [i8* bitcast (i32 (i8*, i32)* @vf1 to i8*)], !type !0
7@vt2 = constant [1 x i8*] [i8* bitcast (i32 (i8*, i32)* @vf2 to i8*)], !type !0
8
9declare i32 @vf1(i8* %this, i32 %arg) readnone
10
11define i32 @vf2(i8* %this, i32 %arg) readnone {
12  ret i32 %arg
13}
14
15; CHECK: define i32 @fn
16define i32 @fn(i8* %obj) {
17  %vtableptr = bitcast i8* %obj to [1 x i8*]**
18  %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
19  %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
20  %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
21  call void @llvm.assume(i1 %p)
22  %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
23  %fptr = load i8*, i8** %fptrptr
24  %fptr_casted = bitcast i8* %fptr to i32 (i8*, i32)*
25  ; CHECK: call i32 %
26  %result = call i32 %fptr_casted(i8* %obj, i32 1)
27  ret i32 %result
28}
29declare i1 @llvm.type.test(i8*, metadata)
30declare void @llvm.assume(i1)
31
32!0 = !{i32 0, !"typeid"}
33