Bläddra i källkod

* changed fix for reusable defs and exceptiontables again: we cannot create
reusable defs for defs in exceptionsymtables, or indeed use any defs from an
exceptionsymtable in the high level code generator, as those defs are freed
before the module is completely compiled -> crashes while trying to use them
in the assembly writing phase ->
o when the symtablestack top is an exception symtable, keep looking for
another symtable to put the def in
o give an internalerror if we encounter a def in an exceptionsymtable anyway
in getreusablesymtab

git-svn-id: trunk@32401 -

Jonas Maebe 9 år sedan
förälder
incheckning
8e43a8a9cf
2 ändrade filer med 11 tillägg och 6 borttagningar
  1. 5 5
      compiler/symdef.pas
  2. 6 1
      compiler/symtype.pas

+ 5 - 5
compiler/symdef.pas

@@ -1692,10 +1692,7 @@ implementation
         if assigned(newdef.owner) then
           internalerror(2015111503);
         reusablesymtab:=origdef.getreusablesymtab;
-        { exception symtable are freed while compiling the current module
-          -> don't reuse }
-        if reusablesymtab.symtabletype<>stt_excepTSymtable then
-          res^.Data:=newdef;
+        res^.Data:=newdef;
         reusablesymtab.insertdef(newdef);
         symtablestack:=oldsymtablestack;
       end;
@@ -2217,8 +2214,11 @@ implementation
           not assigned(self.owner) then
          begin
            insertstack:=symtablestack.stack;
+           { don't insert defs in exception symtables, as they are freed before
+             the module is compiled, so we can get crashes on high level targets
+             if they still need it while e.g. writing assembler code }
            while assigned(insertstack) and
-                 (insertstack^.symtable.symtabletype=withsymtable) do
+                 (insertstack^.symtable.symtabletype in [stt_exceptsymtable,withsymtable]) do
              insertstack:=insertstack^.next;
            if not assigned(insertstack) then
              internalerror(200602044);

+ 6 - 1
compiler/symtype.pas

@@ -402,7 +402,12 @@ implementation
         origowner:=owner;
         while not(origowner.symtabletype in [localsymtable,staticsymtable,globalsymtable,stt_excepTSymtable]) do
           origowner:=origowner.defowner.owner;
-        if origowner.symtabletype in [stt_excepTSymtable,localsymtable] then
+        { if the def is in an exceptionsymtable, we can't create a reusable
+          def because the original one will be freed when the (always
+          temprary) exceptionsymtable is freed }
+        if origowner.symtabletype=stt_excepTSymtable then
+          internalerror(2015111701)
+        else if origowner.symtabletype=localsymtable then
           result:=origowner
         else if assigned(current_module.localsymtable) then
           result:=current_module.localsymtable