From 85c9e970ade4eb7b778b2180d6af2390b986327a Mon Sep 17 00:00:00 2001 From: Jiri Malak Date: Wed, 12 Jun 2024 10:53:54 +0200 Subject: [PATCH] cc: fix C compiler bitfields initialization for C99 designated initializers ( issues #1283 ) --- bld/cc/c/cdinit.c | 48 ++++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/bld/cc/c/cdinit.c b/bld/cc/c/cdinit.c index 7475869398..6ffe34b957 100644 --- a/bld/cc/c/cdinit.c +++ b/bld/cc/c/cdinit.c @@ -657,13 +657,12 @@ static void ResetBitField( uint64 *val64, unsigned start, unsigned width ) val64->u._32[I64LO32] &= ~mask.u._32[I64LO32]; } -static FIELDPTR InitBitField( FIELDPTR field ) +static void InitBitField( FIELDPTR field ) { TYPEPTR typ; target_size size; uint64 value64; const_val bit_value; - target_size offset; TOKEN token; bool is64bit; DATA_TYPE dtype; @@ -677,34 +676,20 @@ static FIELDPTR InitBitField( FIELDPTR field ) dtype = typ->u.f.field_type; is64bit = ( dtype == TYP_LONG64 || dtype == TYP_ULONG64 ); LoadBitField( &value64 ); - offset = field->offset; - while( typ->decl_type == TYP_FIELD || typ->decl_type == TYP_UFIELD ) { - if( typ->u.f.field_type == TYP_BOOL ) { - width = 1; - } else { - width = typ->u.f.field_width; - } - ResetBitField( &value64, typ->u.f.field_start, width ); - if( CurToken != T_RIGHT_BRACE ) { - if( ConstExprAndType( &bit_value ) ) { - if( CheckAssignBits( &bit_value.value, width, true ) ) { - CWarn1( ERR_CONSTANT_TOO_BIG ); - } - U64ShiftL( &bit_value.value, typ->u.f.field_start, &bit_value.value ); - value64.u._32[I64LO32] |= bit_value.value.u._32[I64LO32]; - value64.u._32[I64HI32] |= bit_value.value.u._32[I64HI32]; + if( typ->u.f.field_type == TYP_BOOL ) { + width = 1; + } else { + width = typ->u.f.field_width; + } + ResetBitField( &value64, typ->u.f.field_start, width ); + if( CurToken != T_RIGHT_BRACE ) { + if( ConstExprAndType( &bit_value ) ) { + if( CheckAssignBits( &bit_value.value, width, true ) ) { + CWarn1( ERR_CONSTANT_TOO_BIG ); } - } - if( CurToken == T_EOF ) - break; - field = field->next_field; - if( field == NULL || field->offset != offset ) - break; /* bit field done */ - typ = field->field_type; - if( CurToken != T_RIGHT_BRACE ) { - MustRecog( T_COMMA ); - } else if( token != T_LEFT_BRACE ) { - break; + U64ShiftL( &bit_value.value, typ->u.f.field_start, &bit_value.value ); + value64.u._32[I64LO32] |= bit_value.value.u._32[I64LO32]; + value64.u._32[I64HI32] |= bit_value.value.u._32[I64HI32]; } } if( is64bit ) { @@ -717,7 +702,6 @@ static FIELDPTR InitBitField( FIELDPTR field ) NextToken(); MustRecog( T_RIGHT_BRACE ); } - return( field ); } @@ -900,11 +884,11 @@ static void InitStructUnion( TYPEPTR typ, TYPEPTR ctyp, FIELDPTR field ) offset = field->offset + SizeOfArg( ftyp ); if( ftyp->decl_type == TYP_FIELD || ftyp->decl_type == TYP_UFIELD ) { - field = InitBitField( field ); + InitBitField( field ); } else { InitSymData( ftyp, ctyp, 1 ); - field = field->next_field; } + field = field->next_field; if( typ->decl_type == TYP_UNION ) { if( offset < n ) { ZeroBytes( n - offset ); /* pad the rest */