View Issue Details

IDProjectCategoryView StatusLast Update
0037254FPCCompilerpublic2020-06-29 22:37
Reporterrunewalsh Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilitysometimes
Status resolvedResolutionfixed 
Platformx86-32 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037254: typecast+SHR can generate wrong code on x86-32.
DescriptionSHR‘ing a typecasted value sometimes tricks the compiler into ignoring that typecast, see below.

I blundered into this bug SOLELY on x86-32 and with optimization level 1, x86-64 or any other optimization level (including 0) work cleanly, doing either MOVZX m8 or AND $ff.
Steps To Reproducefunction Get8bShr1_CORRECT(n: SizeUint): SizeUint;
begin
    result := uint8(n) shr 1;
end;

function Get8bShr1_BUGGY_x86_32(n: SizeUint): SizeUint;
begin
    result := n;
    result := uint8(result) shr 1;
end;

begin
    writeln('Correct: ', HexStr(Get8bShr1_CORRECT($AAAAAA), bitsizeof(SizeUint) div 4));
    writeln('Wrong: ', HexStr(Get8bShr1_BUGGY_x86_32($AAAAAA), bitsizeof(SizeUint) div 4));
end.
Additional InformationCorrect: 00000055
Wrong: 00555555
Same thing with uint16.
TagsNo tags attached.
Fixed in Revision45713
FPCOldBugId
FPCTarget-
Attached Files

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2020-06-25 13:36 runewalsh New Issue
2020-06-29 22:37 Florian Assigned To => Florian
2020-06-29 22:37 Florian Status new => resolved
2020-06-29 22:37 Florian Resolution open => fixed
2020-06-29 22:37 Florian Fixed in Version => 3.3.1
2020-06-29 22:37 Florian Fixed in Revision => 45713
2020-06-29 22:37 Florian FPCTarget => -