aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-11-16 15:52:31 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-12-15 21:01:48 +0100
commit2094267c7d36d8696897c509558fc63e8a695765 (patch)
tree2e2f8e0b5648a988a18d23f164b40b6fb38ed016
parentf934193608415cff796694b5500f95e7b2e0fd17 (diff)
downloadsparse-2094267c7d36d8696897c509558fc63e8a695765.tar.gz
improve diagnostic message about wrong redeclaration
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. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--evaluate.c8
-rw-r--r--validation/c11-atomic.c10
-rw-r--r--validation/function-redecl.c50
-rw-r--r--validation/restrict.c10
-rw-r--r--validation/typedef-redef.c5
5 files changed, 65 insertions, 18 deletions
diff --git a/evaluate.c b/evaluate.c
index 4d08956e..8b1ae863 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);
+ sparse_error(sym->pos, "symbol '%s' redeclared with different type (%s):",
+ show_ident(sym->ident), typediff);
+ 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 fc2c27ae..17720861 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 (incompatible argument 1 (different modifiers)):
+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( ... )
+c11-atomic.c:12:6: error: symbol 'f03' redeclared with different type (incompatible argument 1 (different modifiers)):
+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 475f18e7..03151359 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 (different base types):
+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 (different modifiers):
+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 (different address spaces):
+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 (different modifiers):
+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 (incompatible argument 1 (different base types)):
+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 (incompatible argument 1 (different address spaces)):
+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 (incompatible argument 1 (different modifiers)):
+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 (different argument counts):
+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 (different argument counts):
+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 (incompatible variadic arguments):
+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 80c437b0..d7cd8ad9 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 (incompatible argument 1 (different modifiers)):
+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 (incompatible argument 1 (different modifiers)):
+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 3a60a773..f90f266a 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 (different type sizes):
+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
*/