Fix error messages which could cause SEGV on Solaris
[fw/sdcc] / src / SDCCmem.c
index bacebcfb2ffef64635c1e99b3db5db393ce1a006..dece30c26ef3fe7a78237ed3aaecb0b523673e31 100644 (file)
@@ -307,7 +307,9 @@ allocGlobal (symbol * sym)
              "%s%s", port->fun_prefix, sym->name);
 
   /* add it to the operandKey reset */
-  addSet (&operKeyReset, sym);
+  if (!isinSet (operKeyReset, sym)) {
+    addSet(&operKeyReset, sym);
+  }
 
   /* if this is a literal e.g. enumerated type */
   /* put it in the data segment & do nothing   */
@@ -349,14 +351,6 @@ allocGlobal (symbol * sym)
       SPEC_SCLS (sym->etype) == S_SBIT)
     {
 
-      /* if both absolute address & initial  */
-      /* value specified then error        */
-      if (IS_ABSOLUTE (sym->etype) && sym->ival)
-       {
-         werror (E_SFR_INIT, sym->name);
-         sym->ival = NULL;
-       }
-
       SPEC_OCLS (sym->etype) =
        (SPEC_SCLS (sym->etype) == S_SFR ? sfr : sfrbit);
 
@@ -569,8 +563,9 @@ deallocParms (value * val)
       if (!lval->sym->isref)
        {
          lval->sym->allocreq = 0;
-         werror (W_NO_REFERENCE, currFunc->name,
-                 "function argument", lval->sym->name);
+           werror (W_NO_REFERENCE, 
+                   currFunc ? currFunc->name : "(unknown)",
+                   "function argument", lval->sym->name);
        }
 
       /* move the rname if any to the name for both val & sym */
@@ -586,7 +581,9 @@ deallocParms (value * val)
          addSym (SymbolTab, lval->sym, lval->sym->name,
                  lval->sym->level, lval->sym->block, 1);
          lval->sym->_isparm = 1;
-         addSet (&operKeyReset, lval->sym);
+         if (!isinSet (operKeyReset, lval->sym)) {
+           addSet(&operKeyReset, lval->sym);
+         }
        }
 
     }
@@ -679,15 +676,6 @@ allocLocal (symbol * sym)
   if (SPEC_SCLS (sym->etype) == S_SFR ||
       SPEC_SCLS (sym->etype) == S_SBIT)
     {
-
-      /* if both absolute address & initial  */
-      /* value specified then error        */
-      if (IS_ABSOLUTE (sym->etype) && sym->ival)
-       {
-         werror (E_SFR_INIT, sym->name);
-         sym->ival = NULL;
-       }
-
       SPEC_OCLS (sym->etype) =
        (SPEC_SCLS (sym->etype) == S_SFR ? sfr : sfrbit);
 
@@ -722,11 +710,11 @@ allocLocal (symbol * sym)
      will remove and put into the 'data' segment if required after 
      overlay  analysis has been done */
   if (options.model == MODEL_SMALL) {
-    SPEC_OCLS (sym->etype) = 
-      (options.noOverlay ? port->mem.default_local_map
-       : overlay);
+      SPEC_OCLS (sym->etype) = 
+       (options.noOverlay ? port->mem.default_local_map
+        : overlay);
   } else {
-    SPEC_OCLS (sym->etype) = port->mem.default_local_map;
+      SPEC_OCLS (sym->etype) = port->mem.default_local_map;
   }
   allocIntoSeg (sym);
 }
@@ -754,7 +742,8 @@ deallocLocal (symbol * csym)
        }
       /* if not used give a warning */
       if (!sym->isref && !IS_STATIC (sym->etype))
-       werror (W_NO_REFERENCE, currFunc->name,
+       werror (W_NO_REFERENCE, 
+               currFunc ? currFunc->name : "(unknown)",
                "local variable", sym->name);
       /* now delete it from the symbol table */
       deleteSym (SymbolTab, sym, sym->name);
@@ -842,9 +831,8 @@ allocVariables (symbol * symChain)
       /* then args  processing  */
       if (funcInChain (csym->type))
        {
-#if 1 // jwk: TODO should have been done already in addDecl() (oclass????)
          processFuncArgs (csym);
-#endif
+
          /* if register bank specified then update maxRegBank */
          if (maxRegBank < FUNC_REGBANK (csym->type))
            maxRegBank = FUNC_REGBANK (csym->type);
@@ -974,18 +962,6 @@ redoStackOffsets (void)
       xsPtr += size;
     }
 
-  /* if the debug option is set then output the
-     symbols to the map file */
-  if (options.debug)
-    {
-      for (sym = setFirstItem (istack->syms); sym;
-          sym = setNextItem (istack->syms))
-       cdbSymbol (sym, cdbFile, FALSE, FALSE);
-
-      for (sym = setFirstItem (xstack->syms); sym;
-          sym = setNextItem (xstack->syms))
-       cdbSymbol (sym, cdbFile, FALSE, FALSE);
-    }
 }
 
 /*-----------------------------------------------------------------*/
@@ -1015,6 +991,7 @@ printAllocInfoSeg (memmap * map, symbol * func, FILE * of)
       if (!sym->allocreq && sym->reqv)
        {
          int i;
+
          sym = OP_SYMBOL (sym->reqv);
          fprintf (of, "registers ");
          for (i = 0; i < 4 && sym->regs[i]; i++)
@@ -1108,9 +1085,12 @@ doOverlays (eBBlock ** ebbs, int count)
 void 
 printAllocInfo (symbol * func, FILE * of)
 {
+  if (!func)
+       return;
+    
   if (!of)
     of = stdout;
-
+    
   /* must be called after register allocation is complete */
   fprintf (of, ";------------------------------------------------------------\n");
   fprintf (of, ";Allocation info for local variables in function '%s'\n", func->name);