aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/asm
diff options
context:
space:
mode:
authorMark Ryan <markdryan@rivosinc.com>2024-12-11 14:03:17 +0100
committerJoel Sing <joel@sing.id.au>2025-03-19 07:00:36 -0700
commit1aee4f3464b678f135912e2b2703e0f6c060b980 (patch)
treedea4049d25e91179507ce4d7d56ade7c819f8a77 /src/cmd/asm
parent24b395119b4df7f16915b9f01a6aded647b79bbd (diff)
downloadgo-1aee4f3464b678f135912e2b2703e0f6c060b980.tar.xz
cmd/internal/obj/riscv: prevent panics on bad branches
Syntactically incorrect branches, such as BEQ X5, X6, $1 BEQ X5, X6, 31(X10) cause the assembler to panic, which they shouldn't really do. It's better for the user to see a normal error, as reported for other syntax errors in riscv64 assembly. The panics also prevent us from writing negative tests for these sorts of errors. Here we fix the issue by ensuring we generate a normal error instead of panicking when the user provides an invalid branch target. We also add a couple of negative tests. Change-Id: I1da568999a75097484b61a01d418f5d4be3e04fa Reviewed-on: https://go-review.googlesource.com/c/go/+/637316 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Joel Sing <joel@sing.id.au> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
Diffstat (limited to 'src/cmd/asm')
-rw-r--r--src/cmd/asm/internal/asm/testdata/riscv64error.s2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/cmd/asm/internal/asm/testdata/riscv64error.s b/src/cmd/asm/internal/asm/testdata/riscv64error.s
index e8855f6cd5..005b794612 100644
--- a/src/cmd/asm/internal/asm/testdata/riscv64error.s
+++ b/src/cmd/asm/internal/asm/testdata/riscv64error.s
@@ -30,6 +30,8 @@ TEXT errors(SB),$0
SLLI $64, X5, X6 // ERROR "immediate out of range 0 to 63"
SRLI $64, X5, X6 // ERROR "immediate out of range 0 to 63"
SRAI $64, X5, X6 // ERROR "immediate out of range 0 to 63"
+ BEQ X5, X6, $1 // ERROR "instruction with branch-like opcode lacks destination"
+ BEQ X5, X6, 31(X10) // ERROR "instruction with branch-like opcode lacks destination"
RORI $-1, X5, X6 // ERROR "immediate out of range 0 to 63"
SLLI $-1, X5, X6 // ERROR "immediate out of range 0 to 63"
SRLI $-1, X5, X6 // ERROR "immediate out of range 0 to 63"