From 5f215e812667de34f93c9170941eb396cc4b6a0f Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sun, 15 Jun 2025 20:19:25 +0200 Subject: [PATCH] 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 --- compiler/symcreat.pas | 8 ++++++++ tests/webtbs/tw41282.pp | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/webtbs/tw41282.pp diff --git a/compiler/symcreat.pas b/compiler/symcreat.pas index 0fad04eeb4..4d52874194 100644 --- a/compiler/symcreat.pas +++ b/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; diff --git a/tests/webtbs/tw41282.pp b/tests/webtbs/tw41282.pp new file mode 100644 index 0000000000..c97f731db2 --- /dev/null +++ b/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.