Skip to content

Commit e7f5f3e

Browse files
zhangfanniecherrymui
authored andcommitted
cmd/internal/obj/arm64: add error report for invalid base register
The current assembler accepts the non-integer register as the base register, which should be an illegal combination. Add the test cases. Change-Id: Ia21596bbb5b1e212e34bd3a170748ae788860422 Reviewed-on: https://go-review.googlesource.com/134575 Reviewed-by: Cherry Zhang <[email protected]> Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent d5377c2 commit e7f5f3e

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/cmd/asm/internal/asm/testdata/arm64error.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,6 @@ TEXT errors(SB),$0
110110
FLDPD (R1), (F2, F2) // ERROR "constrained unpredictable behavior"
111111
FLDPS (R2), (F3, F3) // ERROR "constrained unpredictable behavior"
112112
FSTPD (R1, R2), (R0) // ERROR "invalid register pair"
113+
FMOVS (F2), F0 // ERROR "illegal combination"
114+
FMOVD F0, (F1) // ERROR "illegal combination"
113115
RET

src/cmd/internal/obj/arm64/asm7.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,10 @@ func (c *ctxt7) aclass(a *obj.Addr) int {
14261426
return C_LIST
14271427

14281428
case obj.TYPE_MEM:
1429+
// The base register should be an integer register.
1430+
if int16(REG_F0) <= a.Reg && a.Reg <= int16(REG_V31) {
1431+
break
1432+
}
14291433
switch a.Name {
14301434
case obj.NAME_EXTERN, obj.NAME_STATIC:
14311435
if a.Sym == nil {
@@ -2968,7 +2972,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
29682972
}
29692973

29702974
case 22: /* movT (R)O!,R; movT O(R)!, R -> ldrT */
2971-
if p.As != AFMOVS && p.As != AFMOVD && p.From.Reg != REGSP && p.From.Reg == p.To.Reg {
2975+
if p.From.Reg != REGSP && p.From.Reg == p.To.Reg {
29722976
c.ctxt.Diag("constrained unpredictable behavior: %v", p)
29732977
}
29742978

@@ -2986,7 +2990,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
29862990
o1 |= ((uint32(v) & 0x1FF) << 12) | (uint32(p.From.Reg&31) << 5) | uint32(p.To.Reg&31)
29872991

29882992
case 23: /* movT R,(R)O!; movT O(R)!, R -> strT */
2989-
if p.As != AFMOVS && p.As != AFMOVD && p.To.Reg != REGSP && p.From.Reg == p.To.Reg {
2993+
if p.To.Reg != REGSP && p.From.Reg == p.To.Reg {
29902994
c.ctxt.Diag("constrained unpredictable behavior: %v", p)
29912995
}
29922996

0 commit comments

Comments
 (0)