From 0ec1c5ce1015c8068d60bd2f21eee32875042a18 Mon Sep 17 00:00:00 2001 From: epetrich Date: Fri, 14 May 2004 20:35:21 +0000 Subject: [PATCH] * src/SDCCsymt.h: added IS_AUTO(symbol) test macro * src/SDCCopt.c (isLocalWithoutDef), * src/SDCCicode.c (operandFromSymbol): use the IS_AUTO test macro which adds a !IS_EXTERN codition. Fixes bugs #877426 and #751703. (credit to Maarten Brock for patch #949363, on which this is based) * support/regression/tests/bug-751703.c: some test cases of extern used within inner scopes. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3307 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 10 +++++++ src/SDCCicode.c | 17 ++++++------ src/SDCCopt.c | 5 +++- src/SDCCsymt.h | 3 ++ support/regression/tests/bug-751703.c | 40 +++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 support/regression/tests/bug-751703.c diff --git a/ChangeLog b/ChangeLog index b4bcdbd5..7856e372 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-05-14 Erik Petrich + + * src/SDCCsymt.h: added IS_AUTO(symbol) test macro + * src/SDCCopt.c (isLocalWithoutDef), + * src/SDCCicode.c (operandFromSymbol): use the IS_AUTO test macro + which adds a !IS_EXTERN codition. Fixes bugs #877426 and #751703. + (credit to Maarten Brock for patch #949363, on which this is based) + * support/regression/tests/bug-751703.c: some test cases of extern used + within inner scopes. + 2004-05-14 Erik Petrich * src/SDCCdwarf2.c (dwMatchTypes): structs must have matching diff --git a/src/SDCCicode.c b/src/SDCCicode.c index fdc27804..9b841e52 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1527,16 +1527,15 @@ operandFromSymbol (symbol * sym) ok = 0; if (!IS_AGGREGATE (sym->type) && /* not an aggregate */ - !IS_FUNC (sym->type) && /* not a function */ - !sym->_isparm && /* not a parameter */ - sym->level && /* is a local variable */ - !sym->addrtaken && /* whose address has not been taken */ - !sym->reqv && /* does not already have a reg equivalence */ + !IS_FUNC (sym->type) && /* not a function */ + !sym->_isparm && /* not a parameter */ + IS_AUTO (sym) && /* is a local auto variable */ + !sym->addrtaken && /* whose address has not been taken */ + !sym->reqv && /* does not already have a reg equivalence */ !IS_VOLATILE (sym->etype) && /* not declared as volatile */ - !IS_STATIC (sym->etype) && /* and not declared static */ - !sym->islbl && /* not a label */ - ok && /* farspace check */ - !IS_BITVAR (sym->etype) /* not a bit variable */ + !sym->islbl && /* not a label */ + ok && /* farspace check */ + !IS_BITVAR (sym->etype) /* not a bit variable */ ) { diff --git a/src/SDCCopt.c b/src/SDCCopt.c index 4e9c2a7b..e39db1b2 100644 --- a/src/SDCCopt.c +++ b/src/SDCCopt.c @@ -611,12 +611,15 @@ convertToFcall (eBBlock ** ebbs, int count) static int isLocalWithoutDef (symbol * sym) { + if (!IS_AUTO (sym)) + return 0; + #if 0 if (!sym->level) return 0; if (IS_STATIC (sym->etype)) return 0; - + #endif if (IS_VOLATILE (sym->type)) return 0; diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 394c4387..259ad9d4 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -467,6 +467,9 @@ extern sym_link *validateLink(sym_link *l, #define IS_CODE(x) (IS_SPEC(x) && SPEC_SCLS(x) == S_CODE) #define IS_REGPARM(x) (IS_SPEC(x) && SPEC_REGPARM(x)) +/* symbol check macros */ +#define IS_AUTO(x) (x->level && !IS_STATIC(x->etype) && !IS_EXTERN(x->etype)) + /* forward declaration for the global vars */ extern bucket *SymbolTab[]; extern bucket *StructTab[]; diff --git a/support/regression/tests/bug-751703.c b/support/regression/tests/bug-751703.c new file mode 100644 index 00000000..49f84e76 --- /dev/null +++ b/support/regression/tests/bug-751703.c @@ -0,0 +1,40 @@ +/* bug-751703.c + + If test_index is char, loses high bit when indexes table + workaround is to use [(unsigned int) test_index] + */ +#include + +int x = 1; +int y = 2; +int z = 0; + +static void +addxy(void) +{ + extern int x, y, z; + z = x+y; +} + +static void +times10x(void) +{ + unsigned char x; + + z = 0; + for (x=0; x<10; x++) + { + extern int x; /* bind to the global x */ + z += x; + } +} + +static void +testExternDeadCode(void) +{ + ASSERT(z == 0); + addxy(); + ASSERT(z == 3); + times10x(); + ASSERT(z == 10); +} -- 2.30.2