aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp
diff options
context:
space:
mode:
authorJacob Gravelle <jgravelle@google.com>2017-10-10 16:20:18 +0000
committerJacob Gravelle <jgravelle@google.com>2017-10-10 16:20:18 +0000
commit37af00e7d0febf397472c40c3b0df5e6ded7688c (patch)
tree58af5f5c4f3500084f44b4a7eb9295bc338d2bde /llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp
parent98a1fd7f96cdabfff1c0b9b5448423f3cf2ac1d5 (diff)
downloadllvm-37af00e7d0febf397472c40c3b0df5e6ded7688c.zip
llvm-37af00e7d0febf397472c40c3b0df5e6ded7688c.tar.gz
llvm-37af00e7d0febf397472c40c3b0df5e6ded7688c.tar.bz2
[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
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp12
1 files changed, 11 insertions, 1 deletions
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<BitCastOperator>(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<Constant>(U.get())) {
// Only add constant bitcasts to the list once; they get RAUW'd
auto c = ConstantBCs.insert(cast<Constant>(U.get()));
- if (!c.second) continue;
+ if (!c.second)
+ continue;
}
Uses.push_back(std::make_pair(&U, &F));
}