llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.64k stars 11.37k forks source link

[MC][Thumb2] .w suffix rejected for certain ldr and str operands #50008

Open rprichard opened 3 years ago

rprichard commented 3 years ago
Bugzilla Link 50664
Version trunk
OS Linux
CC @kbeyls,@nickdesaulniers,@smithp35

Extended Description

LLVM can assemble this Thumb2 code (clang --target=armv7a-linux-gnueabi):

.syntax unified
.thumb
ldr.w r0, [r1, #​0xf00]

But not this:

.syntax unified
.thumb
ldr.w r0, [r1, #-2]

test.S:3:15: error: invalid operand for instruction ldr.w r0, [r1, #-2] ^

It will assemble if I remove the ".w" suffix. The disassembly is then:

00000000 <.text>: 0: f851 0c02 ldr.w r0, [r1, #-2]

... which indicates a wide instruction.

Maybe the fix for bug #​49118 was incomplete?

There are some similar instructions that, IIRC, use the same encoding, and have the same problem. They're wide instructions that can only be assembled if the ".w" suffix is omitted:

ldr.w r0, [r1, #&#8203;2]!
ldr.w r0, [r1], #&#8203;2
ldr.w r0, [r1, #-0]
rprichard commented 3 years ago

ldr.w r0, [r1, #​2]! ldr.w r0, [r1], #​2 ldr.w r0, [r1, #-0]

Actually it looks like a current version of LLVM can handle the first two of these. Only the last one is a problem, and that's basically the same as "ldr.w r0, [r1, #-2]".