aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/evaluate.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-03-30 09:49:13 -0700
committerChristopher Li <sparse@chrisli.org>2014-04-01 00:39:26 -0700
commit0f25c6a78e08fdc15af5e599d836fa24349c042f (patch)
tree7a03723257394bdd2c0768d8f068ae8cae7887cb /evaluate.c
parent7698bae699639892d639b8a9c270efdb8c46725c (diff)
downloadsparse-0f25c6a78e08fdc15af5e599d836fa24349c042f.tar.gz
Add warning about duplicate initializers
Noticed this while looking at an independent bug reported by Hans Verkuil. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Reviewed-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'evaluate.c')
-rw-r--r--evaluate.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/evaluate.c b/evaluate.c
index 98fc52b8..b86b21bf 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -3081,10 +3081,18 @@ static void check_duplicates(struct symbol *sym)
{
int declared = 0;
struct symbol *next = sym;
+ int initialized = sym->initializer != NULL;
while ((next = next->same_symbol) != NULL) {
const char *typediff;
evaluate_symbol(next);
+ if (initialized && next->initializer) {
+ sparse_error(sym->pos, "symbol '%s' has multiple initializers (originally initialized at %s:%d)",
+ show_ident(sym->ident),
+ stream_name(next->pos.stream), next->pos.line);
+ /* Only warn once */
+ initialized = 0;
+ }
declared++;
typediff = type_difference(&sym->ctype, &next->ctype, 0, 0);
if (typediff) {