temp fix for genArrayInit
[fw/sdcc] / src / ds390 / ralloc.c
index bd2ee321bce9945ef35f9a1b01912bbac1e85462..f4f837b2423ebcd879c02d4da3bc378e30db397e 100644 (file)
@@ -484,7 +484,8 @@ createStackSpil (symbol * sym)
      we need to allocate this on the stack : this is really a
      hack!! but cannot think of anything better at this time */
 
-  if (sprintf (slocBuffer, "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
+  if (SNPRINTF (slocBuffer, sizeof(slocBuffer), 
+               "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
     {
       fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
               __FILE__, __LINE__);
@@ -643,9 +644,10 @@ selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
   if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
     {
       sym = leastUsedLR (selectS);
-      strcpy (sym->rname, (sym->usl.spillLoc->rname[0] ?
-                          sym->usl.spillLoc->rname :
-                          sym->usl.spillLoc->name));
+      strncpyz (sym->rname,
+               sym->usl.spillLoc->rname[0] ?
+                  sym->usl.spillLoc->rname : sym->usl.spillLoc->name,
+               sizeof(sym->rname));
       sym->spildir = 1;
       /* mark it as allocation required */
       sym->usl.spillLoc->allocreq++;
@@ -861,6 +863,9 @@ static regs *getRegPtrNoSpil()
     return reg;
 
   assert(0);
+
+  /* just to make the compiler happy */
+  return 0;
 }
 
 /*-----------------------------------------------------------------*/
@@ -878,6 +883,9 @@ static regs *getRegGprNoSpil()
       return reg;
 
   assert(0);
+
+  /* just to make the compiler happy */
+  return 0;
 }
 
 /*-----------------------------------------------------------------*/
@@ -1430,7 +1438,8 @@ static void fillGaps()
                    bitVectBitValue(_G.totRegAssigned,i) == 0) /* and are still assigned to registers */
                    continue ;
                
-               assert (clr = hTabItemWithKey(liveRanges,i));
+               clr = hTabItemWithKey(liveRanges,i);
+               assert(clr);
                
                /* mark these registers as used */
                for (k = 0 ; k < clr->nRegs ; k++ ) 
@@ -1676,14 +1685,17 @@ rematStr (symbol * sym)
   char *s = buffer;
   iCode *ic = sym->rematiCode;
 
+  *s = 0;
+    
   while (1)
     {
 
       /* if plus or minus print the right hand side */
       if (ic->op == '+' || ic->op == '-')
        {
-         sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
-                  ic->op);
+         SNPRINTF (s, sizeof(buffer) - strlen(buffer), 
+                   "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
+                   ic->op);
          s += strlen (s);
          ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
          continue;
@@ -1694,7 +1706,8 @@ rematStr (symbol * sym)
          continue;
       }
       /* we reached the end */
-      sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
+      SNPRINTF (s, sizeof(buffer) - strlen(buffer), 
+               "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
       break;
     }
 
@@ -1748,7 +1761,8 @@ regTypeNum ()
              !IS_BITVAR (sym->etype))
            {
              /* and that pointer is remat in data space */
-             if (OP_SYMBOL (IC_LEFT (ic))->remat &&
+             if (IS_SYMOP (IC_LEFT (ic)) &&
+                 OP_SYMBOL (IC_LEFT (ic))->remat &&
                  !IS_CAST_ICODE(OP_SYMBOL (IC_LEFT (ic))->rematiCode) &&
                  DCL_TYPE (aggrToPtr (operandType(IC_LEFT(ic)), FALSE)) == POINTER)
                {
@@ -1757,7 +1771,7 @@ regTypeNum ()
                  symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
                  psym->type = sym->type;
                  psym->etype = sym->etype;
-                 strcpy (psym->rname, psym->name);
+                 strncpyz (psym->rname, psym->name, sizeof(psym->rname));
                  sym->isspilt = 1;
                  sym->usl.spillLoc = psym;
                  continue;
@@ -2021,7 +2035,7 @@ pack:
   remiCodeFromeBBlock (ebp, ic);
   bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
   hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
-  OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+  OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
   return 1;
 
 }
@@ -2130,6 +2144,8 @@ packRegsForSupport (iCode * ic, eBBlock * ebp)
        sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key);
       }
 
+      wassert(IS_SYMOP(IC_LEFT (ic)));
+      wassert(IS_SYMOP(IC_RIGHT (dic)));
       IC_LEFT (ic)->operand.symOperand =
        IC_RIGHT (dic)->operand.symOperand;
       OP_SYMBOL(IC_LEFT(ic))->liveTo = ic->seq;
@@ -2167,6 +2183,8 @@ right:
        sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key);
       }
 
