Skip to content

Commit 1e7ec48

Browse files
committed
[AST] Get field size in chars rather than bits in RecordLayoutBuilder.
In D79719, LayoutField was refactored to fetch the size of field types in bits and then convert to chars, rather than fetching them in chars directly. This is not ideal, since it makes the calculations char size dependent, and breaks for sizes that are not a multiple of the char size. This patch changes it to use getTypeInfoInChars instead of getTypeInfo. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D85191
1 parent 33f5746 commit 1e7ec48

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,14 +1838,13 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
18381838
CharUnits EffectiveFieldSize;
18391839

18401840
auto setDeclInfo = [&](bool IsIncompleteArrayType) {
1841-
TypeInfo TI = Context.getTypeInfo(D->getType());
1842-
FieldAlign = Context.toCharUnitsFromBits(TI.Align);
1841+
auto TI = Context.getTypeInfoInChars(D->getType());
1842+
FieldAlign = TI.second;
18431843
// Flexible array members don't have any size, but they have to be
18441844
// aligned appropriately for their element type.
18451845
EffectiveFieldSize = FieldSize =
1846-
IsIncompleteArrayType ? CharUnits::Zero()
1847-
: Context.toCharUnitsFromBits(TI.Width);
1848-
AlignIsRequired = TI.AlignIsRequired;
1846+
IsIncompleteArrayType ? CharUnits::Zero() : TI.first;
1847+
AlignIsRequired = Context.getTypeInfo(D->getType()).AlignIsRequired;
18491848
};
18501849

18511850
if (D->getType()->isIncompleteArrayType()) {

0 commit comments

Comments
 (0)