]> granicus.if.org Git - clang/commitdiff
If a member initializer create temporaries we need to destroy them. Fixes PR5077.
authorAnders Carlsson <andersca@mac.com>
Fri, 6 Nov 2009 04:11:09 +0000 (04:11 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 6 Nov 2009 04:11:09 +0000 (04:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86225 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
test/CodeGenCXX/temporaries.cpp

index 029fdedb5026af0661fdf3eeaac68d3e01f2bd5b..0e6b5cb14341411e4843c68bc44de74d7b84925b 100644 (file)
@@ -1468,10 +1468,17 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD,
        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()) {
index e9ed0f7690bc38dc20555f166973eeedf1dc1d9c..5366612001aa3a74553eb0398273bf452084b95d 100644 (file)
@@ -115,3 +115,36 @@ void f7() {
   // 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();
+}
+  
+}