llvm / llvm-project

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

[Aarch64] Backend Bugs #67950

Open witbring opened 9 months ago

witbring commented 9 months ago

I separate the bug report #67787 since the report has distinct bugs.

The subsequent issue was identified within Clang v16.0.0.

Register Type Check Bug

Clang takes incorrect arm syntax and silently change registers.

$ cat buggy2.s
    sxtw X0, X2
    sxth X0, X4
    sxtb X0, X6

$ ./bin/clang -c --target=aarch64-linux-eabi  buggy2.s -o buggy2.o

$ objdump -d buggy2.o

Disassembly of section .text:

0000000000000000 <.text>:
   0:   93407c40    sxtw    x0, w2
   4:   93403c80    sxth            x0, w4
   8:   93401cc0    sxtb    x0, w6

In case of S2, D2 registers, Clang produces error message.

$ cat buggy2.s
    sxtw X0, X2
    sxth X0, S2
    sxtb X0, D2

$/bin/clang -c --target=aarch64-linux-eabi  buggy2.s -o buggy2.o
buggy2.s:2:14: error: invalid operand for instruction
    sxth X0, S2
             ^
buggy2.s:3:14: error: invalid operand for instruction
    sxtb X0, D2
             ^
llvmbot commented 9 months ago

@llvm/issue-subscribers-backend-aarch64

I separate the bug report #67787 since the report has distinct bugs. The subsequent issue was identified within Clang v16.0.0. ### Register Type Check Bug Clang takes incorrect arm syntax and silently change registers. ``` $ cat buggy2.s sxtw X0, X2 sxth X0, X4 sxtb X0, X6 $ ./bin/clang -c --target=aarch64-linux-eabi buggy2.s -o buggy2.o $ objdump -d buggy2.o Disassembly of section .text: 0000000000000000 <.text>: 0: 93407c40 sxtw x0, w2 4: 93403c80 sxth x0, w4 8: 93401cc0 sxtb x0, w6 ``` In case of S2, D2 registers, Clang produces error message. ``` $ cat buggy2.s sxtw X0, X2 sxth X0, S2 sxtb X0, D2 $/bin/clang -c --target=aarch64-linux-eabi buggy2.s -o buggy2.o buggy2.s:2:14: error: invalid operand for instruction sxth X0, S2 ^ buggy2.s:3:14: error: invalid operand for instruction sxtb X0, D2 ^ ```
john-brawn-arm commented 9 months ago

SXTW <Xd>, <Wn> is an alias of (and preferred disassembly for) SBFM <Xd>, <Xn>, #0, #31, so treating SXTW <Xd>, <Xn> also as an alias seems harmless. On the other hand it's not explicitly permitted in the armv8-a architecture reference manual, and it's inconsistent with gcc which gives an error for these instructions.

witbring commented 9 months ago

Yes, it is. There seems to be an issue regarding compatibility with other assemblers. I believe it would be more effective to display an alarm message in order to inform the user about the alias.