fixed the recent bug that disabled the local structure initialisation.
[fw/sdcc] / src / SDCCglue.c
index 2657dbfaf0c8409f9ea28cf7d7f47e93a7aa9c20..4352a468388b973e5111c9ad8e4cf95bb9682641 100644 (file)
@@ -99,6 +99,11 @@ aopLiteralLong (value * val, int offset, int size)
        }
        fl;
 
+       if (!val) {
+         // assuming we have been warned before
+         val=constVal("0");
+       }
+
        /* if it is a float then it gets tricky */
        /* otherwise it is fairly simple */
        if (!IS_FLOAT (val->type)) {
@@ -192,7 +197,7 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
           (sym->_isparm && !IS_REGPARM (sym->etype))) &&
          addPublics &&
          !IS_STATIC (sym->etype) &&
-         (sym->used || sym->fbody))
+          (IS_FUNC(sym->type) ? (sym->used || sym->fbody) : 1))
        {
          addSetHead (&publics, sym);
        }
@@ -245,25 +250,30 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
          it is a global variable */
       if (sym->ival && sym->level == 0)
        {
-         if (IS_AGGREGATE (sym->type))
+         if (IS_AGGREGATE (sym->type)) {
            ival = initAggregates (sym, sym->ival, NULL);
-         else
+         } else {
            ival = newNode ('=', newAst_VALUE (symbolVal (sym)),
                     decorateType (resolveSymbols (list2expr (sym->ival))));
+         }
          codeOutFile = statsg->oFile;
          allocInfo = 0;
 
          // set ival's lineno to where the symbol was defined
-         ival->lineno=sym->lineDef;
-
+         if (ival) ival->lineno=sym->lineDef;
          eBBlockFromiCode (iCodeFromAst (ival));
          allocInfo = 1;
 
-         /* if the ival was a symbol, delete it from its segment */
-         if (symIval=AST_SYMBOL(sym->ival->init.node)) {
+         /* if the ival is a symbol assigned to an aggregate,
+            (bug #458099 -> #462479)
+            we don't need it anymore, so delete it from its segment */
+         if (IS_AST_SYM_VALUE(sym->ival->init.node) &&
+             IS_AGGREGATE (sym->type) ) {
+           symIval=AST_SYMBOL(sym->ival->init.node);
            segment = SPEC_OCLS (symIval->etype);
            deleteSetItem (&segment->syms, symIval);
          }
+
          sym->ival = NULL;
        }
     }
@@ -372,7 +382,7 @@ initPointer (initList * ilist)
                return val;
        }
  wrong:
-       werror (E_INIT_WRONG);
+       werror (W_INIT_WRONG);
        return NULL;
 
 }
@@ -866,7 +876,7 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
 
   /* check the type      */
   if (compareType (type, val->type) == 0)
-    werror (E_INIT_WRONG);
+    werror (W_INIT_WRONG);
 
   /* if val is literal */
   if (IS_LITERAL (val->etype))