1 ; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
3 ; Test that we correctly handle function type mismatches in argument counts
4 ; and bitwidths. We handle an argument count mismatch by refusing
5 ; to optimize. For bitwidth mismatches, we allow the optimization in order
6 ; to simplify the implementation. This is legal because the bitwidth mismatch
7 ; gives the call undefined behavior.
9 target datalayout = "e-p:64:64"
10 target triple = "x86_64-unknown-linux-gnu"
12 @vt1 = constant [1 x i8*] [i8* bitcast (i32 (i8*, i32)* @vf1 to i8*)], !type !0
13 @vt2 = constant [1 x i8*] [i8* bitcast (i32 (i8*, i32)* @vf2 to i8*)], !type !0
15 define i32 @vf1(i8* %this, i32 %arg) readnone {
19 define i32 @vf2(i8* %this, i32 %arg) readnone {
23 ; CHECK: define i32 @bad_arg_type
24 define i32 @bad_arg_type(i8* %obj) {
25 %vtableptr = bitcast i8* %obj to [1 x i8*]**
26 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
27 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
28 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
29 call void @llvm.assume(i1 %p)
30 %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
31 %fptr = load i8*, i8** %fptrptr
32 %fptr_casted = bitcast i8* %fptr to i32 (i8*, i64)*
33 %result = call i32 %fptr_casted(i8* %obj, i64 1)
38 ; CHECK: define i32 @bad_arg_count
39 define i32 @bad_arg_count(i8* %obj) {
40 %vtableptr = bitcast i8* %obj to [1 x i8*]**
41 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
42 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
43 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
44 call void @llvm.assume(i1 %p)
45 %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
46 %fptr = load i8*, i8** %fptrptr
47 %fptr_casted = bitcast i8* %fptr to i32 (i8*, i64, i64)*
49 %result = call i32 %fptr_casted(i8* %obj, i64 1, i64 2)
53 ; CHECK: define i64 @bad_return_type
54 define i64 @bad_return_type(i8* %obj) {
55 %vtableptr = bitcast i8* %obj to [1 x i8*]**
56 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
57 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
58 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
59 call void @llvm.assume(i1 %p)
60 %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
61 %fptr = load i8*, i8** %fptrptr
62 %fptr_casted = bitcast i8* %fptr to i64 (i8*, i32)*
63 %result = call i64 %fptr_casted(i8* %obj, i32 1)
68 declare i1 @llvm.type.test(i8*, metadata)
69 declare void @llvm.assume(i1)
71 !0 = !{i32 0, !"typeid"}