diff mbox

[1/2] Add warning about duplicate initializers

Message ID alpine.LFD.2.11.1403301018060.16237@i7.linux-foundation.org (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Linus Torvalds March 30, 2014, 5:20 p.m. UTC
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(+)

Comments

Josh Triplett March 30, 2014, 8:37 p.m. UTC | #1
On Sun, Mar 30, 2014 at 10:20:41AM -0700, Linus Torvalds wrote:
> 
> 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>

Reviewed-by: Josh Triplett <josh@joshtriplett.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
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christopher Li March 31, 2014, 4:25 a.m. UTC | #2
On Sun, Mar 30, 2014 at 1:37 PM, Josh Triplett <josh@joshtriplett.org> wrote:
> On Sun, Mar 30, 2014 at 10:20:41AM -0700, Linus Torvalds wrote:
>> 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>

This change looks good. Will apply.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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) {