[cfe-commits] r86225 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/temporaries.cpp
Anders Carlsson
andersca at mac.com
Thu Nov 5 20:11:12 PST 2009
Author: andersca
Date: Thu Nov 5 22:11:09 2009
New Revision: 86225
URL: http://llvm.org/viewvc/llvm-project?rev=86225&view=rev
Log:
If a member initializer create temporaries we need to destroy them. Fixes PR5077.
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/test/CodeGenCXX/temporaries.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=86225&r1=86224&r2=86225&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Thu Nov 5 22:11:09 2009
@@ -1468,10 +1468,17 @@
B != E; ++B) {
CXXBaseOrMemberInitializer *Member = (*B);
+ assert(LiveTemporaries.empty() &&
+ "Should not have any live temporaries at initializer start!");
+
if (Member->isBaseInitializer())
EmitBaseInitializer(*this, ClassDecl, Member, CtorType);
else
EmitMemberInitializer(*this, ClassDecl, Member);
+
+ // Pop any live temporaries that the initializers might have pushed.
+ while (!LiveTemporaries.empty())
+ PopCXXTemporary();
}
if (!CD->getNumBaseOrMemberInitializers() && !CD->isTrivial()) {
Modified: cfe/trunk/test/CodeGenCXX/temporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/temporaries.cpp?rev=86225&r1=86224&r2=86225&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/temporaries.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/temporaries.cpp Thu Nov 5 22:11:09 2009
@@ -115,3 +115,36 @@
// CHECK: call void @_ZN1GD1Ev
a(G());
}
+
+namespace PR5077 {
+
+struct A {
+ A();
+ ~A();
+ int f();
+};
+
+void f();
+int g(const A&);
+
+struct B {
+ int a1;
+ int a2;
+ B();
+};
+
+B::B()
+ // CHECK: call void @_ZN6PR50771AC1Ev
+ // CHECK: call i32 @_ZN6PR50771A1fEv
+ // CHECK: call void @_ZN6PR50771AD1Ev
+ : a1(A().f())
+ // CHECK: call void @_ZN6PR50771AC1Ev
+ // CHECK: call i32 @_ZN6PR50771gERKNS_1AE
+ // CHECK: call void @_ZN6PR50771AD1Ev
+ , a2(g(A()))
+{
+ // CHECK: call void @_ZN6PR50771fEv
+ f();
+}
+
+}
More information about the cfe-commits
mailing list