mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-25 22:12:57 +02:00
6186319c3f
Changing arguments from being passed as fixed to varargs is unsafe, as the ABI may require they be handled differently (stack vs. register, for example). Remove two tests which rely on the bitcast being folded into the direct call, which is exactly the transformation that's unsafe. llvm-svn: 149457
123 lines
3.1 KiB
LLVM
123 lines
3.1 KiB
LLVM
; Ignore stderr, we expect warnings there
|
|
; RUN: opt < %s -instcombine 2> /dev/null -S | FileCheck %s
|
|
|
|
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
|
|
|
|
; Simple case, argument translatable without changing the value
|
|
declare void @test1a(i8*)
|
|
|
|
define void @test1(i32* %A) {
|
|
call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
|
|
ret void
|
|
; CHECK: %1 = bitcast i32* %A to i8*
|
|
; CHECK: call void @test1a(i8* %1)
|
|
; CHECK: ret void
|
|
}
|
|
|
|
; More complex case, translate argument because of resolution. This is safe
|
|
; because we have the body of the function
|
|
define void @test2a(i8 %A) {
|
|
ret void
|
|
; CHECK: ret void
|
|
}
|
|
|
|
define i32 @test2(i32 %A) {
|
|
call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
|
|
ret i32 %A
|
|
; CHECK: %1 = trunc i32 %A to i8
|
|
; CHECK: call void @test2a(i8 %1)
|
|
; CHECK: ret i32 %A
|
|
}
|
|
|
|
|
|
; test conversion of return value...
|
|
define i8 @test4a() {
|
|
ret i8 0
|
|
; CHECK: ret i8 0
|
|
}
|
|
|
|
define i32 @test4() {
|
|
%X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( ) ; <i32> [#uses=1]
|
|
ret i32 %X
|
|
; CHECK: %X = call i8 @test4a()
|
|
; CHECK: %1 = zext i8 %X to i32
|
|
; CHECK: ret i32 %1
|
|
}
|
|
|
|
|
|
; test conversion of return value... no value conversion occurs so we can do
|
|
; this with just a prototype...
|
|
declare i32 @test5a()
|
|
|
|
define i32 @test5() {
|
|
%X = call i32 @test5a( ) ; <i32> [#uses=1]
|
|
ret i32 %X
|
|
; CHECK: %X = call i32 @test5a()
|
|
; CHECK: ret i32 %X
|
|
}
|
|
|
|
|
|
; test addition of new arguments...
|
|
declare i32 @test6a(i32)
|
|
|
|
define i32 @test6() {
|
|
%X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( )
|
|
ret i32 %X
|
|
; CHECK: %X = call i32 @test6a(i32 0)
|
|
; CHECK: ret i32 %X
|
|
}
|
|
|
|
|
|
; test removal of arguments, only can happen with a function body
|
|
define void @test7a() {
|
|
ret void
|
|
; CHECK: ret void
|
|
}
|
|
|
|
define void @test7() {
|
|
call void bitcast (void ()* @test7a to void (i32)*)( i32 5 )
|
|
ret void
|
|
; CHECK: call void @test7a()
|
|
; CHECK: ret void
|
|
}
|
|
|
|
|
|
; rdar://7590304
|
|
declare void @test8a()
|
|
|
|
define i8* @test8() {
|
|
invoke void @test8a()
|
|
to label %invoke.cont unwind label %try.handler
|
|
|
|
invoke.cont: ; preds = %entry
|
|
unreachable
|
|
|
|
try.handler: ; preds = %entry
|
|
%exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
|
|
cleanup
|
|
ret i8* null
|
|
}
|
|
|
|
declare i32 @__gxx_personality_v0(...)
|
|
|
|
; Don't turn this into "unreachable": the callee and caller don't agree in
|
|
; calling conv, but the implementation of test8a may actually end up using the
|
|
; right calling conv.
|
|
; CHECK: @test8() {
|
|
; CHECK-NEXT: invoke void @test8a()
|
|
|
|
|
|
|
|
; Don't turn this into a direct call, because test9x is just a prototype and
|
|
; doing so will make it varargs.
|
|
; rdar://9038601
|
|
declare i8* @test9x(i8*, i8*, ...) noredzone
|
|
define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
|
|
entry:
|
|
%call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
|
|
ret i8* %call
|
|
; CHECK: @test9(
|
|
; CHECK: call i8* bitcast
|
|
}
|
|
|