1 ; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
3 target datalayout = "e-p:64:64"
4 target triple = "x86_64-unknown-linux-gnu"
6 %vtTy = type { void (i8*)* }
8 @vt = constant %vtTy { void (i8*)* @vf }, !type !0
10 define void @vf(i8* %this) {
14 ; CHECK: define void @call
15 define void @call(i8* %obj) {
16 %vtableptr = bitcast i8* %obj to [1 x i8*]**
17 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
18 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
19 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
20 call void @llvm.assume(i1 %p)
21 %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
22 %fptr = load i8*, i8** %fptrptr
23 %fptr_casted = bitcast i8* %fptr to void (i8*)*
24 ; CHECK: call void @vf(
25 call void %fptr_casted(i8* %obj)
29 ; CHECK: define void @call_oob
30 define void @call_oob(i8* %obj) {
31 %vtableptr = bitcast i8* %obj to [1 x i8*]**
32 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
33 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
34 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
35 call void @llvm.assume(i1 %p)
36 %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 4
37 %fptr = load i8*, i8** %fptrptr
38 %fptr_casted = bitcast i8* %fptr to void (i8*)*
40 call void %fptr_casted(i8* %obj)
44 ; CHECK: define void @call_unaligned
45 define void @call_unaligned(i8* %obj) {
46 %vtableptr = bitcast i8* %obj to [1 x i8*]**
47 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
48 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
49 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
50 call void @llvm.assume(i1 %p)
51 %fptrptr = getelementptr i8, i8* %vtablei8, i32 1
52 %fptrptr_casted = bitcast i8* %fptrptr to i8**
53 %fptr = load i8*, i8** %fptrptr_casted
54 %fptr_casted = bitcast i8* %fptr to void (i8*)*
56 call void %fptr_casted(i8* %obj)
60 declare i1 @llvm.type.test(i8*, metadata)
61 declare void @llvm.assume(i1)
63 !0 = !{i32 0, !"typeid"}