| Issue |
243034
|
| Summary |
[MIPS] Crash in instruction selection with narrow integer operands bound to explicit registers
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
mu-mu-mu
|
On MIPS, clang crashes in instruction selection when a `char` or `short` local register variable is used as an inline asm operand. The same code with `unsigned int` compiles.
### Reproducer
```c
unsigned char f(unsigned char a) {
register unsigned char z __asm__("$8") = a;
__asm__ volatile("" : "+r"(z));
return z;
}
```
```console
$ clang --target=mips -c test.c
```
### Actual behavior
clang 23.1.3 segfaults in `MIPS DAG->DAG Pattern Instruction Selection`. An assertions build (trunk) fails with:
```console
clang: llvm/include/llvm/CodeGen/TargetLowering.h:1086: virtual const TargetRegisterClass* llvm::TargetLoweringBase::getRegClassFor(llvm::MVT, bool) const: Assertion `RC && "This value type is not natively supported!"' failed.
...
#10 llvm::MipsTargetLowering::parseRegForInlineAsmConstraint(llvm::StringRef, llvm::MVT) const
#11 llvm::MipsTargetLowering::getRegForInlineAsmConstraint(llvm::TargetRegisterInfo const*, llvm::StringRef, llvm::MVT) const
```
test-86110b.c
```c
# 1 "<built-in>"
# 1 "test.c"
unsigned char f(unsigned char a) {
register unsigned char z __asm__("$8") = a;
__asm__ volatile("" : "+r"(z));
return z;
}
```
test-86110b.sh
```sh
# Crash reproducer for clang version 23.1.3 (https://github.com/llvm/llvm-project 0d261d1ca552c95a8f007e061c787ac7132fbcbc)
# Driver args: "--target=mips" "-c" "test.c" "-o" "/tmp/a.o"
# Original command: "/opt/llvm/bin/clang-23" "-cc1" "-triple" "mips" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.c" "-mrelocation-model" "static" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-target-cpu" "mips32r2" "-target-feature" "-noabicalls" "-target-feature" "+fpxx" "-target-feature" "+nooddspreg" "-target-abi" "o32" "-mfloat-abi" "hard" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/w" "-fcoverage-compilation-dir=/w" "-resource-dir" "/opt/llvm/lib/clang/23" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-faddrsig" "-o" "/tmp/a.o" "-x" "c" "test.c"
"/opt/llvm/bin/clang-23" "-cc1" "-triple" "mips" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.c" "-mrelocation-model" "static" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-target-cpu" "mips32r2" "-target-feature" "-noabicalls" "-target-feature" "+fpxx" "-target-feature" "+nooddspreg" "-target-abi" "o32" "-mfloat-abi" "hard" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/w" "-fcoverage-compilation-dir=/w" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-faddrsig" "-x" "c" "test-86110b.c"
```
### Expected behavior
The code compiles, as it does with `unsigned int`, or clang reports an error instead of crashing.
For reference, GCC accepts the code.
clang (assertions trunk): https://godbolt.org/z/qrznhzfvh
gcc: https://godbolt.org/z/zb1o4ex5z
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs