Re: [PATCH] improve diagnostic message about wrong redeclaration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 15/12/2019 16:28, Luc Van Oostenryck wrote:
> The current message is very long (in most cases the position
> of the previous declaration is past the 80th column) and,
> while saying that the types differ, doesn't show these types.
> 
> Change this by splitting the message in 2 parts:
> - first, on the current position, the main message
>   and the type of the current declaration.
> - then the type of the previous declaration on its
>   own position.

Hmm, this loses information and, thus, is not necessarily an
improvement. The first test, below, illustrates this ...

> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
> ---
> 
> This patch is also available at:
>  git://github.com/lucvoo/sparse-dev.git msg-wrong-redecl
> 
>  evaluate.c                   |  8 +++---
>  validation/c11-atomic.c      | 10 ++++++--
>  validation/function-redecl.c | 50 ++++++++++++++++++++++++++++--------
>  validation/restrict.c        | 10 ++++++--
>  validation/typedef-redef.c   |  5 +++-
>  5 files changed, 65 insertions(+), 18 deletions(-)
> 
> diff --git a/evaluate.c b/evaluate.c
> index 4d08956e984c..9ad7d234c789 100644
> --- a/evaluate.c
> +++ b/evaluate.c
> @@ -3380,9 +3380,11 @@ void check_duplicates(struct symbol *sym)
>  		declared++;
>  		typediff = type_difference(&sym->ctype, &next->ctype, 0, 0);
>  		if (typediff) {
> -			sparse_error(sym->pos, "symbol '%s' redeclared with different type (originally declared at %s:%d) - %s",
> -				show_ident(sym->ident),
> -				stream_name(next->pos.stream), next->pos.line, typediff);

... since 'typediff' is no longer displayed ...

> +			sparse_error(sym->pos, "symbol '%s' redeclared with different type:",
> +				show_ident(sym->ident));
> +			info(sym->pos, "   %s", show_typename(sym));
> +			info(next->pos, "note: previously declared as:");
> +			info(next->pos, "   %s", show_typename(next));
>  			return;
>  		}
>  	}
> diff --git a/validation/c11-atomic.c b/validation/c11-atomic.c
> index fc2c27ae9a65..0bf0317c8182 100644
> --- a/validation/c11-atomic.c
> +++ b/validation/c11-atomic.c
> @@ -69,8 +69,14 @@ void baz(void)
>   * check-command: sparse -Wno-decl $file
>   *
>   * check-error-start
> -c11-atomic.c:11:6: error: symbol 'f02' redeclared with different type (originally declared at c11-atomic.c:3) - incompatible argument 1 (different modifiers)
> -c11-atomic.c:12:6: error: symbol 'f03' redeclared with different type (originally declared at c11-atomic.c:4) - incompatible argument 1 (different modifiers)
> +c11-atomic.c:11:6: error: symbol 'f02' redeclared with different type:
> +c11-atomic.c:11:6:    void extern [addressable] [toplevel] f02( ... )
> +c11-atomic.c:3:6: note: previously declared as:
> +c11-atomic.c:3:6:    void extern [addressable] [toplevel] f02( ... )

... we lose the 'incompatible argument 1 (different modifiers)' text.
(which in this case helps the user understand what would otherwise be a
bit of a puzzle!) "redeclared with different type: A instead of A" :-D

ATB,
Ramsay Jones

> +c11-atomic.c:12:6: error: symbol 'f03' redeclared with different type:
> +c11-atomic.c:12:6:    void extern [addressable] [toplevel] f03( ... )
> +c11-atomic.c:4:6: note: previously declared as:
> +c11-atomic.c:4:6:    void extern [addressable] [toplevel] f03( ... )
>  c11-atomic.c:33:13: warning: incorrect type in assignment (different modifiers)
>  c11-atomic.c:33:13:    expected int *extern [assigned] puo
>  c11-atomic.c:33:13:    got int const *
> diff --git a/validation/function-redecl.c b/validation/function-redecl.c
> index 475f18e798f5..bb4d865fb465 100644
> --- a/validation/function-redecl.c
> +++ b/validation/function-redecl.c
> @@ -48,15 +48,45 @@ void arg_vararg(int a, ...) { }			/* check-should-fail */
>   * check-name: function-redecl
>   *
>   * check-error-start
> -function-redecl.c:5:6: error: symbol 'ret_type' redeclared with different type (originally declared at function-redecl.c:4) - different base types
> -function-redecl.c:9:11: error: symbol 'ret_const' redeclared with different type (originally declared at function-redecl.c:8) - different modifiers
> -function-redecl.c:13:13: error: symbol 'ret_as' redeclared with different type (originally declared at function-redecl.c:12) - different address spaces
> -function-redecl.c:17:12: error: symbol 'ret_mod' redeclared with different type (originally declared at function-redecl.c:16) - different modifiers
> -function-redecl.c:21:6: error: symbol 'arg_type' redeclared with different type (originally declared at function-redecl.c:20) - incompatible argument 1 (different base types)
> -function-redecl.c:29:6: error: symbol 'arg_as' redeclared with different type (originally declared at function-redecl.c:28) - incompatible argument 1 (different address spaces)
> -function-redecl.c:33:6: error: symbol 'arg_mod' redeclared with different type (originally declared at function-redecl.c:32) - incompatible argument 1 (different modifiers)
> -function-redecl.c:37:6: error: symbol 'arg_more_arg' redeclared with different type (originally declared at function-redecl.c:36) - different argument counts
> -function-redecl.c:41:6: error: symbol 'arg_less_arg' redeclared with different type (originally declared at function-redecl.c:40) - different argument counts
> -function-redecl.c:45:6: error: symbol 'arg_vararg' redeclared with different type (originally declared at function-redecl.c:44) - incompatible variadic arguments
> +function-redecl.c:5:6: error: symbol 'ret_type' redeclared with different type:
> +function-redecl.c:5:6:    void extern [addressable] [toplevel] ret_type( ... )
> +function-redecl.c:4:5: note: previously declared as:
> +function-redecl.c:4:5:    int extern [signed] [addressable] [toplevel] ret_type( ... )
> +function-redecl.c:9:11: error: symbol 'ret_const' redeclared with different type:
> +function-redecl.c:9:11:    int extern const [signed] [addressable] [toplevel] ret_const( ... )
> +function-redecl.c:8:5: note: previously declared as:
> +function-redecl.c:8:5:    int extern [signed] [addressable] [toplevel] ret_const( ... )
> +function-redecl.c:13:13: error: symbol 'ret_as' redeclared with different type:
> +function-redecl.c:13:13:    void <asn:1> *extern [addressable] [toplevel] ret_as( ... )
> +function-redecl.c:12:6: note: previously declared as:
> +function-redecl.c:12:6:    void *extern [addressable] [toplevel] ret_as( ... )
> +function-redecl.c:17:12: error: symbol 'ret_mod' redeclared with different type:
> +function-redecl.c:17:12:    void const *extern [addressable] [toplevel] ret_mod( ... )
> +function-redecl.c:16:6: note: previously declared as:
> +function-redecl.c:16:6:    void *extern [addressable] [toplevel] ret_mod( ... )
> +function-redecl.c:21:6: error: symbol 'arg_type' redeclared with different type:
> +function-redecl.c:21:6:    void extern [addressable] [toplevel] arg_type( ... )
> +function-redecl.c:20:6: note: previously declared as:
> +function-redecl.c:20:6:    void extern [addressable] [toplevel] arg_type( ... )
> +function-redecl.c:29:6: error: symbol 'arg_as' redeclared with different type:
> +function-redecl.c:29:6:    void extern [addressable] [toplevel] arg_as( ... )
> +function-redecl.c:28:6: note: previously declared as:
> +function-redecl.c:28:6:    void extern [addressable] [toplevel] arg_as( ... )
> +function-redecl.c:33:6: error: symbol 'arg_mod' redeclared with different type:
> +function-redecl.c:33:6:    void extern [addressable] [toplevel] arg_mod( ... )
> +function-redecl.c:32:6: note: previously declared as:
> +function-redecl.c:32:6:    void extern [addressable] [toplevel] arg_mod( ... )
> +function-redecl.c:37:6: error: symbol 'arg_more_arg' redeclared with different type:
> +function-redecl.c:37:6:    void extern [addressable] [toplevel] arg_more_arg( ... )
> +function-redecl.c:36:6: note: previously declared as:
> +function-redecl.c:36:6:    void extern [addressable] [toplevel] arg_more_arg( ... )
> +function-redecl.c:41:6: error: symbol 'arg_less_arg' redeclared with different type:
> +function-redecl.c:41:6:    void extern [addressable] [toplevel] arg_less_arg( ... )
> +function-redecl.c:40:6: note: previously declared as:
> +function-redecl.c:40:6:    void extern [addressable] [toplevel] arg_less_arg( ... )
> +function-redecl.c:45:6: error: symbol 'arg_vararg' redeclared with different type:
> +function-redecl.c:45:6:    void extern [addressable] [toplevel] arg_vararg( ... )
> +function-redecl.c:44:6: note: previously declared as:
> +function-redecl.c:44:6:    void extern [addressable] [toplevel] arg_vararg( ... )
>   * check-error-end
>   */
> diff --git a/validation/restrict.c b/validation/restrict.c
> index 80c437b01b24..698445d3cf62 100644
> --- a/validation/restrict.c
> +++ b/validation/restrict.c
> @@ -69,8 +69,14 @@ void baz(void)
>   * check-command: sparse -Wno-decl $file
>   *
>   * check-error-start
> -restrict.c:11:6: error: symbol 'f02' redeclared with different type (originally declared at restrict.c:3) - incompatible argument 1 (different modifiers)
> -restrict.c:12:6: error: symbol 'f03' redeclared with different type (originally declared at restrict.c:4) - incompatible argument 1 (different modifiers)
> +restrict.c:11:6: error: symbol 'f02' redeclared with different type:
> +restrict.c:11:6:    void extern [addressable] [toplevel] f02( ... )
> +restrict.c:3:6: note: previously declared as:
> +restrict.c:3:6:    void extern [addressable] [toplevel] f02( ... )
> +restrict.c:12:6: error: symbol 'f03' redeclared with different type:
> +restrict.c:12:6:    void extern [addressable] [toplevel] f03( ... )
> +restrict.c:4:6: note: previously declared as:
> +restrict.c:4:6:    void extern [addressable] [toplevel] f03( ... )
>  restrict.c:33:13: warning: incorrect type in assignment (different modifiers)
>  restrict.c:33:13:    expected void **extern [assigned] pup
>  restrict.c:33:13:    got void *const *
> diff --git a/validation/typedef-redef.c b/validation/typedef-redef.c
> index 3a60a773168a..d1535de9fa0b 100644
> --- a/validation/typedef-redef.c
> +++ b/validation/typedef-redef.c
> @@ -8,6 +8,9 @@ typedef long ko_t;
>   * check-name: typedef-redef
>   *
>   * check-error-start
> -typedef-redef.c:5:14: error: symbol 'ko_t' redeclared with different type (originally declared at typedef-redef.c:4) - different type sizes
> +typedef-redef.c:5:14: error: symbol 'ko_t' redeclared with different type:
> +typedef-redef.c:5:14:    long [usertype] ko_t
> +typedef-redef.c:4:14: note: previously declared as:
> +typedef-redef.c:4:14:    int [usertype] ko_t
>   * check-error-end
>   */
> 
> base-commit: f934193608415cff796694b5500f95e7b2e0fd17
> 



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux