Browse Source

LLVM: always added related high parameters to parentfpstruct

Sometimes the high parameter is only first accessed during the first
pass, while we already need to know everything that will go into the
parentfpstruct during the typechecking pass.

resolves #41282
Jonas Maebe 1 month ago
parent
commit
5f215e8126
2 changed files with 31 additions and 0 deletions
  1. 8 0
      compiler/symcreat.pas
  2. 23 0
      tests/webtbs/tw41282.pp

+ 8 - 0
compiler/symcreat.pas

@@ -1990,6 +1990,7 @@ implementation
       old_filepos: tfileposinfo;
       symname,
       symrealname: TSymStr;
+      highsym: tabstractvarsym;
     begin
       nestedvarsdef:=tlocalvarsym(pd.parentfpstruct).vardef;
       { redirect all aliases for the function result also to the function
@@ -2044,6 +2045,13 @@ implementation
               tblocknode(pd.parentfpinitblock).left:=cstatementnode.create
                 (initcode,tblocknode(pd.parentfpinitblock).left);
               current_filepos:=old_filepos;
+
+              { also add the associated high para, if any. It may not be accessed
+                during code generation, and we need to catch 'em all (TM) during
+                the typecheck/firstpass }
+              highsym:=get_high_value_sym(tparavarsym(sym));
+              if assigned(highsym) then
+                maybe_add_sym_to_parentfpstruct(pd, highsym, highsym.vardef, false);
             end;
         end;
     end;

+ 23 - 0
tests/webtbs/tw41282.pp

@@ -0,0 +1,23 @@
+{$mode delphi}
+
+Program test;
+
+procedure outer_proc(var outer: ShortString);
+
+procedure inner_proc;
+Begin
+  outer := 'abc';
+End;
+
+Begin
+  inner_proc();
+End;
+
+var
+ s: shortstring;
+
+Begin
+  outer_proc(s);
+  if s<>'abc' then
+    halt(1);
+End.