@@ -7186,12 +7186,23 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor
7186
7186
error(bfd.loc, " bit field width %d is larger than type" , bfd.fieldWidth);
7187
7187
7188
7188
const style = target.c.bitFieldStyle;
7189
+ if (style != TargetC.BitFieldStyle.MS &&
7190
+ style != TargetC.BitFieldStyle.Gcc_Clang &&
7191
+ style != TargetC.BitFieldStyle.Gcc_Clang_ARM)
7192
+ {
7193
+ assert (0 , " unsupported bit-field style" );
7194
+ }
7195
+
7196
+ const isMicrosoftStyle = style == TargetC.BitFieldStyle.MS ;
7197
+ const contributesToAggregateAlignment = ! anon || style != TargetC.BitFieldStyle.Gcc_Clang;
7189
7198
7190
7199
void startNewField ()
7191
7200
{
7192
7201
if (log) printf(" startNewField()\n " );
7193
7202
uint alignsize;
7194
- if (style == TargetC.BitFieldStyle.Gcc_Clang)
7203
+ if (isMicrosoftStyle)
7204
+ alignsize = memsize; // not memalignsize
7205
+ else
7195
7206
{
7196
7207
if (bfd.fieldWidth > 32 )
7197
7208
alignsize = memalignsize;
@@ -7202,15 +7213,13 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor
7202
7213
else
7203
7214
alignsize = 1 ;
7204
7215
}
7205
- else
7206
- alignsize = memsize; // not memalignsize
7207
7216
7208
7217
uint dummy;
7209
7218
bfd.offset = placeField(
7210
7219
fieldState.offset,
7211
7220
memsize, alignsize, bfd.alignment,
7212
7221
ad.structsize,
7213
- (anon && style == TargetC.BitFieldStyle.Gcc_Clang) ? dummy : ad.alignsize,
7222
+ contributesToAggregateAlignment ? ad.alignsize : dummy ,
7214
7223
isunion);
7215
7224
7216
7225
fieldState.inFlight = true ;
@@ -7219,53 +7228,38 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor
7219
7228
fieldState.fieldSize = memsize;
7220
7229
}
7221
7230
7222
- if (style == TargetC.BitFieldStyle.Gcc_Clang)
7231
+ if (ad.alignsize == 0 )
7232
+ ad.alignsize = 1 ;
7233
+ if (! isMicrosoftStyle && contributesToAggregateAlignment && ad.alignsize < memalignsize)
7234
+ ad.alignsize = memalignsize;
7235
+
7236
+ if (bfd.fieldWidth == 0 )
7223
7237
{
7224
- if (bfd.fieldWidth == 0 )
7238
+ if (! isMicrosoftStyle && ! isunion )
7225
7239
{
7226
- if (! isunion)
7227
- {
7228
- // Use type of zero width field to align to next field
7229
- fieldState.offset = (fieldState.offset + memalignsize - 1 ) & ~ (memalignsize - 1 );
7230
- ad.structsize = fieldState.offset;
7231
- }
7232
-
7233
- fieldState.inFlight = false ;
7234
- return ;
7240
+ // Use type of zero width field to align to next field
7241
+ fieldState.offset = (fieldState.offset + memalignsize - 1 ) & ~ (memalignsize - 1 );
7242
+ ad.structsize = fieldState.offset;
7235
7243
}
7236
-
7237
- if (ad.alignsize == 0 )
7238
- ad.alignsize = 1 ;
7239
- if (! anon &&
7240
- ad.alignsize < memalignsize)
7241
- ad.alignsize = memalignsize;
7242
- }
7243
- else if (style == TargetC.BitFieldStyle.MS )
7244
- {
7245
- if (ad.alignsize == 0 )
7246
- ad.alignsize = 1 ;
7247
- if (bfd.fieldWidth == 0 )
7244
+ else if (isMicrosoftStyle && fieldState.inFlight && ! isunion)
7248
7245
{
7249
- if (fieldState.inFlight && ! isunion)
7250
- {
7251
- // documentation says align to next int
7252
- // const alsz = cast(uint)Type.tint32.size();
7253
- const alsz = memsize; // but it really does this
7254
- fieldState.offset = (fieldState.offset + alsz - 1 ) & ~ (alsz - 1 );
7255
- ad.structsize = fieldState.offset;
7256
- }
7257
-
7258
- fieldState.inFlight = false ;
7259
- return ;
7246
+ // documentation says align to next int
7247
+ // const alsz = cast(uint)Type.tint32.size();
7248
+ const alsz = memsize; // but it really does this
7249
+ fieldState.offset = (fieldState.offset + alsz - 1 ) & ~ (alsz - 1 );
7250
+ ad.structsize = fieldState.offset;
7260
7251
}
7252
+
7253
+ fieldState.inFlight = false ;
7254
+ return ;
7261
7255
}
7262
7256
7263
7257
if (! fieldState.inFlight)
7264
7258
{
7265
7259
// printf("not in flight\n");
7266
7260
startNewField();
7267
7261
}
7268
- else if (style == TargetC.BitFieldStyle.Gcc_Clang )
7262
+ else if (! isMicrosoftStyle )
7269
7263
{
7270
7264
// If the bit-field spans more units of alignment than its type,
7271
7265
// start a new field at the next alignment boundary.
@@ -7288,7 +7282,7 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor
7288
7282
}
7289
7283
}
7290
7284
}
7291
- else if (style == TargetC.BitFieldStyle. MS )
7285
+ else
7292
7286
{
7293
7287
if (memsize != fieldState.fieldSize ||
7294
7288
fieldState.bitOffset + bfd.fieldWidth > fieldState.fieldSize * 8 )
@@ -7297,14 +7291,14 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor
7297
7291
startNewField();
7298
7292
}
7299
7293
}
7300
- else
7301
- assert (0 );
7302
7294
7303
7295
bfd.offset = fieldState.fieldOffset;
7304
7296
bfd.bitOffset = fieldState.bitOffset;
7305
7297
7306
7298
const pastField = bfd.bitOffset + bfd.fieldWidth;
7307
- if (style == TargetC.BitFieldStyle.Gcc_Clang)
7299
+ if (isMicrosoftStyle)
7300
+ fieldState.fieldSize = memsize;
7301
+ else
7308
7302
{
7309
7303
auto size = (pastField + 7 ) / 8 ;
7310
7304
fieldState.fieldSize = size;
@@ -7318,8 +7312,6 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor
7318
7312
else
7319
7313
ad.structsize = bfd.offset + size;
7320
7314
}
7321
- else
7322
- fieldState.fieldSize = memsize;
7323
7315
// printf("at end: ad.structsize = %d\n", cast(int)ad.structsize);
7324
7316
// print(fieldState);
7325
7317
0 commit comments