Merge pull request #2275 from acqn/BitfieldFix

[cc65] Fixed constness of bit-fields
This commit is contained in:
Bob Andrews 2023-12-08 01:54:02 +01:00 committed by GitHub
commit c4575ec2c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
}