All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Add warning about duplicate initializers
@ 2014-03-30 17:20 Linus Torvalds
  2014-03-30 20:37 ` Josh Triplett
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Torvalds @ 2014-03-30 17:20 UTC (permalink / raw)
  To: Christopher Li, Hans Verkuil; +Cc: Linux-Sparse


From: Linus Torvalds <torvalds@linux-foundation.org>
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 <torvalds@linux-foundation.org>
---

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-03-31  4:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-30 17:20 [PATCH 1/2] Add warning about duplicate initializers Linus Torvalds
2014-03-30 20:37 ` Josh Triplett
2014-03-31  4:25   ` Christopher Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.