mirror of https://github.com/microsoft/clang.git
Use external layout information to layout bit-fields for MS ABI.
Patch by Aleksandr Urakov! Differential Revision: https://reviews.llvm.org/D49227 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337047 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a06e85a92c
commit
130cf585e6
|
@ -2677,7 +2677,7 @@ void MicrosoftRecordLayoutBuilder::layoutBitField(const FieldDecl *FD) {
|
|||
// Check to see if this bitfield fits into an existing allocation. Note:
|
||||
// MSVC refuses to pack bitfields of formal types with different sizes
|
||||
// into the same allocation.
|
||||
if (!IsUnion && LastFieldIsNonZeroWidthBitfield &&
|
||||
if (!UseExternalLayout && !IsUnion && LastFieldIsNonZeroWidthBitfield &&
|
||||
CurrentBitfieldSize == Info.Size && Width <= RemainingBitsInField) {
|
||||
placeFieldAtBitOffset(Context.toBits(Size) - RemainingBitsInField);
|
||||
RemainingBitsInField -= Width;
|
||||
|
@ -2689,6 +2689,14 @@ void MicrosoftRecordLayoutBuilder::layoutBitField(const FieldDecl *FD) {
|
|||
placeFieldAtOffset(CharUnits::Zero());
|
||||
Size = std::max(Size, Info.Size);
|
||||
// TODO: Add a Sema warning that MS ignores bitfield alignment in unions.
|
||||
} else if (UseExternalLayout) {
|
||||
auto FieldBitOffset = External.getExternalFieldOffset(FD);
|
||||
placeFieldAtBitOffset(FieldBitOffset);
|
||||
auto NewSize = Context.toCharUnitsFromBits(
|
||||
llvm::alignTo(FieldBitOffset + Width, Context.getCharWidth()));
|
||||
assert(NewSize >= Size && "bit field offset already allocated");
|
||||
Size = NewSize;
|
||||
Alignment = std::max(Alignment, Info.Alignment);
|
||||
} else {
|
||||
// Allocate a new block of memory and place the bitfield in it.
|
||||
CharUnits FieldOffset = Size.alignTo(Info.Alignment);
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
*** Dumping AST Record Layout
|
||||
Type: struct S1
|
||||
|
||||
Layout: <ASTRecordLayout
|
||||
Size:16
|
||||
Alignment:16
|
||||
FieldOffsets: [0, 11]>
|
||||
|
||||
*** Dumping AST Record Layout
|
||||
Type: struct S2
|
||||
|
||||
Layout: <ASTRecordLayout
|
||||
Size:128
|
||||
Alignment:64
|
||||
FieldOffsets: [64]>
|
|
@ -0,0 +1,20 @@
|
|||
// RUN: %clang_cc1 -w -fdump-record-layouts-simple -foverride-record-layout=%S/Inputs/override-bit-field-layout.layout %s | FileCheck %s
|
||||
|
||||
// CHECK: Type: struct S1
|
||||
// CHECK: FieldOffsets: [0, 11]
|
||||
struct S1 {
|
||||
short a : 3;
|
||||
short b : 5;
|
||||
};
|
||||
|
||||
// CHECK: Type: struct S2
|
||||
// CHECK: FieldOffsets: [64]
|
||||
struct S2 {
|
||||
virtual ~S2() = default;
|
||||
short a : 3;
|
||||
};
|
||||
|
||||
void use_structs() {
|
||||
S1 s1s[sizeof(S1)];
|
||||
S2 s2s[sizeof(S2)];
|
||||
}
|
Loading…
Reference in New Issue