+      wassert(IS_SYMOP(IC_RIGHT (ic)));
+      wassert(IS_SYMOP(IC_RIGHT (dic)));       
       IC_RIGHT (ic)->operand.symOperand =
        IC_RIGHT (dic)->operand.symOperand;
       IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
@@ -2610,6 +2628,7 @@ packForPush (iCode * ic, eBBlock * ebp)
          if (bitVectBitValue(dbv,lic->key)) return ;
   }
   /* make sure they have the same type */
+  if (IS_SPEC(operandType(IC_LEFT(ic))))
   {
     sym_link *itype=operandType(IC_LEFT(ic));
     sym_link *ditype=operandType(IC_RIGHT(dic));
@@ -2751,20 +2770,22 @@ packRegisters (eBBlock * ebp)
        }
 
       /* mark the pointer usages */
-      if (POINTER_SET (ic))
+      if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic)))
        OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
 
-      if (POINTER_GET (ic))
+      if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic)))
        OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
 
       if (ic->op == RETURN && IS_SYMOP (IC_LEFT(ic)))
          OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
 
       if (ic->op == RECEIVE && ic->argreg == 1 &&
+         IS_SYMOP (IC_RESULT (ic)) &&
          getSize (operandType(IC_RESULT(ic))) <= 3)
          OP_SYMBOL (IC_RESULT(ic))->uptr = 1;
 
       if (ic->op == SEND && ic->argreg == 1 &&
+         IS_SYMOP(IC_LEFT(ic)) &&
          getSize (aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) <= 3)
          OP_SYMBOL (IC_LEFT(ic))->uptr = 1;
 
@@ -2833,6 +2854,7 @@ packRegisters (eBBlock * ebp)
          one and right is not in far space */
       if (POINTER_SET (ic) &&
          !isOperandInFarSpace (IC_RIGHT (ic)) &&
+         IS_SYMOP (IC_RESULT (ic)) &&
          !OP_SYMBOL (IC_RESULT (ic))->remat &&
          !IS_OP_RUONLY (IC_RIGHT (ic)) &&
          getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1) {
@@ -2843,6 +2865,7 @@ packRegisters (eBBlock * ebp)
       /* if pointer get */
       if (POINTER_GET (ic) &&
          !isOperandInFarSpace (IC_RESULT (ic)) &&
+         IS_SYMOP (IC_LEFT (ic)) &&
          !OP_SYMBOL (IC_LEFT (ic))->remat &&
          !IS_OP_RUONLY (IC_RESULT (ic)) &&
          getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1) {
@@ -2875,7 +2898,7 @@ packRegisters (eBBlock * ebp)
                      remiCodeFromeBBlock (ebp, ic);
                      bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
                      hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
-                     OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+                     OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
                      ic = ic->prev;
                    }
                  else
@@ -2898,7 +2921,7 @@ packRegisters (eBBlock * ebp)
                      remiCodeFromeBBlock (ebp, ic);
                      bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
                      hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
-                     OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+                     OP_DEFS(IC_RESULT (dic))=bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
                      ic = ic->prev;
                    }
                }
@@ -2995,7 +3018,8 @@ ds390_assignRegisters (eBBlock ** ebbs, int count)
   createRegMask (ebbs, count);
 
   /* redo that offsets for stacked automatic variables */
-  redoStackOffsets ();
+  if (currFunc)
+    redoStackOffsets ();
 
   if (options.dump_rassgn) {
     dumpEbbsToFileExt (DUMP_RASSGN, ebbs, count);