bool IsUnion = false;
size_t Alignment = 0;
size_t Size = 0;
+ size_t AlignmentSize = 0;
std::vector<FieldInfo> Fields;
StringMap<size_t> FieldsByName;
- FieldInfo &addField(StringRef FieldName, FieldType FT, size_t FieldSize);
+ FieldInfo &addField(StringRef FieldName, FieldType FT,
+ size_t FieldAlignmentSize);
StructInfo() = default;
};
FieldInfo &StructInfo::addField(StringRef FieldName, FieldType FT,
- size_t FieldSize) {
+ size_t FieldAlignmentSize) {
if (!FieldName.empty())
FieldsByName[FieldName] = Fields.size();
Fields.emplace_back(FT);
if (IsUnion) {
Field.Offset = 0;
} else {
- Size = llvm::alignTo(Size, std::min(Alignment, FieldSize));
+ Size = llvm::alignTo(Size, std::min(Alignment, FieldAlignmentSize));
Field.Offset = Size;
}
+ AlignmentSize = std::max(AlignmentSize, FieldAlignmentSize);
return Field;
}
// Declare a field in the current struct.
bool MasmParser::addStructField(StringRef Name, const StructInfo &Structure) {
StructInfo &OwningStruct = StructInProgress.back();
- FieldInfo &Field = OwningStruct.addField(Name, FT_STRUCT, Structure.Size);
+ FieldInfo &Field =
+ OwningStruct.addField(Name, FT_STRUCT, Structure.AlignmentSize);
StructFieldInfo &StructInfo = Field.Contents.StructInfo;
StructInfo.Structure = Structure;
return Error(NameLoc, "mismatched name in ENDS directive; expected '" +
StructInProgress.back().Name + "'");
StructInfo Structure = StructInProgress.pop_back_val();
- // Pad to make the structure's size divisible by its alignment.
- Structure.Size = llvm::alignTo(Structure.Size, Structure.Alignment);
+ // Pad to make the structure's size divisible by the smaller of its alignment
+ // and the size of its largest field.
+ Structure.Size = llvm::alignTo(
+ Structure.Size, std::min(Structure.Alignment, Structure.AlignmentSize));
Structs[Name.lower()] = Structure;
if (parseToken(AsmToken::EndOfStatement))
else
ParentStruct.Size += Structure.Size;
} else {
- FieldInfo &Field =
- ParentStruct.addField(Structure.Name, FT_STRUCT, Structure.Size);
+ FieldInfo &Field = ParentStruct.addField(Structure.Name, FT_STRUCT,
+ Structure.AlignmentSize);
StructFieldInfo &StructInfo = Field.Contents.StructInfo;
Field.Type = Structure.Size;
Field.LengthOf = 1;