[cfe-commits] r90357 - /cfe/trunk/lib/CodeGen/CGException.cpp

Mike Stump mrs at apple.com
Wed Dec 2 15:37:17 PST 2009


Author: mrs
Date: Wed Dec  2 17:37:16 2009
New Revision: 90357

URL: http://llvm.org/viewvc/llvm-project?rev=90357&view=rev
Log:
Add a cleanup scope for each catch clause.

Modified:
    cfe/trunk/lib/CodeGen/CGException.cpp

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=90357&r1=90356&r2=90357&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Wed Dec  2 17:37:16 2009
@@ -381,29 +381,33 @@
 
     llvm::Value *ExcObject = Builder.CreateCall(getBeginCatchFn(*this), Exc);
 
-    // Bind the catch parameter if it exists.
-    if (CatchParam) {
-      QualType CatchType = CatchParam->getType().getNonReferenceType();
-      setInvokeDest(TerminateHandler);
-      if (!CatchType.getTypePtr()->isPointerType())
-        CatchType = getContext().getPointerType(CatchType);
-      ExcObject =
-        Builder.CreateBitCast(ExcObject, ConvertType(CatchType));
+    {
+      CleanupScope CatchScope(*this);
+      // Bind the catch parameter if it exists.
+      if (CatchParam) {
+        QualType CatchType = CatchParam->getType().getNonReferenceType();
+        setInvokeDest(TerminateHandler);
+        if (!CatchType.getTypePtr()->isPointerType())
+          CatchType = getContext().getPointerType(CatchType);
+        ExcObject = Builder.CreateBitCast(ExcObject, ConvertType(CatchType));
         // CatchParam is a ParmVarDecl because of the grammar
         // construction used to handle this, but for codegen purposes
         // we treat this as a local decl.
-      EmitLocalBlockVarDecl(*CatchParam);
+        EmitLocalBlockVarDecl(*CatchParam);
 #if 0
-      // FIXME: objects with ctors, references
-      Builder.CreateStore(ExcObject, GetAddrOfLocalVar(CatchParam));
+        // FIXME: objects with ctors, references
+        Builder.CreateStore(ExcObject, GetAddrOfLocalVar(CatchParam));
 #else
-      CopyObject(*this, CatchParam->getType().getNonReferenceType(),
-                 ExcObject, GetAddrOfLocalVar(CatchParam));
+        // FIXME: we need to do this sooner so that the EH region for the cleanup doesn't start until after the ctor completes, use a decl init?
+        CopyObject(*this, CatchParam->getType().getNonReferenceType(),
+                   ExcObject, GetAddrOfLocalVar(CatchParam));
 #endif
-      setInvokeDest(MatchHandler);
+        setInvokeDest(MatchHandler);
+      }
+
+      EmitStmt(CatchBody);
     }
 
-    EmitStmt(CatchBody);
     EmitBranchThroughCleanup(FinallyEnd);
 
     EmitBlock(MatchHandler);





More information about the cfe-commits mailing list