[PATCH 3/3] fix: warn on typedef redefinition

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

 



check_duplicates() verifies that symbols are not redefined and
warns if they are.

However, this function is only called at evaluation-time and
then only for symbols corresponding to objects and functions.
So, typedefs can be redefined without any kind of diagnostic.

Fix this by calling check_duplicates() at parsing time on typedefs.

Note: this is C11's semantic or GCC's C89/C99 in non-pedantic mode.

Reported-by: Matthew Wilcox <willy@xxxxxxxxxxxxx>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 parse.c                    | 4 ++++
 validation/typedef-redef.c | 1 -
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/parse.c b/parse.c
index bb504d21a..08515c519 100644
--- a/parse.c
+++ b/parse.c
@@ -2888,6 +2888,10 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
 		if (decl->same_symbol) {
 			decl->definition = decl->same_symbol->definition;
 			decl->op = decl->same_symbol->op;
+			if (is_typedef) {
+				// TODO: handle -std=c89 --pedantic
+				check_duplicates(decl);
+			}
 		}
 
 		if (!match_op(token, ','))
diff --git a/validation/typedef-redef.c b/validation/typedef-redef.c
index b719ff9a4..3a60a7731 100644
--- a/validation/typedef-redef.c
+++ b/validation/typedef-redef.c
@@ -6,7 +6,6 @@ typedef long ko_t;
 
 /*
  * check-name: typedef-redef
- * check-known-to-fail
  *
  * 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
-- 
2.16.3

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



[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