* patch by Sergey Larin: Compile dynarr := nil (and, preferably, SetLength(dynarr, 0)) as fpc_dynarray_clear, resolves #40309

This commit is contained in:
florian 2024-03-04 22:43:56 +01:00
parent 48cb0eb5b1
commit bf2a3566fa

View File

@ -4800,6 +4800,17 @@ implementation
{ first param must be a string or dynamic array ...}
if isarray then
begin
{ SetLength(Arr, 0), Arr := nil, Arr := [] }
if (dims=1) and is_constintvalue(tcallparanode(paras).left, 0) then
begin
ppn.left:=nil; { unlink destppn }
result:=ccallparanode.create(ctypeconvnode.create_internal(destppn,voidpointertype),nil);
result:=ccallnode.createintern('fpc_dynarray_clear',
ccallparanode.create(caddrnode.create_internal(
crttinode.create(tstoreddef(destppn.resultdef),initrtti,rdt_normal)),
result));
exit;
end;
{ create statements with call initialize the arguments and
call fpc_dynarr_setlength }
newblock:=internalstatements(newstatement);