fixed the 'char *s="hallo";' initialization bug
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 25 Dec 2001 13:08:16 +0000 (13:08 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 25 Dec 2001 13:08:16 +0000 (13:08 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1745 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCglue.c
src/SDCCmem.c

index e1e8f3232069203868c5db506bb60b0e94e1d9c8..748f6848b1f95b9984461838f145ea2d5bb9da3a 100644 (file)
@@ -176,7 +176,6 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
     {
       symbol *newSym=NULL;
 
-
       /* if extern then add it into the extern list */
       if (IS_EXTERN (sym->etype))
        {
@@ -236,17 +235,17 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
          // create a new "XINIT (CODE)" symbol, that will be emitted later
          newSym=copySymbol (sym);
          SPEC_OCLS(newSym->etype)=xinit;
-         sprintf (newSym->name, "_xinit_%s", sym->name);
-         sprintf (newSym->rname,"_xinit_%s", sym->rname);
+         sprintf (newSym->name, "__xinit_%s", sym->name);
+         sprintf (newSym->rname,"__xinit_%s", sym->rname);
          SPEC_CONST(newSym->etype)=1;
-         //SPEC_STAT(newSym->etype)=1;
-         addSym (SymbolTab, newSym, newSym->name, 0, 0, 1);
-         
+         SPEC_STAT(newSym->etype)=1;
+         //addSym (SymbolTab, newSym, newSym->name, 0, 0, 1);
+         if (!IS_AGGREGATE(sym->type)) {
+           resolveIvalSym(newSym->ival);
+         }
          // add it to the "XINIT (CODE)" segment
          addSet(&xinit->syms, newSym);
-
-         //fprintf (stderr, "moved %s from xdata to xidata\n", sym->rname);
-         
+         sym->ival=NULL;
        } else {
          if (IS_AGGREGATE (sym->type)) {
            ival = initAggregates (sym, sym->ival, NULL);
@@ -287,7 +286,7 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
        /* 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 (sym->ival->type == INIT_NODE &&
+       if (sym->ival && sym->ival->type == INIT_NODE &&
            IS_AST_SYM_VALUE(sym->ival->init.node) &&
            IS_AGGREGATE (sym->type) ) {
          symIval=AST_SYMBOL(sym->ival->init.node);
@@ -310,24 +309,20 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                   SPEC_ADDR (sym->etype));
        }
       else {
-         if (newSym) {
-             // this has been moved to another segment
-         } else {
-             int size = getSize (sym->type);
-             if (size==0) {
-                 werror(E_UNKNOWN_SIZE,sym->name);
-             }
-             /* allocate space */
-             if (options.debug) {
-                 fprintf (map->oFile, "==.\n");
-             }
-             if (IS_STATIC (sym->etype))
-                 tfprintf (map->oFile, "!slabeldef\n", sym->rname);
-             else
-                 tfprintf (map->oFile, "!labeldef\n", sym->rname);           
-             tfprintf (map->oFile, "\t!ds\n", 
-                       (unsigned int)  size & 0xffff);
-         }
+       int size = getSize (sym->type);
+       if (size==0) {
+         werror(E_UNKNOWN_SIZE,sym->name);
+       }
+       /* allocate space */
+       if (options.debug) {
+         fprintf (map->oFile, "==.\n");
+       }
+       if (IS_STATIC (sym->etype))
+         tfprintf (map->oFile, "!slabeldef\n", sym->rname);
+       else
+         tfprintf (map->oFile, "!labeldef\n", sym->rname);           
+       tfprintf (map->oFile, "\t!ds\n", 
+                 (unsigned int)  size & 0xffff);
       }
     }
 }
index f369a04fda8efd3580aff192be37d82f3efbe3e3..da118602a3f1fcc5d481a5af9dffbb32ba1aae86 100644 (file)
@@ -404,12 +404,12 @@ allocGlobal (symbol * sym)
 
   if (SPEC_SCLS (sym->etype) == S_XDATA)
     {
-      SPEC_OCLS (sym->etype) = xdata;
       // should we move this to the initialized data segment?
       if (port->genXINIT &&
          sym->ival && (sym->level==0) && !SPEC_ABSA(sym->etype)) {
        SPEC_OCLS(sym->etype)=xidata;
-       addSet(&xidata->syms, sym);
+      } else {
+       SPEC_OCLS (sym->etype) = xdata;
       }
       allocIntoSeg (sym);
       return;