summaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2011-10-05 20:05:13 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2011-10-05 20:05:13 +0000
commit11f1a8335e207971f66eb60609e16b8719be5450 (patch)
treed9e3c481fd4599da0d3a9c39accba9b51ce5599a /lib/VMCore
parent30c1ff234d30567fc20d6c41d8fd9c3aacbbf9ca (diff)
downloadllvm-11f1a8335e207971f66eb60609e16b8719be5450.tar.gz
llvm-11f1a8335e207971f66eb60609e16b8719be5450.tar.bz2
llvm-11f1a8335e207971f66eb60609e16b8719be5450.tar.xz
Check for the returns_twice attribute in callsFunctionThatReturnsTwice. This
fixes PR11038, but there are still some cleanups to be done. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141204 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Function.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 1f59bf9716..ef0827b110 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -17,6 +17,7 @@
#include "llvm/LLVMContext.h"
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/Support/CallSite.h"
+#include "llvm/Support/InstIterator.h"
#include "llvm/Support/LeakDetector.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/StringPool.h"
@@ -416,7 +417,6 @@ bool Function::hasAddressTaken(const User* *PutOffender) const {
/// FIXME: Remove after <rdar://problem/8031714> is fixed.
/// FIXME: Is the above FIXME valid?
bool Function::callsFunctionThatReturnsTwice() const {
- const Module *M = this->getParent();
static const char *ReturnsTwiceFns[] = {
"_setjmp",
"setjmp",
@@ -428,16 +428,25 @@ bool Function::callsFunctionThatReturnsTwice() const {
"getcontext"
};
- for (unsigned I = 0; I < array_lengthof(ReturnsTwiceFns); ++I)
- if (const Function *Callee = M->getFunction(ReturnsTwiceFns[I])) {
- if (!Callee->use_empty())
- for (Value::const_use_iterator
- I = Callee->use_begin(), E = Callee->use_end();
- I != E; ++I)
- if (const CallInst *CI = dyn_cast<CallInst>(*I))
- if (CI->getParent()->getParent() == this)
- return true;
+ for (const_inst_iterator I = inst_begin(this), E = inst_end(this); I != E;
+ ++I) {
+ const CallInst* callInst = dyn_cast<CallInst>(&*I);
+ if (!callInst)
+ continue;
+ if (callInst->canReturnTwice())
+ return true;
+
+ // check for known function names.
+ // FIXME: move this to clang.
+ Function *F = callInst->getCalledFunction();
+ if (!F)
+ continue;
+ StringRef Name = F->getName();
+ for (unsigned J = 0; J < array_lengthof(ReturnsTwiceFns); ++J) {
+ if (Name == ReturnsTwiceFns[J])
+ return true;
}
+ }
return false;
}