* constref does not mean that a variable is written, resolves #41206

This commit is contained in:
florian 2025-04-10 22:52:11 +02:00
parent cc20d1fe06
commit f672d4cccf
2 changed files with 30 additions and 2 deletions

View File

@ -1421,8 +1421,7 @@ implementation
else
make_not_regable(left,[ra_addr_regable,ra_addr_taken]);
end;
vs_var,
vs_constref:
vs_var:
begin
set_varstate(left,vs_readwritten,[vsf_must_be_valid,vsf_use_hints]);
{ compilerprocs never capture the address of their
@ -1438,6 +1437,24 @@ implementation
else
make_not_regable(left,[ra_addr_regable,ra_addr_taken]);
end;
vs_constref:
begin
{ constref does not mean that the variable is actually written, this might only
happen if it's address is taken, this is handled below }
set_varstate(left,vs_read,[vsf_must_be_valid,vsf_use_hints]);
{ compilerprocs never capture the address of their
parameters }
if (po_compilerproc in aktcallnode.procdefinition.procoptions) or
{ if we handled already the proc. body and it is not inlined,
we can propagate the information if the address of a parameter is taken or not }
((aktcallnode.procdefinition.typ=procdef) and
not(po_inline in tprocdef(aktcallnode.procdefinition).procoptions) and
(tprocdef(aktcallnode.procdefinition).is_implemented) and
not(parasym.addr_taken)) then
make_not_regable(left,[ra_addr_regable])
else
make_not_regable(left,[ra_addr_regable,ra_addr_taken]);
end;
else
set_varstate(left,vs_read,[vsf_must_be_valid]);
end;

11
tests/webtbs/tw41206.pp Normal file
View File

@ -0,0 +1,11 @@
{ %OPT=-O3 }
procedure f(constref x: int32); noinline;
begin
end;
var
i: int32;
begin
for i := 0 to 9 do f(i);
end.