From 37af00e7d0febf397472c40c3b0df5e6ded7688c Mon Sep 17 00:00:00 2001 From: Jacob Gravelle Date: Tue, 10 Oct 2017 16:20:18 +0000 Subject: [WebAssembly] Narrow the scope of WebAssemblyFixFunctionBitcasts Summary: The pass to fix function bitcasts generates thunks for functions that are called directly with a mismatching signature. It was also generating thunks in cases where the function was address-taken, causing aliasing problems in otherwise valid cases. This patch tightens the restrictions for when the pass runs. Reviewers: sunfish, dschuff Subscribers: jfb, sbc100, llvm-commits, aheejin Differential Revision: https://reviews.llvm.org/D38640 llvm-svn: 315326 --- .../Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp') diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp index 76a2ff3..19df75c 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp @@ -24,6 +24,7 @@ //===----------------------------------------------------------------------===// #include "WebAssembly.h" +#include "llvm/IR/CallSite.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" @@ -68,10 +69,19 @@ static void FindUses(Value *V, Function &F, if (BitCastOperator *BC = dyn_cast(U.getUser())) FindUses(BC, F, Uses, ConstantBCs); else if (U.get()->getType() != F.getType()) { + CallSite CS(U.getUser()); + if (!CS) + // Skip uses that aren't immediately called + continue; + Value *Callee = CS.getCalledValue(); + if (Callee != V) + // Skip calls where the function isn't the callee + continue; if (isa(U.get())) { // Only add constant bitcasts to the list once; they get RAUW'd auto c = ConstantBCs.insert(cast(U.get())); - if (!c.second) continue; + if (!c.second) + continue; } Uses.push_back(std::make_pair(&U, &F)); } -- cgit v1.1