Introduce a CXXTemporariesCleanupScope RAII object and use it to cleanup the temporaries code.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99865 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp
index 8d565f6..0cf1ac4 100644
--- a/lib/CodeGen/CGClass.cpp
+++ b/lib/CodeGen/CGClass.cpp
@@ -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();
- QualType ArgType = Param->getType();
- CallArgs.push_back(std::make_pair(EmitCallArg(DefaultArgExpr, ArgType),
- ArgType));
+ assert(DefaultArgExpr && "Ctor parameter must have default arg!");
+ 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.