mirror of
https://github.com/cc65/cc65.git
synced 2025-02-28 20:29:46 +00:00
Fixed initialization of union when it has an anonymous bit-field as the first member declaration.
This commit is contained in:
parent
5537b61e6a
commit
3b7af398a9
@ -511,7 +511,8 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
|||||||
/* This may be an anonymous bit-field, in which case it doesn't
|
/* This may be an anonymous bit-field, in which case it doesn't
|
||||||
** have an initializer.
|
** have an initializer.
|
||||||
*/
|
*/
|
||||||
if (SymIsBitField (TagSym) && (IsAnonName (TagSym->Name))) {
|
if (SymIsBitField (TagSym) && IsAnonName (TagSym->Name)) {
|
||||||
|
if (!IsTypeUnion (T)) {
|
||||||
/* Account for the data and output it if we have at least a full
|
/* Account for the data and output it if we have at least a full
|
||||||
** byte. We may have more if there was storage unit overlap, for
|
** byte. We may have more if there was storage unit overlap, for
|
||||||
** example two consecutive 7 bit fields. Those would be packed
|
** example two consecutive 7 bit fields. Those would be packed
|
||||||
@ -524,6 +525,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
|||||||
while (SI.ValBits >= CHAR_BITS) {
|
while (SI.ValBits >= CHAR_BITS) {
|
||||||
DefineBitFieldData (&SI);
|
DefineBitFieldData (&SI);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Avoid consuming the comma if any */
|
/* Avoid consuming the comma if any */
|
||||||
goto NextMember;
|
goto NextMember;
|
||||||
}
|
}
|
||||||
@ -628,15 +630,15 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
|||||||
/* Skip the comma next round */
|
/* Skip the comma next round */
|
||||||
SkipComma = 1;
|
SkipComma = 1;
|
||||||
|
|
||||||
NextMember:
|
/* For unions, only the first named member can be initialized */
|
||||||
/* Next member. For unions, only the first one can be initialized */
|
|
||||||
if (IsTypeUnion (T)) {
|
if (IsTypeUnion (T)) {
|
||||||
/* Union */
|
|
||||||
TagSym = 0;
|
TagSym = 0;
|
||||||
} else {
|
continue;
|
||||||
/* Struct */
|
|
||||||
TagSym = TagSym->NextSym;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NextMember:
|
||||||
|
/* Next member */
|
||||||
|
TagSym = TagSym->NextSym;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HasCurly) {
|
if (HasCurly) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2020 The cc65 Authors
|
Copyright 2020-2023 The cc65 Authors
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
@ -25,6 +25,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
|
const unsigned int : 1;
|
||||||
unsigned int bf;
|
unsigned int bf;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@ -38,8 +39,12 @@ static unsigned char failures = 0;
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
bitfield_t bitfield = {0};
|
bitfield_t bitfield = { 42 };
|
||||||
|
|
||||||
|
printf ("Bitfield: %u\n", bitfield.bf);
|
||||||
|
if (bitfield.bf != 42) failures++;
|
||||||
|
|
||||||
|
bitfield.bf ^= 42;
|
||||||
printf ("Bitfield: %u\n", bitfield.bf);
|
printf ("Bitfield: %u\n", bitfield.bf);
|
||||||
if (bitfield.bf != 0) failures++;
|
if (bitfield.bf != 0) failures++;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user