From 1be524b2918928ea37db59073051e4e0bcb288de Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 19 Sep 2026 15:09:54 +0200 Subject: [PATCH] Fixed incorrect flag value after operand reordering --- src/codegen/reorderOperands.go | 3 +++ tests/cast-reorder.q | 4 ++++ tests/tests_test.go | 1 + 3 files changed, 8 insertions(+) create mode 100644 tests/cast-reorder.q diff --git a/src/codegen/reorderOperands.go b/src/codegen/reorderOperands.go index cbd209c..2529c66 100644 --- a/src/codegen/reorderOperands.go +++ b/src/codegen/reorderOperands.go @@ -22,6 +22,7 @@ func (f *Function) reorderOperands(step *Step, instr *ssa.BinaryOp) { if rightStep.Register == step.Register { instr.Left, instr.Right = instr.Right, instr.Left + instr.Swapped = !instr.Swapped return } @@ -33,6 +34,7 @@ func (f *Function) reorderOperands(step *Step, instr *ssa.BinaryOp) { if !leftIsCall || rightStep.Index > leftStep.Index { instr.Left, instr.Right = instr.Right, instr.Left + instr.Swapped = !instr.Swapped return } } @@ -43,6 +45,7 @@ func (f *Function) reorderOperands(step *Step, instr *ssa.BinaryOp) { if leftIsInt && !rightIsInt { instr.Left, instr.Right = instr.Right, instr.Left + instr.Swapped = !instr.Swapped return } } \ No newline at end of file diff --git a/tests/cast-reorder.q b/tests/cast-reorder.q new file mode 100644 index 0000000..26a0af4 --- /dev/null +++ b/tests/cast-reorder.q @@ -0,0 +1,4 @@ +main() { + a := -1952 + assert ((a % 11 + (a as uint32) >> 27) as int) == -1 +} \ No newline at end of file diff --git a/tests/tests_test.go b/tests/tests_test.go index e2d0e3d..c38dcb5 100644 --- a/tests/tests_test.go +++ b/tests/tests_test.go @@ -152,6 +152,7 @@ var tests = []run{ {"function-pointer", nil, "", "", 0}, {"cast", nil, "", "", 0}, {"cast-deduplication", nil, "", "", 0}, + {"cast-reorder", nil, "", "", 0}, {"array-assign", nil, "", "", 0}, {"array-int", nil, "", "", 0}, {"array-int-custom", nil, "", "", 0}, -- 2.51.2