View Issue Details

IDProjectCategoryView StatusLast Update
0036302FPCCompilerpublic2019-11-17 17:40
ReporterDariusz KwiecinskiAssigned ToFlorian 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionunable to reproduce 
PlatformOSWindows 7OS Version
Product Version3.3.1Product Build3.3.1 pccrossarm embedded ARMV6M 
Target VersionFixed in Version 
Summary0036302: Error DIV result
DescriptionI get incorrect results using the div command.

Test code:
program test;
var
  x,size : byte;
 
function doit(ax,asize : byte):byte;
begin
  Result := ax+(asize div 2);
end;
 
begin
   LPC_SYSCON.SYSAHBCLKCTRL := LPC_SYSCON.SYSAHBCLKCTRL or ((1 shl 6) or (1 shl 16));
 
 LPC_GPIO0.DIR := LPC_GPIO0.DIR OR $0002;
 
  size := 16;
  x := 10;
  size := doit(x,size);
  if(size = 18) then
   LPC_GPIO0.MASKED_ACCESS[$0002] := 0;
end.

If "(asize div 2)" change to "trunc(asize/2" or "(asize shr 1)" results is correct.

Im using 3.3.1 from last trunk :
ppcrossarm.exe -Tembedded -Parm -CpARMV6M -MObjFPC -l -vewnhibq -otestprogram -al -WpLPC1114FBD48_303

All outputs assembly in attachments.

Topic in forum:
https://forum.lazarus.freepascal.org/index.php/topic,47363.0.html
Additional InformationMy english is not prefect :)
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Dariusz Kwiecinski

2019-11-12 17:25

reporter  

arm-embedded.zip (4,416 bytes)

Florian

2019-11-12 20:29

administrator   ~0119242

Do you really use the latest trunk? I cannot reproduce it.

Without optimization I get:

# [7] Result := ax+(asize div 2);
        add r0,r13,0000004
        ldrb r0,[r0]
        mov r1,r0
        lsr r1,r1,0000031
        add r1,r0,r1
        asr r1,r1,0000001
        mov r0,r13
        ldrb r0,[r0]
        add r0,r1
        uxtb r1,r0
        add r0,r13,0000008
        strb r1,[r0]

with -O4 I get

# [7] Result := ax+(asize div 2);
        mov r0,r1
        lsr r0,r0,0000031
        add r0,r1,r0
        asr r0,r0,0000001
        add r2,r0

Both variants look correct.

Dariusz Kwiecinski

2019-11-13 21:25

reporter   ~0119276

If compile official trunk 3.0.4 this result is correct.

I used 3.3.1 from source (03/11/2019) and this generated this bug.

the attachment contains the wrong version of the compiler that generated this error.
For windows.

ppcrossarm.zip (1,025,242 bytes)

Dariusz Kwiecinski

2019-11-13 21:26

reporter   ~0119277

added utils files for bad compiler

Utils_arm-embedded.zip (1,780,940 bytes)

Florian

2019-11-13 21:38

administrator   ~0119278

As said, please test with the latest compiler from trunk if you use trunk.

Dariusz Kwiecinski

2019-11-14 09:33

reporter   ~0119290

I can't compile trunk from 14/11/2019

"C:\fpc_src\rtl\units\arm-embedded\system.s:84460: Error: branch out of range
system.pp(336) Error: Error while assembling exitcode 1
system.pp(336) Fatal: There were 2 errors compiling module, stopping"

I will start using 3.0.4 for projects.
Sometimes I will test the latest sources in this direction.
Subject temporarily to close.

Thaddy de Koning

2019-11-14 10:39

reporter   ~0119291

- Dariusz, ping me on the forum, I will help with the build

Issue History

Date Modified Username Field Change
2019-11-12 17:25 Dariusz Kwiecinski New Issue
2019-11-12 17:25 Dariusz Kwiecinski File Added: arm-embedded.zip
2019-11-12 20:29 Florian Note Added: 0119242
2019-11-13 21:25 Dariusz Kwiecinski File Added: ppcrossarm.zip
2019-11-13 21:25 Dariusz Kwiecinski Note Added: 0119276
2019-11-13 21:26 Dariusz Kwiecinski File Added: Utils_arm-embedded.zip
2019-11-13 21:26 Dariusz Kwiecinski Note Added: 0119277
2019-11-13 21:38 Florian Note Added: 0119278
2019-11-14 09:33 Dariusz Kwiecinski Note Added: 0119290
2019-11-14 10:39 Thaddy de Koning Note Added: 0119291
2019-11-17 17:40 Florian Assigned To => Florian
2019-11-17 17:40 Florian Status new => resolved
2019-11-17 17:40 Florian Resolution open => unable to reproduce
2019-11-17 17:40 Florian FPCTarget => -