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.
- Program Ts;
- Procedure ShortTest;
- VAR
- a: byte;
- b: shortint absolute a;
- BEGIN
- for a := 0 to 255 do writeln (a:4,b:5);
- END;
- BEGIN
- Shorttest
- 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