fix(parser): fold a signed parenthesised displacement expression
Test / test (push) Failing after 2m21s
Test / test (push) Failing after 2m21s
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -634,3 +634,27 @@ func TestBareTrailingImmediate(t *testing.T) {
|
||||
t.Errorf("jump target = %+v, want label loop", jmp.Operands[0])
|
||||
}
|
||||
}
|
||||
|
||||
// TestSignedParenDisplacement pins a sign before a parenthesised
|
||||
// displacement expression: -(24+8)(X6) negates the folded value and keeps
|
||||
// the base group, the shape GOROOT's riscv64 and loong64 files use.
|
||||
func TestSignedParenDisplacement(t *testing.T) {
|
||||
file, errs := Parse("t.s", "TEXT \u00b7f(SB), NOSPLIT, $0-0\n\tMOV X7, -(24+8)(X6)\n\tMOV X7, +(16)(X6)\n\tRET\n")
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("parse: %v", errs)
|
||||
}
|
||||
text := file.Decls[0].(*ast.Text)
|
||||
ins := text.Body[0].(*ast.Instr)
|
||||
op := ins.Operands[1] // Plan 9 order: the destination address is last
|
||||
if !op.Addr.HasOff || op.Addr.Offset != -32 {
|
||||
t.Errorf("-(24+8): offset = %v hasOff=%v, want -32 true", op.Addr.Offset, op.Addr.HasOff)
|
||||
}
|
||||
if op.Addr.Base != "X6" {
|
||||
t.Errorf("-(24+8): base = %q, want X6", op.Addr.Base)
|
||||
}
|
||||
ins = text.Body[1].(*ast.Instr)
|
||||
op = ins.Operands[1]
|
||||
if !op.Addr.HasOff || op.Addr.Offset != 16 || op.Addr.Base != "X6" {
|
||||
t.Errorf("+(16): offset = %v hasOff=%v base=%q, want 16 true X6", op.Addr.Offset, op.Addr.HasOff, op.Addr.Base)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user