diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-03-30 10:13:54 -0700 |
---|---|---|
committer | Christopher Li <sparse@chrisli.org> | 2014-04-01 00:42:02 -0700 |
commit | 6e71132697e13a56625bac0bc51392e8f819c6de (patch) | |
tree | c2cd13ce43b3b4a32fe9db6e9976bdf5157d1793 | |
parent | 0f25c6a78e08fdc15af5e599d836fa24349c042f (diff) | |
download | sparse-6e71132697e13a56625bac0bc51392e8f819c6de.tar.gz |
Use any previous initializer to size a symbol
When we size a symbol, we only have one initializer per symbol, but we
may have multiple symbol declarations for the same symbol. So make sure
to walk the "same_symbol" chain to find the initializer, rather than
assuming it is attached to the current declaration.
Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Christopher Li <sparse@chrisli.org>
-rw-r--r-- | symbol.c | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -354,6 +354,15 @@ static int count_array_initializer(struct symbol *t, struct expression *expr) return nr; } +static struct expression *get_symbol_initializer(struct symbol *sym) +{ + do { + if (sym->initializer) + return sym->initializer; + } while ((sym = sym->same_symbol) != NULL); + return NULL; +} + static struct symbol * examine_node_type(struct symbol *sym) { struct symbol *base_type = examine_base_type(sym); @@ -376,12 +385,15 @@ static struct symbol * examine_node_type(struct symbol *sym) sym->ctype.alignment = alignment; /* Unsized array? The size might come from the initializer.. */ - if (bit_size < 0 && base_type->type == SYM_ARRAY && sym->initializer) { - struct symbol *node_type = base_type->ctype.base_type; - int count = count_array_initializer(node_type, sym->initializer); - - if (node_type && node_type->bit_size >= 0) - bit_size = node_type->bit_size * count; + if (bit_size < 0 && base_type->type == SYM_ARRAY) { + struct expression *initializer = get_symbol_initializer(sym); + if (initializer) { + struct symbol *node_type = base_type->ctype.base_type; + int count = count_array_initializer(node_type, initializer); + + if (node_type && node_type->bit_size >= 0) + bit_size = node_type->bit_size * count; + } } sym->bit_size = bit_size; |