Browse Source

* backported fix for 4277
* typedconsts are always written to datasegment
to prevent mixing arrayindexes with string data

git-svn-id: branches/fixes_2_0@900 -

peter 20 years ago
parent
commit
2a9ae912ff
6 changed files with 42 additions and 45 deletions
  1. 1 0
      .gitattributes
  2. 0 37
      compiler/ncgutil.pas
  3. 0 1
      compiler/pdecl.pas
  4. 0 2
      compiler/pdecvar.pas
  5. 30 5
      compiler/ptconst.pas
  6. 11 0
      tests/webtbs/tw4277.pp

+ 1 - 0
.gitattributes

@@ -5999,6 +5999,7 @@ tests/webtbs/tw4240.pp svneol=native#text/plain
 tests/webtbs/tw4247.pp svneol=native#text/plain
 tests/webtbs/tw4247.pp svneol=native#text/plain
 tests/webtbs/tw4253.pp svneol=native#text/plain
 tests/webtbs/tw4253.pp svneol=native#text/plain
 tests/webtbs/tw4260.pp svneol=native#text/plain
 tests/webtbs/tw4260.pp svneol=native#text/plain
+tests/webtbs/tw4277.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 0 - 37
compiler/ncgutil.pas

@@ -103,7 +103,6 @@ interface
     procedure new_exception(list:TAAsmoutput;const t:texceptiontemps;exceptlabel:tasmlabel);
     procedure new_exception(list:TAAsmoutput;const t:texceptiontemps;exceptlabel:tasmlabel);
     procedure free_exception(list:TAAsmoutput;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
     procedure free_exception(list:TAAsmoutput;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
 
 
-    procedure insertconstdata(sym : ttypedconstsym);
     procedure insertbssdata(sym : tglobalvarsym);
     procedure insertbssdata(sym : tglobalvarsym);
 
 
     procedure gen_alloc_symtable(list:TAAsmoutput;st:tsymtable);
     procedure gen_alloc_symtable(list:TAAsmoutput;st:tsymtable);
@@ -1905,42 +1904,6 @@ implementation
                                Const Data
                                Const Data
 ****************************************************************************}
 ****************************************************************************}
 
 
-    procedure insertconstdata(sym : ttypedconstsym);
-    { this does not affect the local stack space, since all
-      typed constansts and initialized variables are always
-      put in the .data / .rodata section
-    }
-      var
-        storefilepos : tfileposinfo;
-        curconstsegment : taasmoutput;
-        l : longint;
-      begin
-        storefilepos:=aktfilepos;
-        aktfilepos:=sym.fileinfo;
-        if sym.is_writable then
-          curconstsegment:=datasegment
-        else
-          curconstsegment:=consts;
-        l:=sym.getsize;
-        { insert cut for smartlinking or alignment }
-        maybe_new_object_file(curconstSegment);
-        new_section(curconstSegment,sec_rodata,lower(sym.mangledname),const_align(l));
-{$ifdef GDB}
-        if (cs_debuginfo in aktmoduleswitches) then
-          sym.concatstabto(curconstSegment);
-{$endif GDB}
-        if (sym.owner.symtabletype=globalsymtable) or
-           maybe_smartlink_symbol or
-           (assigned(current_procinfo) and
-            (po_inline in current_procinfo.procdef.procoptions)) or
-           DLLSource then
-          curconstSegment.concat(Tai_symbol.Createname_global(sym.mangledname,AT_DATA,l))
-        else
-          curconstSegment.concat(Tai_symbol.Createname(sym.mangledname,AT_DATA,l));
-        aktfilepos:=storefilepos;
-      end;
-
-
     procedure insertbssdata(sym : tglobalvarsym);
     procedure insertbssdata(sym : tglobalvarsym);
       var
       var
         l,varalign : longint;
         l,varalign : longint;

+ 0 - 1
compiler/pdecl.pas

@@ -204,7 +204,6 @@ implementation
                    sym:=ttypedconstsym.createtype(orgname,tt,(cs_typed_const_writable in aktlocalswitches));
                    sym:=ttypedconstsym.createtype(orgname,tt,(cs_typed_const_writable in aktlocalswitches));
                    akttokenpos:=storetokenpos;
                    akttokenpos:=storetokenpos;
                    symtablestack.insert(sym);
                    symtablestack.insert(sym);
-                   insertconstdata(ttypedconstsym(sym));
                    { procvar can have proc directives, but not type references }
                    { procvar can have proc directives, but not type references }
                    if (tt.def.deftype=procvardef) and
                    if (tt.def.deftype=procvardef) and
                       (tt.sym=nil) then
                       (tt.sym=nil) then

