]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/internal/obj/riscv: prevent constant loads that do not target registers
authorJoel Sing <joel@sing.id.au>
Wed, 17 Feb 2021 10:03:59 +0000 (21:03 +1100)
committerJoel Sing <joel@sing.id.au>
Tue, 23 Feb 2021 09:15:50 +0000 (09:15 +0000)
Check that the target of a constant load is a register and add test coverage
for this error condition. While here, rename the RISC-V testdata and tests
to be consistent with other platforms.

Change-Id: I7fd0bfcee8cf9df0597d72e65cd74a2d0bfd349a
Reviewed-on: https://go-review.googlesource.com/c/go/+/292895
Trust: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/asm/internal/asm/endtoend_test.go
src/cmd/asm/internal/asm/testdata/riscv64.s [moved from src/cmd/asm/internal/asm/testdata/riscvenc.s with 100% similarity]
src/cmd/asm/internal/asm/testdata/riscv64error.s [new file with mode: 0644]
src/cmd/internal/obj/riscv/obj.go

index a4153f3af12fe1f78dd2bf8babc3cd467467d64f..92cf64575b93e26a774f5ea1cf9429c7267f8f32 100644 (file)
@@ -439,8 +439,12 @@ func TestPPC64EndToEnd(t *testing.T) {
        testEndToEnd(t, "ppc64", "ppc64")
 }
 
-func TestRISCVEncoder(t *testing.T) {
-       testEndToEnd(t, "riscv64", "riscvenc")
+func TestRISCVEndToEnd(t *testing.T) {
+       testEndToEnd(t, "riscv64", "riscv64")
+}
+
+func TestRISCVErrors(t *testing.T) {
+       testErrors(t, "riscv64", "riscv64error")
 }
 
 func TestS390XEndToEnd(t *testing.T) {
diff --git a/src/cmd/asm/internal/asm/testdata/riscv64error.s b/src/cmd/asm/internal/asm/testdata/riscv64error.s
new file mode 100644 (file)
index 0000000..fb43e68
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+TEXT errors(SB),$0
+       MOV     $0, 0(SP)                       // ERROR "constant load must target register"
+       MOV     $0, 8(SP)                       // ERROR "constant load must target register"
+       MOV     $1234, 0(SP)                    // ERROR "constant load must target register"
+       MOV     $1234, 8(SP)                    // ERROR "constant load must target register"
+       MOVB    $1, X5                          // ERROR "unsupported constant load"
+       MOVH    $1, X5                          // ERROR "unsupported constant load"
+       MOVW    $1, X5                          // ERROR "unsupported constant load"
+       MOVF    $1, X5                          // ERROR "unsupported constant load"
+       RET
index d104f1cfa514d9e8f645f32fcd2fb80a749d79ed..391c2486ca50dc03dd1101ba0aba7f3690e13abf 100644 (file)
@@ -302,7 +302,10 @@ func rewriteMOV(ctxt *obj.Link, newprog obj.ProgAlloc, p *obj.Prog) {
                //   LUI top20bits(c), R
                //   ADD bottom12bits(c), R, R
                if p.As != AMOV {
-                       ctxt.Diag("unsupported constant load at %v", p)
+                       ctxt.Diag("%v: unsupported constant load", p)
+               }
+               if p.To.Type != obj.TYPE_REG {
+                       ctxt.Diag("%v: constant load must target register", p)
                }
                off := p.From.Offset
                to := p.To