[fpc-devel] ref count issue with out param
Florian Klämpfl
florian at freepascal.org
Sat Jun 13 18:48:32 CEST 2015
Am 13.06.2015 um 16:42 schrieb Martin Frb:
> On 13/06/2015 15:18, Florian Klämpfl wrote:
>> Foo2(a1[i],a2[j])
>>
>> a1, a2 being dyn. arrays, but sharing data, i and j having the same value.
>>
>>
>
> I dug out my old "turbo delphi".
>
> In all both cases (my original example / you dyn array example) Delphi passes nil for the normal
> parameter, and fpc passes a dangling pointer.
>
This depends on the order in which parameters are loaded and is coincidence. Nevertheless, I'll fix
the evaluation order because the code is non-optimal (but not wrong!).
3.1.1 i386:
# [22] Foo2(s1,s1);
movl U_$P$PROJECT1_$$_S1,%ebx
movl $U_$P$PROJECT1_$$_S1,%eax
call fpc_ansistr_decr_ref
movl $U_$P$PROJECT1_$$_S1,%eax
movl %ebx,%edx
call P$PROJECT1_$$_FOO2$ANSISTRING$ANSISTRING
2.6.4 i386:
# [19] Foo1(s1,s1);
movl $U_P$PROJECT1_S1,%eax
call FPC_ANSISTR_DECR_REF
movl $U_P$PROJECT1_S1,%edx
movl U_P$PROJECT1_S1,%eax
call P$PROJECT1_FOO1$ANSISTRING$ANSISTRING
2.6.4 x86-64:
# [22] Foo2(s1,s1);
movq U_P$PROJECT1_S1(%rip),%rbx
leaq U_P$PROJECT1_S1(%rip),%rcx
call FPC_ANSISTR_DECR_REF
leaq U_P$PROJECT1_S1(%rip),%rcx
movq %rbx,%rdx
call P$PROJECT1_FOO2$ANSISTRING$ANSISTRING
More information about the fpc-devel
mailing list