Optimizer bug when using absolute
Summary
wrong assembly is generated on linux with -O3
System Information
x86_64-linux, fpc 3.2.2
Steps to reproduce
program project1;
{$mode objfpc}{$H+}
var ind:integer=0;
const vals:array[0..1] of integer=(1052909725,1092805937);
function GetLong:integer;
begin
Result := vals[ind];
inc(ind);
end;
function GetDouble: double;
type TpDoubleRec=packed record v1,v2:integer;end;
var V:TpDoubleRec absolute Result;
begin
V.v1 := GetLong;
V.v2 := GetLong;
end;
var r:double;
begin
r := GetDouble;
if round(r*100000)<>61916062257 then
writeln('wrong')
else
writeln('ok');
end.
What is the current bug behavior?
Compiling on windows as i386-win32:
- without optimizing or with -O3: writes ok to console
Compiling on linux as x86_64-linux:
- without optimizing: writes ok to console
- with -O3: writes wrong to console (and r is widely off, its roughly 2.15320923002915E-317)
Full discussion including workarounds here: https://forum.lazarus.freepascal.org/index.php/topic,62766.msg474801.html
Edited by Paul van der Linden