scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit baebb5ab3963d5383344290a1d4df0c29cf967b6
parent 346e337cbefde594d18942b63686cee9680ee82d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 26 Feb 2017 11:59:54 +0100

[cc1] Fix install()

Install() was only checking if the symbol to install was already
defined before creating a new symbol, but it fails in the case of
functions, where you can have a parameter with the same name than
the function. In this case the parameter is installed before the
function symbol is installed.

Diffstat:
Mcc1/symbol.c | 2+-
Atests/execute/0120-funpar.c | 12++++++++++++
Mtests/execute/scc-tests.lst | 1+
3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -296,7 +296,7 @@ lookup(int ns, char *name, int alloc) Symbol * install(int ns, Symbol *sym) { - if (sym->flags & SDECLARED) { + if (sym->flags & SDECLARED || sym->ctx != curctx) { if (sym->ctx == curctx && ns == sym->ns) return NULL; sym = newsym(ns, sym->name); diff --git a/tests/execute/0120-funpar.c b/tests/execute/0120-funpar.c @@ -0,0 +1,12 @@ + +int +f(int f) +{ + return f; +} + +int +main() +{ + return f(0); +} diff --git a/tests/execute/scc-tests.lst b/tests/execute/scc-tests.lst @@ -110,3 +110,4 @@ 0117-pointarith.c 0118-voidmain.c 0119-macrostr.c +0120-funpar.c