diff options
author | Tom Stellard <tstellar@redhat.com> | 2018-05-30 18:06:17 +0000 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2018-05-30 18:06:17 +0000 |
commit | ba3c53d060a8c1943297a14b3b770e90cf9afd65 (patch) | |
tree | 28d37068f639817948535bde602f9d610dd7ac37 | |
parent | Merging r326235: (diff) | |
download | llvm-project-ba3c53d060a8c1943297a14b3b770e90cf9afd65.tar.gz llvm-project-ba3c53d060a8c1943297a14b3b770e90cf9afd65.tar.bz2 llvm-project-ba3c53d060a8c1943297a14b3b770e90cf9afd65.zip |
Merging r326173:
------------------------------------------------------------------------
r326173 | mstorsjo | 2018-02-26 22:27:06 -0800 (Mon, 26 Feb 2018) | 17 lines
[RecordLayout] Don't align to non-power-of-2 sizes when using -mms-bitfields
When targeting GNU/MinGW for i386, the size of the "long double" data
type is 12 bytes (while it is 8 bytes in MSVC). When building
with -mms-bitfields to have struct layouts match MSVC, data types
are laid out in a struct with alignment according to their size.
However, this doesn't make sense for the long double type, since
it doesn't match MSVC at all, and aligning to a non-power-of-2
size triggers other asserts later.
This matches what GCC does, aligning a long double to 4 bytes
in structs on i386 even when -mms-bitfields is specified.
This fixes asserts when using the max_align_t data type when
building for MinGW/i386 with the -mms-bitfields flag.
Differential Revision: https://reviews.llvm.org/D43734
------------------------------------------------------------------------
llvm-svn: 333569
-rw-r--r-- | clang/lib/AST/RecordLayoutBuilder.cpp | 7 | ||||
-rw-r--r-- | clang/test/CodeGen/mingw-long-double.c | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp index a9d43dfa80c5..240e7f6e682f 100644 --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -1751,7 +1751,12 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D, QualType T = Context.getBaseElementType(D->getType()); if (const BuiltinType *BTy = T->getAs<BuiltinType>()) { CharUnits TypeSize = Context.getTypeSizeInChars(BTy); - if (TypeSize > FieldAlign) + assert( + (llvm::isPowerOf2_64(TypeSize.getQuantity()) || + Context.getTargetInfo().getTriple().isWindowsGNUEnvironment()) && + "Non PowerOf2 size outside of GNU mode"); + if (TypeSize > FieldAlign && + llvm::isPowerOf2_64(TypeSize.getQuantity())) FieldAlign = TypeSize; } } diff --git a/clang/test/CodeGen/mingw-long-double.c b/clang/test/CodeGen/mingw-long-double.c index 1c7c31f88be3..166f7decfc3a 100644 --- a/clang/test/CodeGen/mingw-long-double.c +++ b/clang/test/CodeGen/mingw-long-double.c @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -triple i686-windows-gnu -emit-llvm -o - %s \ // RUN: | FileCheck %s --check-prefix=GNU32 +// RUN: %clang_cc1 -triple i686-windows-gnu -emit-llvm -o - %s -mms-bitfields \ +// RUN: | FileCheck %s --check-prefix=GNU32 // RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -o - %s \ // RUN: | FileCheck %s --check-prefix=GNU64 // RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -o - %s \ |