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 [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 8 9define void @vf(i8* %this) { 10 ret void 11} 12 13; CHECK: define void @unaligned1 14define 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*)* 24 ; CHECK: call void % 25 call void %fptr_casted(i8* %obj) 26 ret void 27} 28 29; CHECK: define void @unaligned2 30define 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*)* 40 ; CHECK: call void % 41 call void %fptr_casted(i8* %obj) 42 ret void 43} 44 45; CHECK: define void @outofbounds 46define 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*)* 56 ; CHECK: call void % 57 call void %fptr_casted(i8* %obj) 58 ret void 59} 60 61; CHECK: define void @nonfunction 62define 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*)* 72 ; CHECK: call void % 73 call void %fptr_casted(i8* %obj) 74 ret void 75} 76 77declare i1 @llvm.type.test(i8*, metadata) 78declare void @llvm.assume(i1) 79 80!0 = !{i32 0, !"typeid"} 81!1 = !{i32 0, !"typeid2"} 82