* src/SDCCsymt.h: added IS_AUTO(symbol) test macro
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 14 May 2004 20:35:21 +0000 (20:35 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 14 May 2004 20:35:21 +0000 (20:35 +0000)
* 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
src/SDCCicode.c
src/SDCCopt.c
src/SDCCsymt.h
support/regression/tests/bug-751703.c [new file with mode: 0644]

index b4bcdbd53c1cff158ae102ff4d593c46500064b7..7856e37251918d3c89719052a12e658a2e82cd60 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+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
index fdc278044186d9e437ab8ebad1a51941928d0a66..9b841e5219bc278fc546397106634b626160a5ad 100644 (file)
@@ -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 */
     )
     {                                   
 
index 4e9c2a7be560647efde1841a42b6a0a9efcf780c..e39db1b264f7d26250964a1463eeabb573ffc8a1 100644 (file)
@@ -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;
   
index 394c4387b232b4cb932058ed80f3bd992c2f41f9..259ad9d46b037702e960a27ec3608939e08b0e59 100644 (file)
@@ -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 (file)
index 0000000..49f84e7
--- /dev/null
@@ -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 <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);
+}