Skip to content

Commit 6028c96

Browse files
committed
[WebAssembly] Don't error on conflicting uses of prototype-less functions
When we can't determine with certainty the signature of a function import we pick the fist signature we find rather than error'ing out. The resulting program might not do what is expected since we might pick the wrong signature. However since undefined behavior in C to use the same function with different signatures this seems better than refusing to compile such programs. Fixes PR40472 Differential Revision: https://reviews.llvm.org/D58304 llvm-svn: 354523
1 parent 65e9f98 commit 6028c96

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,24 @@ bool WebAssemblyAddMissingPrototypes::runOnModule(Module &M) {
8989
Function *NewF = nullptr;
9090
for (Use &U : F.uses()) {
9191
LLVM_DEBUG(dbgs() << "prototype-less use: " << F.getName() << "\n");
92+
LLVM_DEBUG(dbgs() << *U.getUser() << "\n");
9293
if (auto *BC = dyn_cast<BitCastOperator>(U.getUser())) {
9394
if (auto *DestType = dyn_cast<FunctionType>(
9495
BC->getDestTy()->getPointerElementType())) {
9596
if (!NewType) {
9697
// Create a new function with the correct type
9798
NewType = DestType;
99+
LLVM_DEBUG(dbgs() << "found function type: " << *NewType << "\n");
98100
NewF = Function::Create(NewType, F.getLinkage(), F.getName() + ".fixed_sig");
99101
NewF->setAttributes(F.getAttributes());
100102
NewF->removeFnAttr("no-prototype");
101103
Replacements.emplace_back(&F, NewF);
102-
} else {
103-
if (NewType != DestType) {
104-
report_fatal_error("Prototypeless function used with "
105-
"conflicting signatures: " +
106-
F.getName());
107-
}
104+
} else if (NewType != DestType) {
105+
errs() << "warning: prototype-less function used with "
106+
"conflicting signatures: "
107+
<< F.getName() << "\n";
108+
LLVM_DEBUG(dbgs() << " " << *DestType << "\n");
109+
LLVM_DEBUG(dbgs() << " "<< *NewType << "\n");
108110
}
109111
}
110112
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: opt -S -wasm-add-missing-prototypes -o %t.ll %s 2>&1 | FileCheck %s -check-prefix=WARNING
2+
; RUN: cat %t.ll | FileCheck %s
3+
4+
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
5+
target triple = "wasm32-unknown-unknown"
6+
7+
; WARNING: warning: prototype-less function used with conflicting signatures: foo
8+
9+
; CHECK-LABEL: @call_with_conflicting_prototypes
10+
; CHECK: %call1 = call i64 bitcast (i64 (i32, i32)* @foo to i64 (i32)*)(i32 42)
11+
; CHECK: %call2 = call i64 @foo(i32 42, i32 43)
12+
define void @call_with_conflicting_prototypes() {
13+
%call1 = call i64 bitcast (i64 (...)* @foo to i64 (i32)*)(i32 42)
14+
%call2 = call i64 bitcast (i64 (...)* @foo to i64 (i32, i32)*)(i32 42, i32 43)
15+
ret void
16+
}
17+
18+
; CHECK: declare extern_weak i64 @foo(i32, i32)
19+
declare extern_weak i64 @foo(...) #1
20+
21+
; CHECK-NOT: attributes {{.*}} = { {{.*}}"no-prototype"{{.*}} }
22+
attributes #1 = { "no-prototype" }

0 commit comments

Comments
 (0)