[cfe-commits] r114259 - in /cfe/trunk/lib/CodeGen: CodeGenFunction.cpp CodeGenFunction.h

John McCall rjmccall at apple.com
Fri Sep 17 19:24:39 PDT 2010


Author: rjmccall
Date: Fri Sep 17 21:24:39 2010
New Revision: 114259

URL: http://llvm.org/viewvc/llvm-project?rev=114259&view=rev
Log:
Adjust a fixup's starting branch if it's being resolved because
it reached the outermost scope and it hasn't yet been forwarded
to a cleanup.  Fixed PR8175.


Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=114259&r1=114258&r2=114259&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Fri Sep 17 21:24:39 2010
@@ -28,6 +28,10 @@
 using namespace clang;
 using namespace CodeGen;
 
+static void ResolveAllBranchFixups(CodeGenFunction &CGF,
+                                   llvm::SwitchInst *Switch,
+                                   llvm::BasicBlock *CleanupEntry);
+
 CodeGenFunction::CodeGenFunction(CodeGenModule &cgm)
   : BlockFunction(cgm, *this, Builder), CGM(cgm),
     Target(CGM.getContext().Target),
@@ -1075,8 +1079,10 @@
                           Scope.getBranchAfterBlock(I));
         }
 
+        // If there aren't any enclosing cleanups, we can resolve all
+        // the fixups now.
         if (HasFixups && !HasEnclosingCleanups)
-          ResolveAllBranchFixups(Switch);
+          ResolveAllBranchFixups(*this, Switch, NormalEntry);
       } else {
         // We should always have a branch-through destination in this case.
         assert(BranchThroughDest);
@@ -1325,21 +1331,38 @@
 /// All the branch fixups on the EH stack have propagated out past the
 /// outermost normal cleanup; resolve them all by adding cases to the
 /// given switch instruction.
-void CodeGenFunction::ResolveAllBranchFixups(llvm::SwitchInst *Switch) {
+static void ResolveAllBranchFixups(CodeGenFunction &CGF,
+                                   llvm::SwitchInst *Switch,
+                                   llvm::BasicBlock *CleanupEntry) {
   llvm::SmallPtrSet<llvm::BasicBlock*, 4> CasesAdded;
 
-  for (unsigned I = 0, E = EHStack.getNumBranchFixups(); I != E; ++I) {
+  for (unsigned I = 0, E = CGF.EHStack.getNumBranchFixups(); I != E; ++I) {
     // Skip this fixup if its destination isn't set or if we've
     // already treated it.
-    BranchFixup &Fixup = EHStack.getBranchFixup(I);
+    BranchFixup &Fixup = CGF.EHStack.getBranchFixup(I);
     if (Fixup.Destination == 0) continue;
     if (!CasesAdded.insert(Fixup.Destination)) continue;
 
-    Switch->addCase(Builder.getInt32(Fixup.DestinationIndex),
+    // If there isn't an OptimisticBranchBlock, then InitialBranch is
+    // still pointing directly to its destination; forward it to the
+    // appropriate cleanup entry.  This is required in the specific
+    // case of
+    //   { std::string s; goto lbl; }
+    //   lbl:
+    // i.e. where there's an unresolved fixup inside a single cleanup
+    // entry which we're currently popping.
+    if (Fixup.OptimisticBranchBlock == 0) {
+      new llvm::StoreInst(CGF.Builder.getInt32(Fixup.DestinationIndex),
+                          CGF.getNormalCleanupDestSlot(),
+                          Fixup.InitialBranch);
+      Fixup.InitialBranch->setSuccessor(0, CleanupEntry);
+    }
+
+    Switch->addCase(CGF.Builder.getInt32(Fixup.DestinationIndex),
                     Fixup.Destination);
   }
 
-  EHStack.clearFixups();
+  CGF.EHStack.clearFixups();
 }
 
 void CodeGenFunction::ResolveBranchFixups(llvm::BasicBlock *Block) {

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=114259&r1=114258&r2=114259&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Sep 17 21:24:39 2010
@@ -414,7 +414,7 @@
   void popNullFixups();
 
   /// Clears the branch-fixups list.  This should only be called by
-  /// CodeGenFunction::ResolveAllBranchFixups.
+  /// ResolveAllBranchFixups.
   void clearFixups() { BranchFixups.clear(); }
 
   /// Gets the next EH destination index.
@@ -625,7 +625,6 @@
   /// the cleanup blocks that have been added.
   void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize);
 
-  void ResolveAllBranchFixups(llvm::SwitchInst *Switch);
   void ResolveBranchFixups(llvm::BasicBlock *Target);
 
   /// The given basic block lies in the current EH scope, but may be a





More information about the cfe-commits mailing list