View Issue Details

IDProjectCategoryView StatusLast Update
0038698FPCCompilerpublic2021-04-05 02:36
ReporterKirinn Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Platformx86_64OSWindows/Linux 
Product Version3.2.0 
Fixed in Version3.3.1 
Summary0038698: Deadstore optimisation can break a for-loop
DescriptionRun 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 Reproduceprocedure 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
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Florian

2021-04-04 18:05

administrator   ~0130083

This is already fixed in trunk. As the fix is too invasive (and -Oodeadstore in in 3.2.x is not recommended to be used), I am against merging it.

Kirinn

2021-04-05 02:36

reporter   ~0130100

Fair enough. I'll make note of this on the Optimization wiki page.

Issue History

Date Modified Username Field Change
2021-04-03 13:29 Kirinn New Issue
2021-04-04 18:05 Florian Assigned To => Florian
2021-04-04 18:05 Florian Status new => resolved
2021-04-04 18:05 Florian Resolution open => no change required
2021-04-04 18:05 Florian Fixed in Version => 3.3.1
2021-04-04 18:05 Florian FPCTarget => -
2021-04-04 18:05 Florian Note Added: 0130083
2021-04-05 02:36 Kirinn Note Added: 0130100