From mboxrd@z Thu Jan 1 00:00:00 1970 From: Linus Torvalds Subject: [PATCH 1/2] Add warning about duplicate initializers Date: Sun, 30 Mar 2014 10:20:41 -0700 (PDT) Message-ID: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Return-path: Received: from mail-pb0-f44.google.com ([209.85.160.44]:35590 "EHLO mail-pb0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752092AbaC3RUn (ORCPT ); Sun, 30 Mar 2014 13:20:43 -0400 Received: by mail-pb0-f44.google.com with SMTP id rp16so7146965pbb.17 for ; Sun, 30 Mar 2014 10:20:43 -0700 (PDT) Sender: linux-sparse-owner@vger.kernel.org List-Id: linux-sparse@vger.kernel.org To: Christopher Li , Hans Verkuil Cc: Linux-Sparse From: Linus Torvalds Date: Sun, 30 Mar 2014 09:49:13 -0700 Subject: [PATCH 1/2] Add warning about duplicate initializers Noticed this while looking at an independent bug reported by Hans Verkuil. Signed-off-by: Linus Torvalds --- This is not a big deal, but the next patch will make us take the array size from any initializer, so let's warn on multiple initializers. evaluate.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/evaluate.c b/evaluate.c index 66556150ddac..8a53b3e884e0 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3043,10 +3043,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) { -- 1.9.0