View Issue Details

IDProjectCategoryView StatusLast Update
0037709FPCCompilerpublic2020-09-08 23:47
ReporterBernd Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformRISC-VOSEmbedded 
Fixed in Version3.3.1 
Summary0037709: RISC-V Embedded, code generator seems to use wrong registers.
DescriptionThe attached test program was compiled with the following options:
ppcrossrv32 -CpRV32IMAC -Tembedded -WpGD32VF103CB -k-melf32lriscv -B -al -O2 test.pas

The test program fails, because the local copy of the shortstring variable sIn (in the procedure TestShortString) is corrupt. I think, that fpc_shortstr_to_shortstr is called with a wrong register setup.

The relevant part of TestShortString is assembled to:

.section .text.n_p$test_$$_testshortstring$shortstring,"ax"
    .balign 4
.globl P$TEST_$$_TESTSHORTSTRING$SHORTSTRING
P$TEST_$$_TESTSHORTSTRING$SHORTSTRING:
# Temps allocated between x8-316 and x8-60
# [test.pas]
# [9] begin
    addi x2,x2,-8
    sw x1,4(x2)
    sw x8,0(x2)
    addi x8,x2,8
    addi x2,x2,-316
# Var sIn located at x8-56, size=OS_32
# Var b located at x8-60, size=OS_8
    sw x10,-56(x8)
    lw x10,-56(x8)
    addi x13,x10,0 <<< x13 should be x12
    addi x12,x0,255 <<< x12 should be x11
    addi x11,x8,-316 <<< x11 should be x10
.Lj5:
    auipc x1,%pcrel_hi(fpc_shortstr_to_shortstr)
    jalr x1,x1,%pcrel_lo(.Lj5)

If I swap the registers at runtime, the program runs correct.
TagsNo tags attached.
Fixed in Revision46803
FPCOldBugId
FPCTarget-
Attached Files

Activities

Bernd

2020-09-06 01:40

reporter  

test.pas (358 bytes)   
program test;
{$mode objfpc}{$H-}
var
   s: ShortString;

procedure TestShortString(sIn: ShortString);
var
   b: Byte;
begin
   b:= Ord(sIn[1]);  // b = 'L' = 76
   if b <> 76 then begin
      { Error, program executes here! }
      repeat
      until FALSE;
   end;
   asm
      ebreak;
   end;
end;

begin
   s:= 'Laberhannes';
   TestShortString(s);
end.
test.pas (358 bytes)   

Bernd

2020-09-08 23:47

reporter   ~0125442

Thank you.

Issue History

Date Modified Username Field Change
2020-09-06 01:40 Bernd New Issue
2020-09-06 01:40 Bernd File Added: test.pas
2020-09-08 22:32 Florian Assigned To => Florian
2020-09-08 22:32 Florian Status new => resolved
2020-09-08 22:32 Florian Resolution open => fixed
2020-09-08 22:32 Florian Fixed in Version => 3.3.1
2020-09-08 22:32 Florian Fixed in Revision => 46803
2020-09-08 22:32 Florian FPCTarget => -
2020-09-08 23:47 Bernd Status resolved => closed
2020-09-08 23:47 Bernd Note Added: 0125442