View Issue Details

IDProjectCategoryView StatusLast Update
0038861FPCCompilerpublic2021-05-08 07:20
ReporterChristo Crause Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilitysometimes
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038861: AVR incorrect instructions generated for a variable at absolute 0 when passed as a var parameter
DescriptionNewer type controllers in the avrxmega3 subarch can have a peripheral (e.g. VPORTA) mapped to address 0. Incorrect instructions are generated when passing such a variable as a var parameter to a procedure, see steps to reproduce.

The problem appears to be that the compiler assumes ref.offset should not be 0 to be a reference referring to an absolute address. Attached a patch that implements extra checks to handle this situations.
Steps To Reproduceprogram test;

procedure test1(var a: byte);
begin
end;

var
  r: byte absolute 0;

begin
  test1(r);
end.

The instructions generated for passing the reference to r to the proecdure call test1 is incorrect:
# [10] begin
    call FPC_INIT_FUNC_TABLE
.Ll5:
# [11] test1(r);
    mov r18,r19 // r19 is uninitialized
    mov r25,r19
    mov r24,r18
    call PsTEST_ss_TEST1sBYTE
.Ll6:
# [12] end.
    call fpc_do_exit
TagsNo tags attached.
Fixed in Revision49344
FPCOldBugId
FPCTarget-
Attached Files

Activities

Christo Crause

2021-05-05 20:31

reporter  

absolute-zero.patch (638 bytes)   
Index: avr/cgcpu.pas
===================================================================
--- avr/cgcpu.pas	(revision 49246)
+++ avr/cgcpu.pas	(working copy)
@@ -2357,7 +2357,9 @@
          if ref.addressmode<>AM_UNCHANGED then
            internalerror(2011021706);
 
-        if assigned(ref.symbol) or (ref.offset<>0) then
+         if assigned(ref.symbol) or (ref.offset<>0) or
+           { If no other reference information it must imply an absolute reference to address 0 }
+           ((ref.index=NR_NO) and (ref.base=NR_NO)) then
           begin
             reference_reset(tmpref,0,[]);
             tmpref.symbol:=ref.symbol;
absolute-zero.patch (638 bytes)   

Florian

2021-05-07 16:20

administrator   ~0130788

Thanks, applied.

Christo Crause

2021-05-08 07:20

reporter   ~0130796

Thanks!

Issue History

Date Modified Username Field Change
2021-05-05 20:31 Christo Crause New Issue
2021-05-05 20:31 Christo Crause File Added: absolute-zero.patch
2021-05-07 16:20 Florian Assigned To => Florian
2021-05-07 16:20 Florian Status new => resolved
2021-05-07 16:20 Florian Resolution open => fixed
2021-05-07 16:20 Florian Fixed in Version => 3.3.1
2021-05-07 16:20 Florian Fixed in Revision => 49344
2021-05-07 16:20 Florian FPCTarget => -
2021-05-07 16:20 Florian Note Added: 0130788
2021-05-08 07:20 Christo Crause Status resolved => closed
2021-05-08 07:20 Christo Crause Note Added: 0130796