Deadstore optimisation can break a for-loop
Original Reporter info from Mantis: bunnylin @bunnylin
-
Reporter name: Kirinn
Original Reporter info from Mantis: bunnylin @bunnylin
- Reporter name: Kirinn
Description:
Run this tiny program to reproduce. When compiled without deadstore optimisation, it runs as expected; i = 1 in the for-loop.
When compiled with -gt -Oodfa,deadstore then i has a trash value within the for-loop, which shouldn't be possible.
Interestingly, this only happens if i is an unsigned type. Any signed type still works correctly.
Steps to reproduce:
procedure ForLoop;
var i : dword;
begin
for i := 1 to 1 do begin
writeln('i=',i);
if i <> 1 then halt(1);
end;
end;
begin
ForLoop;
end.
------------------
Compile with:
fpc -gt -Oodfa,deadstore
Mantis conversion info:
- Mantis ID: 38698
- OS: Windows/Linux
- Platform: x86_64
- Version: 3.2.0
- Fixed in version: 3.3.1
- Monitored by: » @MageSlayer (Denis Golovan)