peephole optimizer, leads to incorrect values in debugger (patch attached)
Original Reporter info from Mantis: Martin @martin_frb
-
Reporter name: Martin Friebe
Original Reporter info from Mantis: Martin @martin_frb
- Reporter name: Martin Friebe
Description:
See Example below.
-O1 is "debugger friendly". Even though it does not guarantee to be 100% dbg proof. In this case it can be improved.
The debug info will specify that in is in -12(%ebp)
But in the optimized version, this is not the case in line 1.
The optimization really needs to be seen as replacing (all in line 1)
movl $1,-12(%ebp)
by
movl $1,%eax
movl %eax,-12(%ebp)
and dropping the first asm from line 2, since eax is already loaded.
This is archived by moving the 2nd TAI into the first line (changing its line info)
Additional information:
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
i := 1;
// After this line Delphi Evaluate/Modify shows '1', Lazarus still a random (uninitialized?) integer
i := i + 1;
// Ater this line Delphi & Lazarus both show '2'
ShowMessageFmt('%d',[i]);
end;
------------------------------------------- Before optimization # [36] i := 1; movl $1,-12(%ebp) # [38] i := i + 1; movl -12(%ebp),%eax addl $1,%eax ------------------------------------------- After optimization # [36] i := 1; movl $1,%eax # [38] i := i + 1; movl %eax,-12(%ebp) // &LtPos;< this should be part of the first line
addl $1,%eax
Mantis conversion info:
- Mantis ID: 25584
- OS: win
- OS Build: vista
- Build: 26519
- Platform: w32
- Version: 2.7.1
- Fixed in version: 3.0.0
- Fixed in revision: 26794 (#cbefdcf8)