• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 (i1 (i8*)* @vf0 to i8*)], !type !0
7@vt2 = constant [1 x i8*] [i8* bitcast (i1 (i8*)* @vf0 to i8*)], !type !0, !type !1
8@vt3 = constant [1 x i8*] [i8* bitcast (i1 (i8*)* @vf1 to i8*)], !type !0, !type !1
9@vt4 = constant [1 x i8*] [i8* bitcast (i1 (i8*)* @vf1 to i8*)], !type !1
10
11define i1 @vf0(i8* %this) readnone {
12  ret i1 0
13}
14
15define i1 @vf1(i8* %this) readnone {
16  ret i1 1
17}
18
19; CHECK: define i1 @call1
20define i1 @call1(i8* %obj) {
21  %vtableptr = bitcast i8* %obj to [1 x i8*]**
22  %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
23  ; CHECK: [[VT1:%[^ ]*]] = bitcast [1 x i8*]* {{.*}} to i8*
24  %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
25  %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid1")
26  call void @llvm.assume(i1 %p)
27  %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
28  %fptr = load i8*, i8** %fptrptr
29  %fptr_casted = bitcast i8* %fptr to i1 (i8*)*
30  ; CHECK: [[RES1:%[^ ]*]] = icmp eq i8* [[VT1]], bitcast ([1 x i8*]* @vt3 to i8*)
31  %result = call i1 %fptr_casted(i8* %obj)
32  ; CHECK: ret i1 [[RES1]]
33  ret i1 %result
34}
35
36; CHECK: define i1 @call2
37define i1 @call2(i8* %obj) {
38  %vtableptr = bitcast i8* %obj to [1 x i8*]**
39  %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
40  ; CHECK: [[VT2:%[^ ]*]] = bitcast [1 x i8*]* {{.*}} to i8*
41  %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
42  %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid2")
43  call void @llvm.assume(i1 %p)
44  %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
45  %fptr = load i8*, i8** %fptrptr
46  %fptr_casted = bitcast i8* %fptr to i1 (i8*)*
47  ; CHECK: [[RES1:%[^ ]*]] = icmp ne i8* [[VT1]], bitcast ([1 x i8*]* @vt2 to i8*)
48  %result = call i1 %fptr_casted(i8* %obj)
49  ret i1 %result
50}
51
52declare i1 @llvm.type.test(i8*, metadata)
53declare void @llvm.assume(i1)
54
55!0 = !{i32 0, !"typeid1"}
56!1 = !{i32 0, !"typeid2"}
57