Wrong code generated on x86-64
Original Reporter info from Mantis: runewalsh
-
Reporter name:
Original Reporter info from Mantis: runewalsh
- Reporter name:
Description:
Code below should write "#######... 70%", but depending on compiler settings it writes garbage or even crashes.
I have this happening on x86-64-win64 with optimization levels greater than -O1.
Bug vanishes after replacing
pChar(result)[i] :=
with conventional
result[1 + i] :=
or after removing the second condition part, i. e.
(i = int32(divs) - 1) and (progress >= 1)
or after replacing any of 32-bit variables with 64-bit equivalent
so I can't even come close to guessing what's going on here.
Steps to reproduce:
function Bar(const progress: single; divs: uint32): string;
const
BarSym: array[boolean] of char = ('.', '#');
var
i: int32;
begin
SetLength(result, divs);
for i := 0 to int32(divs) - 1 do
pChar(result)[i] := BarSym[(progress >= (0.75 + i) / divs) or (i = int32(divs) - 1) and (progress >= 1)];
end;
var
s: string;
begin
writeln(Bar(0.7, 10) + ' 70%');
end.
Mantis conversion info:
- Mantis ID: 38129
- Build: 63950
- Platform: x86-64-win64
- Fixed in version: 3.3.1
- Fixed in revision: 49095 (#cc64d9eb)
- Monitored by: » Vincent (Vincent Snijders), » @MageSlayer (Denis Golovan), » @CuriousKit (J. Gareth Moreton)