Fixed constness of bit-fields.

This commit is contained in:
acqn 2023-11-29 12:27:01 +08:00
parent 5537b61e6a
commit 6434176909
4 changed files with 19 additions and 4 deletions

View File

@ -497,8 +497,8 @@ Type* NewPointerTo (const Type* T)
Type* NewBitFieldOf (const Type* T, unsigned BitOffs, unsigned BitWidth)
/* Return a type string that is "T : BitWidth" aligned on BitOffs. The type
** string is allocated on the heap and may be freed after use.
/* Return a type string that is "unqualified T : BitWidth" aligned on BitOffs.
** The type string is allocated on the heap and may be freed after use.
*/
{
Type* P;

View File

@ -435,8 +435,8 @@ Type* NewPointerTo (const Type* T);
*/
Type* NewBitFieldOf (const Type* T, unsigned BitOffs, unsigned BitWidth);
/* Return a type string that is "T : BitWidth" aligned on BitOffs. The type
** string is allocated on the heap and may be freed after use.
/* Return a type string that is "unqualified T : BitWidth" aligned on BitOffs.
** The type string is allocated on the heap and may be freed after use.
*/
const Type* AddressOf (const Type* T);

View File

@ -1023,6 +1023,7 @@ SymEntry* AddBitField (const char* Name, const Type* T, unsigned Offs,
} else {
Entry->Type = NewBitFieldOf (T, BitOffs, BitWidth);
}
Entry->Type[0].C |= GetQualifier (T) & T_MASK_QUAL;
/* Add the entry to the symbol table */
AddSymEntry (FieldTab, Entry);

View File

@ -0,0 +1,14 @@
/* Bug #2018 - Compiler has problems with const struct fields */
typedef union U {
int a : 16;
const int b : 16;
} U;
int main(void)
{
U x = { 42 };
x.b = 0;
return 0;
}