Code clean up.
[oota-llvm.git] / lib / VMCore / Function.cpp
index 4f55098da16adc9c8a0911779ebb873829973b36..575381e03035998128e0fa05b5da2a36fb380384 100644 (file)
@@ -16,6 +16,7 @@
 #include "llvm/IntrinsicInst.h"
 #include "llvm/LLVMContext.h"
 #include "llvm/CodeGen/ValueTypes.h"
+#include "llvm/Support/CallSite.h"
 #include "llvm/Support/LeakDetector.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/StringPool.h"
@@ -402,11 +403,14 @@ Function *Intrinsic::getDeclaration(Module *M, ID id, const Type **Tys,
 
 /// hasAddressTaken - returns true if there are any uses of this function
 /// other than direct calls or invokes to it.
-bool Function::hasAddressTaken() const {
+bool Function::hasAddressTaken(const User* *PutOffender) const {
   for (Value::use_const_iterator I = use_begin(), E = use_end(); I != E; ++I) {
-    if (I.getOperandNo() != 0 ||
-        (!isa<CallInst>(*I) && !isa<InvokeInst>(*I)))
-      return true;
+    const User *U = *I;
+    if (!isa<CallInst>(U) && !isa<InvokeInst>(U))
+      return PutOffender ? (*PutOffender = U, true) : true;
+    CallSite CS(const_cast<Instruction*>(static_cast<const Instruction*>(U)));
+    if (!CS.isCallee(I))
+      return PutOffender ? (*PutOffender = U, true) : true;
   }
   return false;
 }