powerpc/powerpc64 bug
Original Reporter info from Mantis: Pierre @PierreMuller
-
Reporter name: Pierre Muller
Original Reporter info from Mantis: Pierre @PierreMuller
- Reporter name: Pierre Muller
Description:
fpc_pchar_to_shortstring in rtl/powerpc/powerpc.inc is wrong for p=nil!
The output of the code below should be zero,
but we get one for powerpc/powerpc64 at least on linux.
Assigned to Sergei according to:
[muller@gcc1-power7 powerpc]$ svn blame powerpc.inc | grep -nA22 pchar_to_short
1005: 8906 jonas procedure fpc_pchar_to_shortstr(out res : shortstring;p:pchar);assembler;[public,alias:'FPC_PCHAR_TO_SHORTSTR']; compilerproc; nostackframe;
1006- 27832 sergei {
1007- 27832 sergei r3: result address
1008- 27832 sergei r4: high(result)
1009- 27832 sergei r5: p (source)
1010- 27832 sergei }
1011- 27832 sergei asm
1012- 27832 sergei { nil? }
1013- 27832 sergei mr r8, p
1014- 27832 sergei cmplwi p, 0
1015- 27832 sergei { load the begin of the string in the data cache }
1016- 27832 sergei dcbt 0, p
1017- 27832 sergei { maxlength }
1018- 27832 sergei mr r10,r4
1019- 27832 sergei mtctr r10
1020- 27832 sergei { at LStrPasDone, we set the length of the result to 255 - r10 - r4 }
1021- 27832 sergei { = 255 - 255 - 0 if the soure = nil -> perfect :) }
1022- 27832 sergei beq .LStrPasDone
1023- 27832 sergei { save address for at the end and use r7 in loop }
1024- 27832 sergei mr r7,r3
1025- 27832 sergei { no "subi r7,r7,1" because the first byte = length byte }
Steps to reproduce:
Compile the following few lines:
var
s : string;
p : pchar;
i : longint;
begin
p:=nil;
s:=p;
i:=length(s);
writeln('Length of s is ',i);
end.
Mantis conversion info:
- Mantis ID: 35937
- Version: 3.0.4
- Fixed in version: 4.0.0