+ 0 - 2
compiler/pdecvar.pas

@@ -649,7 +649,6 @@ implementation
               tcsym:=ttypedconstsym.createtype('default'+vs.realname,tt,false);
               tcsym:=ttypedconstsym.createtype('default'+vs.realname,tt,false);
               vs.defaultconstsym:=tcsym;
               vs.defaultconstsym:=tcsym;
               symtablestack.insert(tcsym);
               symtablestack.insert(tcsym);
-              insertconstdata(tcsym);
               readtypedconst(tt,tcsym,false);
               readtypedconst(tt,tcsym,false);
               { The variable has a value assigned }
               { The variable has a value assigned }
               vs.varstate:=vs_assigned;
               vs.varstate:=vs_assigned;
@@ -660,7 +659,6 @@ implementation
               tcsym.fileinfo:=vs.fileinfo;
               tcsym.fileinfo:=vs.fileinfo;
               symtablestack.replace(vs,tcsym);
               symtablestack.replace(vs,tcsym);
               vs.free;
               vs.free;
-              insertconstdata(tcsym);
               consume(_EQUAL);
               consume(_EQUAL);
               readtypedconst(tt,tcsym,true);
               readtypedconst(tt,tcsym,true);
             end;
             end;

+ 30 - 5
compiler/ptconst.pas

@@ -41,7 +41,7 @@ implementation
        symconst,symbase,symdef,symtable,
        symconst,symbase,symdef,symtable,
        aasmbase,aasmtai,aasmcpu,defutil,defcmp,
        aasmbase,aasmtai,aasmcpu,defutil,defcmp,
        { pass 1 }
        { pass 1 }
-       node,htypechk,
+       node,htypechk,procinfo,
        nmat,nadd,ncal,nmem,nset,ncnv,ninl,ncon,nld,nflw,
        nmat,nadd,ncal,nmem,nset,ncnv,ninl,ncon,nld,nflw,
        { parser specific stuff }
        { parser specific stuff }
        pbase,pexpr,
        pbase,pexpr,
@@ -82,6 +82,7 @@ implementation
          pw        : pcompilerwidestring;
          pw        : pcompilerwidestring;
          error     : boolean;
          error     : boolean;
          old_block_type : tblock_type;
          old_block_type : tblock_type;
+         storefilepos : tfileposinfo;
 
 
          procedure check_range(def:torddef);
          procedure check_range(def:torddef);
          begin
          begin
@@ -98,10 +99,34 @@ implementation
       begin
       begin
          old_block_type:=block_type;
          old_block_type:=block_type;
          block_type:=bt_const;
          block_type:=bt_const;
-         if writable then
-           curconstsegment:=datasegment
-         else
-           curconstsegment:=consts;
+
+         { put everything in the datasemgent to prevent
+           mixing array indexes with ansistring data }
+         curconstsegment:=datasegment;
+
+         if assigned(sym) then
+           begin
+             storefilepos:=aktfilepos;
+             aktfilepos:=sym.fileinfo;
+             l:=sym.getsize;
+             { insert cut for smartlinking or alignment }
+             maybe_new_object_file(curconstSegment);
+             new_section(curconstSegment,sec_rodata,lower(sym.mangledname),const_align(l));
+     {$ifdef GDB}
+             if (cs_debuginfo in aktmoduleswitches) then
+               sym.concatstabto(curconstSegment);
+     {$endif GDB}
+             if (sym.owner.symtabletype=globalsymtable) or
+                maybe_smartlink_symbol or
+                (assigned(current_procinfo) and
+                 (po_inline in current_procinfo.procdef.procoptions)) or
+                DLLSource then
+               curconstSegment.concat(Tai_symbol.Createname_global(sym.mangledname,AT_DATA,l))
+             else
+               curconstSegment.concat(Tai_symbol.Createname(sym.mangledname,AT_DATA,l));
+             aktfilepos:=storefilepos;
+           end;
+
          case t.def.deftype of
          case t.def.deftype of
             orddef:
             orddef:
               begin
               begin

+ 11 - 0
tests/webtbs/tw4277.pp

@@ -0,0 +1,11 @@
+{$mode delphi}
+{$J-}
+
+const
+  RFCMonthNames : Array[1..12] of String = (
+    'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
+    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
+
+begin
+  writeln(RFCMonthNames[10]);
+end.