[cfe-commits] r99865 - in /cfe/trunk/lib/CodeGen: CGClass.cpp CGTemporaries.cpp CodeGenFunction.h
Anders Carlsson
andersca at mac.com
Mon Mar 29 20:14:41 PDT 2010
Author: andersca
Date: Mon Mar 29 22:14:41 2010
New Revision: 99865
URL: http://llvm.org/viewvc/llvm-project?rev=99865&view=rev
Log:
Introduce a CXXTemporariesCleanupScope RAII object and use it to cleanup the temporaries code.
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGTemporaries.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=99865&r1=99864&r2=99865&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Mar 29 22:14:41 2010
@@ -550,29 +550,27 @@
CallArgs.push_back(std::make_pair(RValue::get(Src),
BaseCopyCtor->getParamDecl(0)->getType()));
- unsigned OldNumLiveTemporaries = LiveTemporaries.size();
+ {
+ CXXTemporariesCleanupScope Scope(*this);
- // If the copy constructor has default arguments, emit them.
- for (unsigned I = 1, E = BaseCopyCtor->getNumParams(); I < E; ++I) {
- const ParmVarDecl *Param = BaseCopyCtor->getParamDecl(I);
- const Expr *DefaultArgExpr = Param->getDefaultArg();
-
- assert(DefaultArgExpr && "Ctor parameter must have default arg!");
+ // If the copy constructor has default arguments, emit them.
+ for (unsigned I = 1, E = BaseCopyCtor->getNumParams(); I < E; ++I) {
+ const ParmVarDecl *Param = BaseCopyCtor->getParamDecl(I);
+ const Expr *DefaultArgExpr = Param->getDefaultArg();
+
+ assert(DefaultArgExpr && "Ctor parameter must have default arg!");
+
+ QualType ArgType = Param->getType();
+ CallArgs.push_back(std::make_pair(EmitCallArg(DefaultArgExpr, ArgType),
+ ArgType));
- QualType ArgType = Param->getType();
- CallArgs.push_back(std::make_pair(EmitCallArg(DefaultArgExpr, ArgType),
- ArgType));
+ }
+ const FunctionProtoType *FPT =
+ BaseCopyCtor->getType()->getAs<FunctionProtoType>();
+ EmitCall(CGM.getTypes().getFunctionInfo(CallArgs, FPT),
+ Callee, ReturnValueSlot(), CallArgs, BaseCopyCtor);
}
-
- const FunctionProtoType *FPT =
- BaseCopyCtor->getType()->getAs<FunctionProtoType>();
- EmitCall(CGM.getTypes().getFunctionInfo(CallArgs, FPT),
- Callee, ReturnValueSlot(), CallArgs, BaseCopyCtor);
-
- // Pop temporaries.
- while (LiveTemporaries.size() > OldNumLiveTemporaries)
- PopCXXTemporary();
}
}
@@ -1306,14 +1304,12 @@
// before the construction of the next array element, if any.
// Keep track of the current number of live temporaries.
- unsigned OldNumLiveTemporaries = LiveTemporaries.size();
+ {
+ CXXTemporariesCleanupScope Scope(*this);
- EmitCXXConstructorCall(D, Ctor_Complete, Address, ArgBeg, ArgEnd);
+ EmitCXXConstructorCall(D, Ctor_Complete, Address, ArgBeg, ArgEnd);
+ }
- // Pop temporaries.
- while (LiveTemporaries.size() > OldNumLiveTemporaries)
- PopCXXTemporary();
-
EmitBlock(ContinueBlock);
// Emit the increment of the loop counter.
Modified: cfe/trunk/lib/CodeGen/CGTemporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGTemporaries.cpp?rev=99865&r1=99864&r2=99865&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGTemporaries.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGTemporaries.cpp Mon Mar 29 22:14:41 2010
@@ -127,15 +127,14 @@
size_t CleanupStackDepth = CleanupEntries.size();
(void) CleanupStackDepth;
- unsigned OldNumLiveTemporaries = LiveTemporaries.size();
-
- RValue RV = EmitAnyExpr(E->getSubExpr(), AggLoc, IsAggLocVolatile,
- /*IgnoreResult=*/false, IsInitializer);
-
- // Pop temporaries.
- while (LiveTemporaries.size() > OldNumLiveTemporaries)
- PopCXXTemporary();
-
+ RValue RV;
+
+ {
+ CXXTemporariesCleanupScope Scope(*this);
+
+ RV = EmitAnyExpr(E->getSubExpr(), AggLoc, IsAggLocVolatile,
+ /*IgnoreResult=*/false, IsInitializer);
+ }
assert(CleanupEntries.size() == CleanupStackDepth &&
"Cleanup size mismatch!");
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=99865&r1=99864&r2=99865&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Mon Mar 29 22:14:41 2010
@@ -254,6 +254,27 @@
}
};
+ /// CXXTemporariesCleanupScope - Enters a new scope for catching live
+ /// temporaries, all of which will be popped once the scope is exited.
+ class CXXTemporariesCleanupScope {
+ CodeGenFunction &CGF;
+ size_t NumLiveTemporaries;
+
+ // DO NOT IMPLEMENT
+ CXXTemporariesCleanupScope(const CXXTemporariesCleanupScope &);
+ CXXTemporariesCleanupScope &operator=(const CXXTemporariesCleanupScope &);
+
+ public:
+ explicit CXXTemporariesCleanupScope(CodeGenFunction &CGF)
+ : CGF(CGF), NumLiveTemporaries(CGF.LiveTemporaries.size()) { }
+
+ ~CXXTemporariesCleanupScope() {
+ while (CGF.LiveTemporaries.size() > NumLiveTemporaries)
+ CGF.PopCXXTemporary();
+ }
+ };
+
+
/// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup
/// blocks that have been added.
void EmitCleanupBlocks(size_t OldCleanupStackSize);
More information about the cfe-commits
mailing list