View Issue Details

IDProjectCategoryView StatusLast Update
0038636FPCCompilerpublic2021-03-27 16:31
ReporterVille Krumlinde Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityrandom
Status resolvedResolutionfixed 
Platformaarch64OSmacOS 
Product Version3.2.1 
Fixed in Version3.3.1 
Summary0038636: Array access fails
DescriptionCalling this function with a valid index gives incorrect output on aarch64. Tested on MacBook Air M1, macOS 11.2.1.

const
    lowlimit = 536879040;

procedure test(i : integer);
const
  myarray : array[lowlimit..lowlimit+2] of integer = (1,2,3);
begin
  writeln('value: ',myarray[i]);
end;
Steps To ReproduceBuild attached project.

Run it.

Expected output is "1".

At least 4 times out of 5 here it will output other values here.
Additional InformationUsing a lower number than "536879040" will work so I guess the code generation for aarch64 does not correctly reduce the array index with this value.
TagsNo tags attached.
Fixed in Revision49065
FPCOldBugId
FPCTarget-
Attached Files

Activities

Ville Krumlinde

2021-03-18 10:33

reporter  

Project1.pas (224 bytes)   
program Project1;

const
    lowlimit = 536879040;

procedure test(i : integer);
const
  myarray : array[lowlimit..lowlimit+2] of integer = (1,2,3);
begin
  writeln('value: ',myarray[i]);
end;

begin
  test(lowlimit);
end.

Project1.pas (224 bytes)   

Bart Broersma

2021-03-18 23:21

reporter   ~0129755

Last edited: 2021-03-18 23:21

View 2 revisions

On Windows I get a compiler error:
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc -Criot test.pas
Free Pascal Compiler version 3.3.1 [2021/03/14] for i386
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
test.pas(12,16) Error: Range check error while evaluating constants (536879040 must be between -32768 and 32767)
test.pas(14) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

When build with -MObjfpc I get another error:
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc -Criot -Mobjfpc test.pas
Free Pascal Compiler version 3.3.1 [2021/03/14] for i386
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
test.pas(6,52) Error: Data element too large
test.pas(14) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

Without rangechecking you get a warning with the same message.

Delphi7 gives no warning/error and the output of the program is "value: 1".

Florian

2021-03-20 10:08

administrator   ~0129768

Please provide the whole command line you are using. If you are not using a mode where integer is 4 bytes, then the program is simply invalid.

Ville Krumlinde

2021-03-22 09:20

reporter   ~0129821

I'm building from Lazarus. I've not made any custom settings.

Sizeof(integer) = 4

Lazarus options:

/usr/local/bin/fpc
-MObjFPC
-Scghi
-gw
-gl
-l
-vewnhibq
-Filib/aarch64-darwin
-Fu.
-FUlib/aarch64-darwin
-FE.

Free Pascal Compiler version 3.2.1 [2021/03/15] for aarch64
Copyright (c) 1993-2020 by Florian Klaempfl and others
(1002) Target OS: Darwin for AArch64

Issue History

Date Modified Username Field Change
2021-03-18 10:33 Ville Krumlinde New Issue
2021-03-18 10:33 Ville Krumlinde File Added: Project1.pas
2021-03-18 23:21 Bart Broersma Note Added: 0129755
2021-03-18 23:21 Bart Broersma Note Edited: 0129755 View Revisions
2021-03-20 10:08 Florian Status new => feedback
2021-03-20 10:08 Florian FPCTarget => -
2021-03-20 10:08 Florian Note Added: 0129768
2021-03-22 09:20 Ville Krumlinde Note Added: 0129821
2021-03-22 09:20 Ville Krumlinde Status feedback => new
2021-03-27 16:31 Jonas Maebe Assigned To => Jonas Maebe
2021-03-27 16:31 Jonas Maebe Status new => resolved
2021-03-27 16:31 Jonas Maebe Resolution open => fixed
2021-03-27 16:31 Jonas Maebe Fixed in Version => 3.3.1
2021-03-27 16:31 Jonas Maebe Fixed in Revision => 49065