llvm-project/llvm/test/MC/ARM/lower-upper-errors-2.s
Simon Tatham d97f17a959
[MC][ARM] Fix crash when assembling Thumb 'movs r0,#foo'. (#115026)
If the assembler sees this instruction, understanding `foo` to be an
external symbol, there's no relocation it can write that will put the
whole value of `foo` into the 8-bit immediate field of the 16-bit Thumb
add instruction. So it should report an error message pointing at the
source line, and in LLVM 18, it did exactly that. But now the error is
not reported, due to an indexing error in the operand list in
`validateInstruction`, and instead the code continues to attempt
assembly, ending up aborting at the `llvm_unreachable` at the end of
`getHiLoImmOpValue`.

In this commit I've fixed the index in the `ARM::tMOVi8` case of
`validateInstruction`, and also the one for `tADDi8` which must cope
with either the 2- or 3-operand form in the input assembly source. But
also, while writing the test, I found that if you assemble for Armv7-M
instead of Armv6-M, the instruction has opcode `t2ADDri` when it goes
through `validateInstruction`, and only turns into `tMOVi8` later in
`processInstruction`. Then it's too late for `validateInstruction` to
report that error. So I've adjusted `processInstruction` to spot that
case and inhibit the conversion.
2024-11-14 09:14:59 +00:00

19 lines
669 B
ArmAsm

// RUN: not llvm-mc --triple thumbv7m -filetype=obj -o /dev/null %s 2>&1 | FileCheck %s
// This test checks reporting of errors of the form "you should have
// used :lower16: in this immediate field", when the errors are
// discovered at the object-file output stage by checking the set of
// available relocations.
//
// For errors that are reported earlier, when initially reading the
// instructions, see lower-upper-errors.s.
// CHECK: [[@LINE+1]]:1: error: unsupported relocation
adds r0, r0, #foo
// CHECK: [[@LINE+1]]:1: error: unsupported relocation
add r9, r0, #foo
// CHECK: [[@LINE+1]]:1: error: expected relocatable expression
movs r11, :upper8_15:#foo