Compiler bug - Apple Silicon lazarus / 21-General ---------------------------------------------------------------------- AlanTheBeast · 2023-12-30 17:38 Given the bit of code below, on an intel Mac, gives the correct output (negative values of b when a>127) when the code is compiled with or without optimization level 2.  But Apple Si yields positive values for b -always- if the -O2 switch is set. Bug is the same for integerabsolute over a word when the -O2 switch is on. Likewise, Linux (fpc 3.2.2) behaviour is correct regardless of switch. WinXP (fpc 2.6.2) behaviour is correct regardless of switch. Added to https://gitlab.com/freepascal.org/fpc/source/-/issues/40576 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Program Ts; Procedure ShortTest;VAR   a: byte;   b: shortint absolute a;BEGIN   for a := 0 to 255 do begin writeln (a:4,b:5) end;END; BEGIN   ShorttestEND. fpc ts fpc -O2 ts Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i .globl  _P$HYDRO_$$_SHORTTEST_P$HYDRO_$$_SHORTTEST:# [555] BEGIN        stp   x29,x30,[sp, #-16]!        mov     x29,sp        stp     x19,x20,[sp, #-16]!# Var a located in register w0# Var a located in register w19                                       << is this b?# [556] for a := 0 to 255 do begin writeln (a:4,b:5) end;        movz    w19,#255 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i # Var a located in register al                           << intel version# Var a located in register bl                           << same not-same register mapping, but functions ok  On the Apple Si, placing a {$0-} in the VAR section resolves the issue.  But the compiler should be assigning the b var to the same register as the a var. intel Mac - same (that is: correct) result regardless of optimization switch. However, on Apple Si the same code always results in positive values of b if the -O2 switch is set. CORRECT O/P: (      fpc -O2 Ts --on intel Mac,   or fpc Ts --on Apple Si Mac):  126  126  127  127  128 -128  129 -127  130 -126   INCORRECT O/P.  (      fpc -O2 Ts --on Apple Silicon):  126  126  127  127  128  128  129  129  130  130 Exception:  if the a and b variable are in globals, then there is no problem (memory mapped rather than register in the -O2 case).