1 ; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
3 target datalayout = "e-p:64:64"
4 target triple = "x86_64-unknown-linux-gnu"
6 @vt1 = constant [2 x i8*] [i8* zeroinitializer, i8* bitcast (void (i8*)* @vf to i8*)], !type !0
7 @vt2 = constant i8* bitcast (void (i8*)* @vf to i8*), !type !1
9 define void @vf(i8* %this) {
13 ; CHECK: define void @unaligned1
14 define void @unaligned1(i8* %obj) {
15 %vtableptr = bitcast i8* %obj to [1 x i8*]**
16 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
17 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
18 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
19 call void @llvm.assume(i1 %p)
20 %fptrptr = getelementptr i8, i8* %vtablei8, i32 1
21 %fptrptr_casted = bitcast i8* %fptrptr to i8**
22 %fptr = load i8*, i8** %fptrptr_casted
23 %fptr_casted = bitcast i8* %fptr to void (i8*)*
25 call void %fptr_casted(i8* %obj)
29 ; CHECK: define void @unaligned2
30 define void @unaligned2(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 !"typeid2")
35 call void @llvm.assume(i1 %p)
36 %fptrptr = getelementptr i8, i8* %vtablei8, i32 1
37 %fptrptr_casted = bitcast i8* %fptrptr to i8**
38 %fptr = load i8*, i8** %fptrptr_casted
39 %fptr_casted = bitcast i8* %fptr to void (i8*)*
41 call void %fptr_casted(i8* %obj)
45 ; CHECK: define void @outofbounds
46 define void @outofbounds(i8* %obj) {
47 %vtableptr = bitcast i8* %obj to [1 x i8*]**
48 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
49 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
50 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
51 call void @llvm.assume(i1 %p)
52 %fptrptr = getelementptr i8, i8* %vtablei8, i32 16
53 %fptrptr_casted = bitcast i8* %fptrptr to i8**
54 %fptr = load i8*, i8** %fptrptr_casted
55 %fptr_casted = bitcast i8* %fptr to void (i8*)*
57 call void %fptr_casted(i8* %obj)
61 ; CHECK: define void @nonfunction
62 define void @nonfunction(i8* %obj) {
63 %vtableptr = bitcast i8* %obj to [1 x i8*]**
64 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
65 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
66 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
67 call void @llvm.assume(i1 %p)
68 %fptrptr = getelementptr i8, i8* %vtablei8, i32 0
69 %fptrptr_casted = bitcast i8* %fptrptr to i8**
70 %fptr = load i8*, i8** %fptrptr_casted
71 %fptr_casted = bitcast i8* %fptr to void (i8*)*
73 call void %fptr_casted(i8* %obj)
77 declare i1 @llvm.type.test(i8*, metadata)
78 declare void @llvm.assume(i1)
80 !0 = !{i32 0, !"typeid"}
81 !1 = !{i32 0, !"typeid2"}