From: Anders Carlsson Date: Tue, 2 Feb 2010 19:58:43 +0000 (+0000) Subject: Set the correct vtable pointers _before_ generating code for any member initializers... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a78fa2c40fbbe505485e7d120dc68a292ee0c968;p=clang Set the correct vtable pointers _before_ generating code for any member initializers. Fixes about ~2000 clang/LLVM tests in the clang-on-clang build. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95116 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index 01b3934c4c..8362945e1e 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -861,6 +861,8 @@ static void EmitMemberInitializer(CodeGenFunction &CGF, void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType CtorType) { const CXXRecordDecl *ClassDecl = CD->getParent(); + + llvm::SmallVector MemberInitializers; // FIXME: Add vbase initialization @@ -875,14 +877,17 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD, 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(); + MemberInitializers.push_back(Member); } InitializeVtablePtrs(ClassDecl); + + for (unsigned I = 0, E = MemberInitializers.size(); I != E; ++I) { + assert(LiveTemporaries.empty() && + "Should not have any live temporaries at initializer start!"); + + EmitMemberInitializer(*this, ClassDecl, MemberInitializers[I]); + } } /// EmitDtorEpilogue - Emit all code that comes at the end of class's diff --git a/test/CodeGenCXX/member-initializers.cpp b/test/CodeGenCXX/member-initializers.cpp new file mode 100644 index 0000000000..1a27b7d202 --- /dev/null +++ b/test/CodeGenCXX/member-initializers.cpp @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 -O3 | FileCheck %s + +struct A { + virtual int f() { return 1; } +}; + +struct B : A { + B() : i(f()) { } + + virtual int f() { return 2; } + + int i; +}; + +// CHECK: define i32 @_Z1fv() nounwind +int f() { + B b; + + // CHECK: call i32 @_ZN1B1fEv + return b.i; +} +