@@ -2274,9 +2274,10 @@ static unsigned getPaddingDiagFromTagKind(TagTypeKind Tag) {
22742274 }
22752275}
22762276
2277- void ItaniumRecordLayoutBuilder::CheckFieldPadding (
2278- uint64_t Offset, uint64_t UnpaddedOffset, uint64_t UnpackedOffset,
2279- unsigned UnpackedAlign, bool isPacked, const FieldDecl *D) {
2277+ // Function based on ItaniumRecordLayoutBuilder::CheckFieldPadding.
2278+ static void CheckFieldPadding (const ASTContext &Context, bool IsUnion,
2279+ uint64_t Offset, uint64_t UnpaddedOffset,
2280+ const FieldDecl *D) {
22802281 // We let objc ivars without warning, objc interfaces generally are not used
22812282 // for padding tricks.
22822283 if (isa<ObjCIvarDecl>(D))
@@ -2300,23 +2301,31 @@ void ItaniumRecordLayoutBuilder::CheckFieldPadding(
23002301 if (D->getIdentifier ()) {
23012302 auto Diagnostic = D->isBitField () ? diag::warn_padded_struct_bitfield
23022303 : diag::warn_padded_struct_field;
2303- Diag (D->getLocation (), Diagnostic)
2304+ Context.getDiagnostics ().Report (D->getLocation (),
2305+ Diagnostic)
23042306 << getPaddingDiagFromTagKind (D->getParent ()->getTagKind ())
23052307 << Context.getTypeDeclType (D->getParent ()) << PadSize
23062308 << (InBits ? 1 : 0 ) // (byte|bit)
23072309 << D->getIdentifier ();
23082310 } else {
23092311 auto Diagnostic = D->isBitField () ? diag::warn_padded_struct_anon_bitfield
23102312 : diag::warn_padded_struct_anon_field;
2311- Diag (D->getLocation (), Diagnostic)
2313+ Context.getDiagnostics ().Report (D->getLocation (),
2314+ Diagnostic)
23122315 << getPaddingDiagFromTagKind (D->getParent ()->getTagKind ())
23132316 << Context.getTypeDeclType (D->getParent ()) << PadSize
23142317 << (InBits ? 1 : 0 ); // (byte|bit)
23152318 }
2316- }
2317- if (isPacked && Offset != UnpackedOffset) {
2318- HasPackedField = true ;
2319- }
2319+ }
2320+ }
2321+
2322+ void ItaniumRecordLayoutBuilder::CheckFieldPadding (
2323+ uint64_t Offset, uint64_t UnpaddedOffset, uint64_t UnpackedOffset,
2324+ unsigned UnpackedAlign, bool isPacked, const FieldDecl *D) {
2325+ ::CheckFieldPadding (Context, IsUnion, Offset, UnpaddedOffset, D);
2326+ if (isPacked && Offset != UnpackedOffset) {
2327+ HasPackedField = true ;
2328+ }
23202329}
23212330
23222331static const CXXMethodDecl *computeKeyFunction (ASTContext &Context,
@@ -2605,8 +2614,6 @@ struct MicrosoftRecordLayoutBuilder {
26052614 void computeVtorDispSet (
26062615 llvm::SmallPtrSetImpl<const CXXRecordDecl *> &HasVtorDispSet,
26072616 const CXXRecordDecl *RD) const ;
2608- void CheckFieldPadding (uint64_t Offset, uint64_t UnpaddedOffset,
2609- const FieldDecl *D);
26102617 const ASTContext &Context;
26112618 EmptySubobjectMap *EmptySubobjects;
26122619
@@ -3008,8 +3015,8 @@ void MicrosoftRecordLayoutBuilder::layoutField(const FieldDecl *FD) {
30083015 uint64_t UnpaddedFielddOffsetInBits =
30093016 Context.toBits (DataSize) - RemainingBitsInField;
30103017
3011- CheckFieldPadding (Context.toBits (FieldOffset), UnpaddedFielddOffsetInBits ,
3012- FD);
3018+ :: CheckFieldPadding (Context, IsUnion, Context .toBits(FieldOffset),
3019+ UnpaddedFielddOffsetInBits, FD);
30133020
30143021 RemainingBitsInField = 0 ;
30153022
@@ -3064,8 +3071,8 @@ void MicrosoftRecordLayoutBuilder::layoutBitField(const FieldDecl *FD) {
30643071 Size = FieldOffset + Info.Size ;
30653072 Alignment = std::max (Alignment, Info.Alignment );
30663073 RemainingBitsInField = Context.toBits (Info.Size ) - Width;
3067- CheckFieldPadding (Context.toBits (FieldOffset), UnpaddedFieldOffsetInBits ,
3068- FD);
3074+ :: CheckFieldPadding (Context, IsUnion, Context .toBits(FieldOffset),
3075+ UnpaddedFieldOffsetInBits, FD);
30693076 }
30703077 DataSize = Size;
30713078}
@@ -3095,8 +3102,8 @@ MicrosoftRecordLayoutBuilder::layoutZeroWidthBitField(const FieldDecl *FD) {
30953102 RemainingBitsInField = 0 ;
30963103 Size = FieldOffset;
30973104 Alignment = std::max (Alignment, Info.Alignment );
3098- CheckFieldPadding (Context.toBits (FieldOffset), UnpaddedFieldOffsetInBits ,
3099- FD);
3105+ :: CheckFieldPadding (Context, IsUnion, Context .toBits(FieldOffset),
3106+ UnpaddedFieldOffsetInBits, FD);
31003107 }
31013108 DataSize = Size;
31023109}
@@ -3219,51 +3226,6 @@ void MicrosoftRecordLayoutBuilder::layoutVirtualBases(const CXXRecordDecl *RD) {
32193226 PreviousBaseLayout = &BaseLayout;
32203227 }
32213228}
3222- // Function based on ItaniumRecordLayoutBuilder::CheckFieldPadding.
3223- void MicrosoftRecordLayoutBuilder::CheckFieldPadding (uint64_t Offset,
3224- uint64_t UnpaddedOffset,
3225- const FieldDecl *D) {
3226-
3227- // We let objc ivars without warning, objc interfaces generally are not used
3228- // for padding tricks.
3229- if (isa<ObjCIvarDecl>(D))
3230- return ;
3231-
3232- // Don't warn about structs created without a SourceLocation. This can
3233- // be done by clients of the AST, such as codegen.
3234- if (D->getLocation ().isInvalid ())
3235- return ;
3236-
3237- unsigned CharBitNum = Context.getTargetInfo ().getCharWidth ();
3238-
3239- // Warn if padding was introduced to the struct/class.
3240- if (!IsUnion && Offset > UnpaddedOffset) {
3241- unsigned PadSize = Offset - UnpaddedOffset;
3242- bool InBits = true ;
3243- if (PadSize % CharBitNum == 0 ) {
3244- PadSize = PadSize / CharBitNum;
3245- InBits = false ;
3246- }
3247- if (D->getIdentifier ()) {
3248- auto Diagnostic = D->isBitField () ? diag::warn_padded_struct_bitfield
3249- : diag::warn_padded_struct_field;
3250- Context.getDiagnostics ().Report (D->getLocation (),
3251- Diagnostic)
3252- << getPaddingDiagFromTagKind (D->getParent ()->getTagKind ())
3253- << Context.getTypeDeclType (D->getParent ()) << PadSize
3254- << (InBits ? 1 : 0 ) // (byte|bit)
3255- << D->getIdentifier ();
3256- } else {
3257- auto Diagnostic = D->isBitField () ? diag::warn_padded_struct_anon_bitfield
3258- : diag::warn_padded_struct_anon_field;
3259- Context.getDiagnostics ().Report (D->getLocation (),
3260- Diagnostic)
3261- << getPaddingDiagFromTagKind (D->getParent ()->getTagKind ())
3262- << Context.getTypeDeclType (D->getParent ()) << PadSize
3263- << (InBits ? 1 : 0 ); // (byte|bit)
3264- }
3265- }
3266- }
32673229
32683230void MicrosoftRecordLayoutBuilder::finalizeLayout (const RecordDecl *RD) {
32693231 uint64_t UnpaddedSizeInBits = Context.toBits (DataSize);
0 commit comments