Fix another minor bug, exposed by perlbmk
authorChris Lattner <sabre@nondot.org>
Sun, 7 Mar 2004 22:43:27 +0000 (22:43 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 7 Mar 2004 22:43:27 +0000 (22:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12198 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/ArgumentPromotion.cpp

index 639c518037803f2447c4a0c1d5ff3135ba1a8a06..eb4fc463e699445c8dbb038b6970511d6063ce6d 100644 (file)
@@ -136,10 +136,18 @@ bool ArgPromotion::PromoteArguments(Function *F) {
   // Second check: make sure that all callers are direct callers.  We can't
   // transform functions that have indirect callers.
   for (Value::use_iterator UI = F->use_begin(), E = F->use_end();
-       UI != E; ++UI)
-    // What about CPRs?
-    if (!CallSite::get(*UI).getInstruction())
+       UI != E; ++UI) {
+    CallSite CS = CallSite::get(*UI);
+    if (Instruction *I = CS.getInstruction()) {
+      // Ensure that this call site is CALLING the function, not passing it as
+      // an argument.
+      for (CallSite::arg_iterator AI = CS.arg_begin(), E = CS.arg_end();
+           AI != E; ++AI)
+        if (*AI == F) return false;   // Passing the function address in!
+    } else {
       return false;  // Cannot promote an indirect call!
+    }
+  }
 
   // Check to see which arguments are promotable.  If an argument is not
   // promotable, remove it from the PointerArgs vector.