From 7605b7bbf2cabbaf2e53a110ee9bb3eb5e6c4169 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 27 Mar 2018 20:11:45 -0500 Subject: [PATCH] Fix bug where bitwise binary ops on 32-bit values will be miscalculated and trash the stack in certain cases. The following program (derived from a csmith-generated test case) demonstrates the crash: #pragma optimize 8+64 #include long g = 0; int main (void) { long l = 0x10305070; printf("%08lx\n", l ^ (g = (1 , 0x12345678))); } --- Gen.pas | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Gen.pas b/Gen.pas index 7f30571..e1487e8 100644 --- a/Gen.pas +++ b/Gen.pas @@ -3895,7 +3895,10 @@ procedure GenTree {op: icptr}; lab1: integer; {label number} begin {GenOp} - GenImplied(m_pla); + if gLong.where = A_X then + GenImplied(m_phx) + else + GenImplied(m_pla); if gLong.where = constant then begin GenNative(opi, immediate, long(gLong.lval).lsw, nil, 0); GenImplied(m_pha);