r219775 - MS ABI: Use the correct this arg when generating implicit array copy ctor
David Majnemer
david.majnemer at gmail.com
Tue Oct 14 21:54:55 PDT 2014
Author: majnemer
Date: Tue Oct 14 23:54:54 2014
New Revision: 219775
URL: http://llvm.org/viewvc/llvm-project?rev=219775&view=rev
Log:
MS ABI: Use the correct this arg when generating implicit array copy ctor
We assumed the last argument of the copy constructor was the this
pointer. However, this is not the case under the MS ABI.
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/test/CodeGenCXX/pr20897.cpp
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=219775&r1=219774&r2=219775&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Tue Oct 14 23:54:54 2014
@@ -580,9 +580,8 @@ static void EmitMemberInitializer(CodeGe
CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(MemberInit->getInit());
if (BaseElementTy.isPODType(CGF.getContext()) ||
(CE && CE->getConstructor()->isTrivial())) {
- // Find the source pointer. We know it's the last argument because
- // we know we're in an implicit copy constructor.
- unsigned SrcArgIndex = Args.size() - 1;
+ unsigned SrcArgIndex =
+ CGF.CGM.getCXXABI().getSrcArgforCopyCtor(Constructor, Args);
llvm::Value *SrcPtr
= CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(Args[SrcArgIndex]));
LValue ThisRHSLV = CGF.MakeNaturalAlignAddrLValue(SrcPtr, RecordTy);
Modified: cfe/trunk/test/CodeGenCXX/pr20897.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pr20897.cpp?rev=219775&r1=219774&r2=219775&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/pr20897.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/pr20897.cpp Tue Oct 14 23:54:54 2014
@@ -15,3 +15,19 @@ struct __declspec(dllexport) Derived : v
bool a : 1;
bool b : 1;
};
+
+// __declspec(dllexport) causes us to export the implicit copy constructor.
+struct __declspec(dllexport) Derived2 : virtual Base {
+// CHECK-LABEL: define weak_odr dllexport x86_thiscallcc %struct.Derived2* @"\01??0Derived2@@QAE at ABU0@@Z"
+// CHECK: %[[this:.*]] = load %struct.Derived2** {{.*}}
+// CHECK-NEXT: store %struct.Derived2* %[[this]], %struct.Derived2** %[[retval:.*]]
+// CHECK: %[[dest_a_gep:.*]] = getelementptr inbounds %struct.Derived2* %[[this]], i32 0, i32 1
+// CHECK-NEXT: %[[src_load:.*]] = load %struct.Derived2** {{.*}}
+// CHECK-NEXT: %[[src_a_gep:.*]] = getelementptr inbounds %struct.Derived2* %[[src_load:.*]], i32 0, i32 1
+// CHECK-NEXT: %[[dest_a_bitcast:.*]] = bitcast [1 x i32]* %[[dest_a_gep]] to i8*
+// CHECK-NEXT: %[[src_a_bitcast:.*]] = bitcast [1 x i32]* %[[src_a_gep]] to i8*
+// CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[dest_a_bitcast]], i8* %[[src_a_bitcast]], i32 4, i32 4, i1 false)
+// CHECK-NEXT: %[[dest_this:.*]] = load %struct.Derived2** %[[retval]]
+// CHECK-NEXT: ret %struct.Derived2* %[[dest_this]]
+ int Array[1];
+};
More information about the cfe-commits
mailing list