summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndreas Fried <andreas.fried@kit.edu>2019-07-29 22:33:36 +0200
committerAndreas Fried <andreas.fried@kit.edu>2019-07-29 22:35:49 +0200
commit55aa3c5c83aa573a87f4126da208d6a03126a69c (patch)
treedeaeecdeb123a45d0c43bb0d2760f2cfdd18e087
parent83e7ce225c500e5f00412de58fc35ccbad451b4f (diff)
Handle anonymous struct/union members in walk_designator (constfold.c).
This fixes C/gnu99/anonstruct4.c and C/init9.c.
-rw-r--r--src/ast/constfold.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/ast/constfold.c b/src/ast/constfold.c
index 9eea0dd..adeac32 100644
--- a/src/ast/constfold.c
+++ b/src/ast/constfold.c
@@ -409,13 +409,20 @@ static long get_offsetof_offset(const offsetof_expression_t *expression)
symbol_t *symbol = designator->symbol;
compound_t *compound = type->compound.compound;
- entity_t *iter = compound->members.first_entity;
- for (; iter->base.symbol != symbol; iter = iter->base.next) {}
- assert(iter->kind == ENTITY_COMPOUND_MEMBER);
- offset += iter->compound_member.offset;
+ for (;;) {
+ entity_t *member = find_compound_entry(compound, symbol);
+ assert(member->kind = ENTITY_COMPOUND_MEMBER);
+ offset += member->compound_member.offset;
- orig_type = iter->declaration.type;
+ orig_type = member->declaration.type;
+
+ if (member->base.symbol) {
+ break;
+ }
+
+ compound = skip_typeref(orig_type)->compound.compound;
+ }
} else {
expression_t *array_index = designator->array_index;
assert(designator->array_index != NULL);