[cfe-commits] r134045 - in /cfe/trunk: include/clang/Basic/LangOptions.h include/clang/Driver/CC1Options.td include/clang/Driver/Options.td lib/CodeGen/CGBlocks.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/reset-local

Eli Friedman eli.friedman at gmail.com
Tue Jun 28 18:03:14 PDT 2011


On Tue, Jun 28, 2011 at 5:40 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
>
> On Jun 28, 2011, at 5:14 PM, Eli Friedman wrote:
>
>> On Tue, Jun 28, 2011 at 4:51 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
>>> Author: fjahanian
>>> Date: Tue Jun 28 18:51:26 2011
>>> New Revision: 134045
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=134045&view=rev
>>> Log:
>>> Under a compiler flag, -freset-local-blocks,
>>> wipe out stack blocks when they go out of scope.
>>> // rdar://9227352
>>>
>>> Added:
>>>    cfe/trunk/test/CodeGen/reset-local-block.c
>>>
>>
>> I'm not sure this bit of code works correctly in the presence of
>> goto's... I was doing something sort of similar in rdar://9421018 and
>> ran into issues.
>
> This doesn't have to work perfectly. It is for debugging only and may only be
> used with a compiler option. But we use the infrastructure in other places too,
> so it may be a problem when we depend on this feature working perfectly.

The issue in question only comes up when you have a cleanup for an
unprotected scope (scopes you can "goto" into), which don't exist
normally.  And you might care if the compiler crashes. :)

For reference, attaching my really ugly scope hack which makes
cleanups for unprotected scopes not crash in the presence of goto's.

-Eli
-------------- next part --------------
Index: lib/CodeGen/CGCleanup.cpp
===================================================================
--- lib/CodeGen/CGCleanup.cpp	(revision 131903)
+++ lib/CodeGen/CGCleanup.cpp	(working copy)
@@ -156,7 +156,7 @@
   return Scope->getCleanupBuffer();
 }
 
-void EHScopeStack::popCleanup() {
+void EHScopeStack::popCleanup(CodeGenFunction &CGF) {
   assert(!empty() && "popping exception stack when not empty");
 
   assert(isa<EHCleanupScope>(*begin()));
@@ -181,6 +181,11 @@
     else
       popNullFixups();
   }
+
+  for (llvm::DenseMap<const LabelDecl*, CodeGenFunction::JumpDest>::iterator I = CGF.LabelMap.begin(), E = CGF.LabelMap.end(); I != E; ++I) {
+    if (stable_begin().encloses(I->second.ScopeDepth))
+      I->second.ScopeDepth = stable_begin();
+  }
 }
 
 EHFilterScope *EHScopeStack::pushFilter(unsigned NumFilters) {
@@ -571,7 +576,7 @@
 
   // If we don't need the cleanup at all, we're done.
   if (!RequiresNormalCleanup && !RequiresEHCleanup) {
-    EHStack.popCleanup(); // safe because there are no fixups
+    EHStack.popCleanup(*this); // safe because there are no fixups
     assert(EHStack.getNumBranchFixups() == 0 ||
            EHStack.hasNormalCleanups());
     return;
@@ -645,7 +650,7 @@
   }
 
   if (!RequiresNormalCleanup) {
-    EHStack.popCleanup();
+    EHStack.popCleanup(*this);
   } else {
     // If we have a fallthrough and no other need for the cleanup,
     // emit it directly.
@@ -661,7 +666,7 @@
         delete Scope.getNormalBlock();
       }
 
-      EHStack.popCleanup();
+      EHStack.popCleanup(*this);
 
       EmitCleanup(*this, Fn, /*ForEH*/ false, NormalActiveFlag);
 
@@ -771,7 +776,7 @@
       }
 
       // IV.  Pop the cleanup and emit it.
-      EHStack.popCleanup();
+      EHStack.popCleanup(*this);
       assert(EHStack.hasNormalCleanups() == HasEnclosingCleanups);
 
       EmitCleanup(*this, Fn, /*ForEH*/ false, NormalActiveFlag);
Index: lib/CodeGen/CodeGenFunction.h
===================================================================
--- lib/CodeGen/CodeGenFunction.h	(revision 131903)
+++ lib/CodeGen/CodeGenFunction.h	(working copy)
@@ -387,7 +387,7 @@
 
   /// Pops a cleanup scope off the stack.  This should only be called
   /// by CodeGenFunction::PopCleanupBlock.
-  void popCleanup();
+  void popCleanup(CodeGenFunction &CGF);
 
   /// Push a set of catch handlers on the stack.  The catch is
   /// uninitialized and will need to have the given number of handlers
@@ -524,7 +524,7 @@
     EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; }
     unsigned getDestIndex() const { return Index; }
 
-  private:
+  //private:
     llvm::BasicBlock *Block;
     EHScopeStack::stable_iterator ScopeDepth;
     unsigned Index;
@@ -962,9 +962,10 @@
   typedef llvm::DenseMap<const Decl*, llvm::Value*> DeclMapTy;
   DeclMapTy LocalDeclMap;
 
+public:
   /// LabelMap - This keeps track of the LLVM basic block for each C label.
   llvm::DenseMap<const LabelDecl*, JumpDest> LabelMap;
-
+private:
   // BreakContinueStack - This keeps track of where break and continue
   // statements should jump to.
   struct BreakContinue {


More information about the cfe-commits mailing list