[llvm-commits] [llvm] r136768 - in /llvm/trunk: lib/VMCore/AsmWriter.cpp test/Transforms/StripSymbols/block-address.ll

Chris Lattner sabre at nondot.org
Tue Aug 2 23:15:41 PDT 2011


Author: lattner
Date: Wed Aug  3 01:15:41 2011
New Revision: 136768

URL: http://llvm.org/viewvc/llvm-project?rev=136768&view=rev
Log:
fix PR10286, a problem with the .ll printer handling block addresses that are out-of-scope.

Added:
    llvm/trunk/test/Transforms/StripSymbols/block-address.ll
Modified:
    llvm/trunk/lib/VMCore/AsmWriter.cpp

Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=136768&r1=136767&r2=136768&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Wed Aug  3 01:15:41 2011
@@ -1037,26 +1037,35 @@
 
   char Prefix = '%';
   int Slot;
+  // If we have a SlotTracker, use it.
   if (Machine) {
     if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
       Slot = Machine->getGlobalSlot(GV);
       Prefix = '@';
     } else {
       Slot = Machine->getLocalSlot(V);
+      
+      // If the local value didn't succeed, then we may be referring to a value
+      // from a different function.  Translate it, as this can happen when using
+      // address of blocks.
+      if (Slot == -1)
+        if ((Machine = createSlotTracker(V))) {
+          Slot = Machine->getLocalSlot(V);
+          delete Machine;
+        }
     }
-  } else {
-    Machine = createSlotTracker(V);
-    if (Machine) {
-      if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
-        Slot = Machine->getGlobalSlot(GV);
-        Prefix = '@';
-      } else {
-        Slot = Machine->getLocalSlot(V);
-      }
-      delete Machine;
+  } else if ((Machine = createSlotTracker(V))) {
+    // Otherwise, create one to get the # and then destroy it.
+    if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
+      Slot = Machine->getGlobalSlot(GV);
+      Prefix = '@';
     } else {
-      Slot = -1;
+      Slot = Machine->getLocalSlot(V);
     }
+    delete Machine;
+    Machine = 0;
+  } else {
+    Slot = -1;
   }
 
   if (Slot != -1)

Added: llvm/trunk/test/Transforms/StripSymbols/block-address.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/StripSymbols/block-address.ll?rev=136768&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/StripSymbols/block-address.ll (added)
+++ llvm/trunk/test/Transforms/StripSymbols/block-address.ll Wed Aug  3 01:15:41 2011
@@ -0,0 +1,23 @@
+; RUN: opt %s -strip -S | FileCheck %s
+; PR10286
+
+ at main_addrs = constant [2 x i8*] [i8* blockaddress(@f, %FOO), i8* blockaddress(@f, %BAR)]
+; CHECK: @main_addrs = constant [2 x i8*] [i8* blockaddress(@f, %2), i8* blockaddress(@f, %3)]
+
+declare void @foo() nounwind
+declare void @bar() nounwind
+
+define void @f(i8* %indirect.goto.dest) nounwind uwtable ssp {
+entry:
+  indirectbr i8* %indirect.goto.dest, [label %FOO, label %BAR]
+
+  ; CHECK: indirectbr i8* %0, [label %2, label %3]
+
+FOO:
+  call void @foo()
+  ret void
+
+BAR:
+  call void @bar()
+  ret void
+}





More information about the llvm-commits mailing list