Skip to content

Compiler error - Apple Silicon - absolute with -O2

  • Lazarus/FPC Version: <3.2.2>
  • Operating System: <MacOS 14.2.1>
  • CPU / Bitness: <64>

What happens

Within a function or procedure, if a byte is overlaid with a shortint, the shortint var does not interpret as negative with b7 set.

Likewise: if an integer overlays a word, same error occurs.

  1. Program Ts;
  2.  
  3. Procedure ShortTest;
  4. VAR
  5.    a: byte;
  6.    b: shortint absolute a;
  7. BEGIN
  8.    for a := 0 to 255 do writeln (a:4,b:5);
  9. END;
  10.  
  11. BEGIN
  12.    Shorttest
  13. END.
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

What did you expect

Normal behaviour such as: VAR a: byte; b:shortint absolute a; then assigning a= 129 should give b= -127.

If the vars are located in globals, then the behaviour is correct.

Steps to reproduce

Within a procedure: Declare a shortint absolute over a byte. Compile with -O2 . Plug in values over 127 into a; b values should be negative.

Edited by Alan The Beast
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information