[fpc-pascal] SetLength warnings - request

Vojtěch Čihák vojtech.cihak at atlas.cz
Tue Sep 4 15:53:03 CEST 2018

even if there's closed issue https://bugs.freepascal.org/view.php?id=34169 I would like to ask if it can be reconsidered.
The subject is that SetLength now gives warning: Variable "dynamic array" of a managed type does not seem to be initialized
in 3.3.1 and 3.1.1 while it doesn't give any warning in stable 3.0.4
As a solution is recommended do declaration: var arr: array of widechar = ();
But it means that initialization is in fact done twice. See assembler of following code:
procedure TForm1.Button1Click(Sender: TObject);
var DA: array of widechar = ();
  SetLength(DA, 10);
unit1.pas:30                              var DA: array of widechar = ();
00000000004696C9 488d1538536600           lea    0x665338(%rip),%rdx        # 0xacea08 <RTTI_$UNIT1_$$_def00000138>
00000000004696D0 488b3529536600           mov    0x665329(%rip),%rsi        # 0xacea00 <TC_$UNIT1$_$TFORM1_$_BUTTON1CLICK$TOBJECT_$$_defaultDA>
00000000004696D7 4889e7                   mov    %rsp,%rdi
00000000004696DA e8d199fcff               callq  0x4330b0 <fpc_dynarray_assign>
unit1.pas:32                              SetLength(DA, 10);
00000000004696DF 48c74424680a000000       movq   $0xa,0x68(%rsp)
00000000004696E8 488d3519536600           lea    0x665319(%rip),%rsi        # 0xacea08 <RTTI_$UNIT1_$$_def00000138>
00000000004696EF 488d4c2468               lea    0x68(%rsp),%rcx
00000000004696F4 4889e7                   mov    %rsp,%rdi
00000000004696F7 ba01000000               mov    $0x1,%edx
00000000004696FC e8df99fcff               callq  0x4330e0 <fpc_dynarray_setlength>
unit1.pas:33                              writeln(DA[0]);
To avoid warning we now need four extra instructions incl. call to fpc_array_assign, which is obviously redundant.As an explanation is written: Setlength uses a var parameter. This is no different from other cases of var parameter usage.I disaggre here, because SetLength is not an usual procedure, it is fundamental part of compiler. Therefore it deserves some exception.That's why I ask for reconsidering and make it behave like in 3.0.4 or change declaration from "var" to "out" as it is done in getmem().Thanks, Vojtěch. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180904/71d6469b/attachment.html>

More information about the fpc-pascal mailing list