aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorEli Bendersky <eliben@chromium.org>2013-10-11 10:16:26 -0700
committerEli Bendersky <eliben@chromium.org>2013-10-11 10:16:26 -0700
commite87e8cd648035ac8e2cda19ce0cfd9d9a6e309fb (patch)
treeefa2c12a9699fffc6e5a4ffc64e8a9b1d22ba802 /lib/Transforms
parent1763e0545c0ee2748b6dbf4aaa1b4bb9d20a2ef0 (diff)
Fix bug in rewriting of library calls to intrinsics + new regression test.
The pass gets confused in some cases when library functions get passed to other functions as arguments, because use_iterator returns the call instruction. The existing test (rewrite-longjmp-noncall-uses.ll) did not catch this problem because there a bitcast constexpr was applied to the library function pointer, and it came up as the use instead of the containing call. BUG=https://code.google.com/p/nativeclient/issues/detail?id=3706 R=mseaborn@chromium.org Review URL: https://codereview.chromium.org/26952003
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/NaCl/RewritePNaClLibraryCalls.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Transforms/NaCl/RewritePNaClLibraryCalls.cpp b/lib/Transforms/NaCl/RewritePNaClLibraryCalls.cpp
index a01e8c6b2a..6656a672fe 100644
--- a/lib/Transforms/NaCl/RewritePNaClLibraryCalls.cpp
+++ b/lib/Transforms/NaCl/RewritePNaClLibraryCalls.cpp
@@ -171,9 +171,14 @@ bool RewritePNaClLibraryCalls::RewriteLibraryCall(
for (Value::use_iterator UI = LibFunc->use_begin(),
UE = LibFunc->use_end(); UI != UE;) {
Value *Use = *UI++;
+ // use_iterator will also provide call instructions in which the used
+ // value is an argument, and not the value being called. Make sure we
+ // rewrite only actual calls to LibFunc here.
if (CallInst *Call = dyn_cast<CallInst>(Use)) {
- (this->*(CallRewriter))(Call);
- Changed = true;
+ if (Call->getCalledValue() == LibFunc) {
+ (this->*(CallRewriter))(Call);
+ Changed = true;
+ }
}
}