diff options
author | Akira Hatanaka <ahatanaka@apple.com> | 2018-01-27 00:34:09 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@apple.com> | 2018-01-27 00:34:09 +0000 |
commit | e5dbb64652a02c788437738685ff40ce7f469c58 (patch) | |
tree | 3a9dd078e8824bc23c32a2ebd5e127abd4e80051 /clang/lib/CodeGen/CGClass.cpp | |
parent | 1edb905e823c5eabd3c934ef0129c5387bc3f9fb (diff) | |
download | llvm-e5dbb64652a02c788437738685ff40ce7f469c58.zip llvm-e5dbb64652a02c788437738685ff40ce7f469c58.tar.gz llvm-e5dbb64652a02c788437738685ff40ce7f469c58.tar.bz2 |
[CodeGen] Use the non-virtual alignment when emitting the base
constructor.
Previously, clang would emit an over-aligned (16-byte) store to
initialize B::x in B's base constructor when compiling the following
code:
struct A {
__attribute__((aligned(16))) double data1;
};
struct B : public virtual A {
B() : x(123) {}
double a;
int x;
};
struct C : public virtual B {};
void test() { B b; C c; }
This was happening because the code in IRGen that does member
initialization was using the alignment of a complete object instead of
the non-virtual alignment.
This commit fixes the bug.
rdar://problem/36382481
Differential Revision: https://reviews.llvm.org/D42521
llvm-svn: 323578
Diffstat (limited to 'clang/lib/CodeGen/CGClass.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGClass.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index b1496a8..56bd250 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -615,7 +615,14 @@ static void EmitMemberInitializer(CodeGenFunction &CGF, llvm::Value *ThisPtr = CGF.LoadCXXThis(); QualType RecordTy = CGF.getContext().getTypeDeclType(ClassDecl); - LValue LHS = CGF.MakeNaturalAlignAddrLValue(ThisPtr, RecordTy); + LValue LHS; + + // If a base constructor is being emitted, create an LValue that has the + // non-virtual alignment. + if (CGF.CurGD.getCtorType() == Ctor_Base) + LHS = CGF.MakeNaturalAlignPointeeAddrLValue(ThisPtr, RecordTy); + else + LHS = CGF.MakeNaturalAlignAddrLValue(ThisPtr, RecordTy); EmitLValueForAnyFieldInitialization(CGF, MemberInit, LHS); |