View Issue Details

IDProjectCategoryView StatusLast Update
0035937FPCRTLpublic2019-08-08 17:28
ReporterPierre MullerAssigned ToSergei Gorelkin 
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Product Version3.0.4Product Build 
Target VersionFixed in Version 
Summary0035937: powerpc/powerpc64 bug
Descriptionfpc_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 ReproduceCompile 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.

TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

rd0x

2019-08-08 17:20

reporter   ~0117593

might be related?
https://github.com/graemeg/freepascal/commit/40958efaea1f39424fae017b2517b0145a9c99f7

Pierre Muller

2019-08-08 17:28

developer   ~0117594

Indeed, this is supposed to fix the powerpc/powerpc64 specific bug.

  I was waiting to check what the new test gives on all platforms before
changing the status of this bug report to fixed!

Pierre

Issue History

Date Modified Username Field Change
2019-08-07 17:38 Pierre Muller New Issue
2019-08-07 17:38 Pierre Muller Status new => assigned
2019-08-07 17:38 Pierre Muller Assigned To => Sergei Gorelkin
2019-08-08 17:20 rd0x Note Added: 0117593
2019-08-08 17:28 Pierre Muller Note Added: 0117594