// - Call with fewer arguments than needed: arguments are filled in with undef
// - Return value is not needed: drop it
// - Return value needed but not present: supply an undef
+//
+// For now, return nullptr without creating a wrapper if the wrapper cannot
+// be generated due to incompatible types.
static Function *CreateWrapper(Function *F, FunctionType *Ty) {
Module *M = F->getParent();
FunctionType::param_iterator PI = F->getFunctionType()->param_begin();
FunctionType::param_iterator PE = F->getFunctionType()->param_end();
for (; AI != Wrapper->arg_end() && PI != PE; ++AI, ++PI) {
- assert(AI->getType() == *PI &&
- "mismatched argument types not supported yet");
+ if (AI->getType() != *PI) {
+ Wrapper->eraseFromParent();
+ return nullptr;
+ }
Args.push_back(&*AI);
}
for (; PI != PE; ++PI)
BB);
else if (F->getFunctionType()->getReturnType() == Ty->getReturnType())
ReturnInst::Create(M->getContext(), Call, BB);
- else
- llvm_unreachable("mismatched return types not supported yet");
+ else {
+ Wrapper->eraseFromParent();
+ return nullptr;
+ }
return Wrapper;
}
if (Pair.second)
Pair.first->second = CreateWrapper(F, Ty);
+ Function *Wrapper = Pair.first->second;
+ if (!Wrapper)
+ continue;
+
if (isa<Constant>(U->get()))
- U->get()->replaceAllUsesWith(Pair.first->second);
+ U->get()->replaceAllUsesWith(Wrapper);
else
- U->set(Pair.first->second);
+ U->set(Wrapper);
}
return true;
; CHECK-LABEL: test:
; CHECK-NEXT: call .Lbitcast@FUNCTION{{$}}
; CHECK-NEXT: call .Lbitcast.1@FUNCTION{{$}}
-; CHECK-NEXT: i32.const $push[[L0:[0-9]*]]=, 0
+; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 0
; CHECK-NEXT: call .Lbitcast.2@FUNCTION, $pop[[L0]]{{$}}
; CHECK-NEXT: i32.call $drop=, .Lbitcast.3@FUNCTION{{$}}
; CHECK-NEXT: call foo2@FUNCTION{{$}}
--- /dev/null
+; RUN: llc < %s -asm-verbose=false | FileCheck %s
+
+; Test that function pointer casts that require conversions are not converted
+; to wrappers. In theory some conversions could be supported, but currently no
+; conversions are implemented.
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+; CHECK-LABEL: test:
+; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: call has_i64_arg@FUNCTION, $pop[[L0]]{{$}}
+; CHECK-NEXT: i32.call $drop=, has_i64_ret@FUNCTION{{$}}
+; CHECK-NEXT: .endfunc
+
+; CHECK-NOT: .Lbitcast
+
+declare void @has_i64_arg(i64)
+declare i64 @has_i64_ret()
+
+define void @test() {
+entry:
+ call void bitcast (void (i64)* @has_i64_arg to void (i32)*)(i32 0)
+ %t = call i32 bitcast (i64 ()* @has_i64_ret to i32 ()*)()
+ ret void
+}