r269465 - [MS ABI] Delegating constructors should not assume they are most derived
David Majnemer via cfe-commits
cfe-commits at lists.llvm.org
Fri May 13 13:05:09 PDT 2016
Author: majnemer
Date: Fri May 13 15:05:09 2016
New Revision: 269465
URL: http://llvm.org/viewvc/llvm-project?rev=269465&view=rev
Log:
[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.
Modified:
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp
Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=269465&r1=269464&r2=269465&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Fri May 13 15:05:09 2016
@@ -1467,16 +1467,18 @@ unsigned MicrosoftCXXABI::addImplicitCon
// Add the 'most_derived' argument second if we are variadic or last if not.
const FunctionProtoType *FPT = D->getType()->castAs<FunctionProtoType>();
- 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.
}
Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp?rev=269465&r1=269464&r2=269465&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp Fri May 13 15:05:09 2016
@@ -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 at 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 at delegating_ctor@@QAE at 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 at delegating_ctor@@QAE at 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;
}
-
More information about the cfe-commits
mailing list