Skip to content

Wrong code generated on i386 (since 2018).

Did you know that talignrec1.pas crashes on i386/win32 (at -O2+) because it generates some absolutely nonsensical code? But the issue is not about the alignment. I made a smaller example:

var
	a, b: int32;
	x, y: byte;
begin
	x := PtrUint(@a) mod 32;
	y := PtrUint(@b) mod 32;
	writeln(x, ' ', y);
end.

and did a git bisect; the bug was introduced in ac37a54d, 5 years ago...

Btw, the disassembly is:

; begin
push ebx
push esi
lea esp, [esp - 4]
call FPC_INITIALIZEUNITS
; x := PtrUint(@a) mod 32;
mov bl, $10               ; ?
jo +$24                   ; ??????????
and [eax + $0040F020], bh ; ??? note that $0040F020 is numerically equal to the 'b' address.
; y := PtrUint(@b) mod 32;
and eax, $1F              ; EAX is undefined, or at least does not contain the 'b' address, so this code is just as wrong.
mov [esp], al
; ...
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information