* 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
+2004-05-14 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
+
+ * 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 <epetrich AT ivorytower.norman.ok.us>
* src/SDCCdwarf2.c (dwMatchTypes): structs must have matching
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 */
)
{
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;
#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[];
--- /dev/null
+/* bug-751703.c
+
+ If test_index is char, loses high bit when indexes table
+ workaround is to use [(unsigned int) test_index]
+ */
+#include <testfwk.h>
+
+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);
+}