From: David Majnemer Date: Fri, 13 May 2016 20:05:09 +0000 (+0000) Subject: [MS ABI] Delegating constructors should not assume they are most derived X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=448a26226e94335722b2215b3f8b01220c17d299;p=clang [MS ABI] Delegating constructors should not assume they are most derived A constructor needs to know whether or not it is most derived in order to determine if it is responsible for virtual bases. Delegating constructors assumed they were most derived. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@269465 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/MicrosoftCXXABI.cpp b/lib/CodeGen/MicrosoftCXXABI.cpp index 0e15f5054d..2e41f934a2 100644 --- a/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/lib/CodeGen/MicrosoftCXXABI.cpp @@ -1467,16 +1467,18 @@ unsigned MicrosoftCXXABI::addImplicitConstructorArgs( // Add the 'most_derived' argument second if we are variadic or last if not. const FunctionProtoType *FPT = D->getType()->castAs(); - llvm::Value *MostDerivedArg = - llvm::ConstantInt::get(CGM.Int32Ty, Type == Ctor_Complete); - RValue RV = RValue::get(MostDerivedArg); - if (MostDerivedArg) { - if (FPT->isVariadic()) - Args.insert(Args.begin() + 1, - CallArg(RV, getContext().IntTy, /*needscopy=*/false)); - else - Args.add(RV, getContext().IntTy); + llvm::Value *MostDerivedArg; + if (Delegating) { + MostDerivedArg = getStructorImplicitParamValue(CGF); + } else { + MostDerivedArg = llvm::ConstantInt::get(CGM.Int32Ty, Type == Ctor_Complete); } + RValue RV = RValue::get(MostDerivedArg); + if (FPT->isVariadic()) + Args.insert(Args.begin() + 1, + CallArg(RV, getContext().IntTy, /*needscopy=*/false)); + else + Args.add(RV, getContext().IntTy); return 1; // Added one arg. } diff --git a/test/CodeGenCXX/microsoft-abi-structors.cpp b/test/CodeGenCXX/microsoft-abi-structors.cpp index 3fb97b9a36..a576f0c3d7 100644 --- a/test/CodeGenCXX/microsoft-abi-structors.cpp +++ b/test/CodeGenCXX/microsoft-abi-structors.cpp @@ -7,7 +7,7 @@ // RUN: FileCheck --check-prefix DTORS3 %s < %t // RUN: FileCheck --check-prefix DTORS4 %s < %t // -// RUN: %clang_cc1 -emit-llvm %s -o - -mconstructor-aliases -triple=x86_64-pc-win32 -fno-rtti | FileCheck --check-prefix DTORS-X64 %s +// RUN: %clang_cc1 -emit-llvm %s -o - -mconstructor-aliases -triple=x86_64-pc-win32 -fno-rtti -std=c++11 | FileCheck --check-prefix DTORS-X64 %s namespace basic { @@ -443,6 +443,20 @@ void g() { new MoveOnly(f()); } // CHECK: store {{.*}} @"\01??_7MoveOnly@implicit_copy_vtable@@6B@" } +namespace delegating_ctor { +struct Y {}; +struct X : virtual Y { + X(int); + X(); +}; +X::X(int) : X() {} +} +// CHECK: define x86_thiscallcc %"struct.delegating_ctor::X"* @"\01??0X@delegating_ctor@@QAE@H@Z"( +// CHECK: %[[is_most_derived_addr:.*]] = alloca i32, align 4 +// CHECK: store i32 %is_most_derived, i32* %[[is_most_derived_addr]] +// CHECK: %[[is_most_derived:.*]] = load i32, i32* %[[is_most_derived_addr]] +// CHECK: call x86_thiscallcc {{.*}}* @"\01??0X@delegating_ctor@@QAE@XZ"({{.*}} i32 %[[is_most_derived]]) + // Dtor thunks for classes in anonymous namespaces should be internal, not // linkonce_odr. namespace { @@ -471,4 +485,3 @@ class G { extern void testG() { G g; } -