[hackers] [scc] Detect redefinition of external symbols. || Roberto E. Vargas Caballero
commit ef6b767b7d3ea2088f8652fe5ea76117661edef0
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sat Jan 9 21:30:52 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sat Jan 9 21:30:52 2016 +0100
Detect redefinition of external symbols.
An external declaration is a tentative definition, and a file can contain
several tentative definition for a symbol, but when an external
declaration also has an initializer, it is a definition. Due to the order
in the if this error was not catched.
diff --git a/cc1/expr.c b/cc1/expr.c
index ccb9dae..88c35eb 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -1247,10 +1247,13 @@ initializer(Symbol *sym, Type *tp, int nelem)
np = assignop(OINIT, varnode(sym), np);
- if ((flags & (ISGLOBAL|ISLOCAL|ISPRIVATE)) != 0) {
+ if (flags & ISDEFINED) {
+ errorp("redeclaration of '%s'", sym->name);
+ } else if ((flags & (ISGLOBAL|ISLOCAL|ISPRIVATE)) != 0) {
if (!np->right->constant)
errorp("initializer element is not constant");
emit(OINIT, np);
+ sym->flags |= ISDEFINED;
} else if ((flags & (ISEXTERN|ISTYPEDEF)) != 0) {
errorp("'%s' has both '%s' and initializer",
sym->name, (flags&ISEXTERN) ? "extern" : "typedef");
Received on Sat Jan 09 2016 - 21:33:37 CET
This archive was generated by hypermail 2.3.0
: Sat Jan 09 2016 - 21:36:29 CET