@@ -2274,9 +2274,10 @@ static unsigned getPaddingDiagFromTagKind(TagTypeKind Tag) {
2274
2274
}
2275
2275
}
2276
2276
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) {
2280
2281
// We let objc ivars without warning, objc interfaces generally are not used
2281
2282
// for padding tricks.
2282
2283
if (isa<ObjCIvarDecl>(D))
@@ -2300,23 +2301,31 @@ void ItaniumRecordLayoutBuilder::CheckFieldPadding(
2300
2301
if (D->getIdentifier ()) {
2301
2302
auto Diagnostic = D->isBitField () ? diag::warn_padded_struct_bitfield
2302
2303
: diag::warn_padded_struct_field;
2303
- Diag (D->getLocation (), Diagnostic)
2304
+ Context.getDiagnostics ().Report (D->getLocation (),
2305
+ Diagnostic)
2304
2306
<< getPaddingDiagFromTagKind (D->getParent ()->getTagKind ())
2305
2307
<< Context.getTypeDeclType (D->getParent ()) << PadSize
2306
2308
<< (InBits ? 1 : 0 ) // (byte|bit)
2307
2309
<< D->getIdentifier ();
2308
2310
} else {
2309
2311
auto Diagnostic = D->isBitField () ? diag::warn_padded_struct_anon_bitfield
2310
2312
: diag::warn_padded_struct_anon_field;
2311
- Diag (D->getLocation (), Diagnostic)
2313
+ Context.getDiagnostics ().Report (D->getLocation (),
2314
+ Diagnostic)
2312
2315
<< getPaddingDiagFromTagKind (D->getParent ()->getTagKind ())
2313
2316
<< Context.getTypeDeclType (D->getParent ()) << PadSize
2314
2317
<< (InBits ? 1 : 0 ); // (byte|bit)
2315
2318
}
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
+ }
2320
2329
}
2321
2330
2322
2331
static const CXXMethodDecl *computeKeyFunction (ASTContext &Context,
@@ -2605,8 +2614,6 @@ struct MicrosoftRecordLayoutBuilder {
2605
2614
void computeVtorDispSet (
2606
2615
llvm::SmallPtrSetImpl<const CXXRecordDecl *> &HasVtorDispSet,
2607
2616
const CXXRecordDecl *RD) const ;
2608
- void CheckFieldPadding (uint64_t Offset, uint64_t UnpaddedOffset,
2609
- const FieldDecl *D);
2610
2617
const ASTContext &Context;
2611
2618
EmptySubobjectMap *EmptySubobjects;
2612
2619
@@ -3008,8 +3015,8 @@ void MicrosoftRecordLayoutBuilder::layoutField(const FieldDecl *FD) {
3008
3015
uint64_t UnpaddedFielddOffsetInBits =
3009
3016
Context.toBits (DataSize) - RemainingBitsInField;
3010
3017
3011
- CheckFieldPadding (Context.toBits (FieldOffset), UnpaddedFielddOffsetInBits ,
3012
- FD);
3018
+ :: CheckFieldPadding (Context, IsUnion, Context .toBits(FieldOffset),
3019
+ UnpaddedFielddOffsetInBits, FD);
3013
3020
3014
3021
RemainingBitsInField = 0 ;
3015
3022
@@ -3064,8 +3071,8 @@ void MicrosoftRecordLayoutBuilder::layoutBitField(const FieldDecl *FD) {
3064
3071
Size = FieldOffset + Info.Size ;
3065
3072
Alignment = std::max (Alignment, Info.Alignment );
3066
3073
RemainingBitsInField = Context.toBits (Info.Size ) - Width;
3067
- CheckFieldPadding (Context.toBits (FieldOffset), UnpaddedFieldOffsetInBits ,
3068
- FD);
3074
+ :: CheckFieldPadding (Context, IsUnion, Context .toBits(FieldOffset),
3075
+ UnpaddedFieldOffsetInBits, FD);
3069
3076
}
3070
3077
DataSize = Size ;
3071
3078
}
@@ -3095,8 +3102,8 @@ MicrosoftRecordLayoutBuilder::layoutZeroWidthBitField(const FieldDecl *FD) {
3095
3102
RemainingBitsInField = 0 ;
3096
3103
Size = FieldOffset;
3097
3104
Alignment = std::max (Alignment, Info.Alignment );
3098
- CheckFieldPadding (Context.toBits (FieldOffset), UnpaddedFieldOffsetInBits ,
3099
- FD);
3105
+ :: CheckFieldPadding (Context, IsUnion, Context .toBits(FieldOffset),
3106
+ UnpaddedFieldOffsetInBits, FD);
3100
3107
}
3101
3108
DataSize = Size ;
3102
3109
}
@@ -3219,51 +3226,6 @@ void MicrosoftRecordLayoutBuilder::layoutVirtualBases(const CXXRecordDecl *RD) {
3219
3226
PreviousBaseLayout = &BaseLayout;
3220
3227
}
3221
3228
}
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
- }
3267
3229
3268
3230
void MicrosoftRecordLayoutBuilder::finalizeLayout (const RecordDecl *RD) {
3269
3231
uint64_t UnpaddedSizeInBits = Context.toBits (DataSize);
0 commit comments