Issue 243029
Summary [WebAssembly] Crash on a symbol operand to br in inline asm ("unexpected symbolic operand kind")
Labels new issue
Assignees
Reporter mu-mu-mu
    
On WebAssembly, clang crashes when an inline asm instruction that takes an integer operand (here, the depth of `br`) is given a symbol. The same instruction in a `.s` file is rejected with an error.

### Reproducer

```c
extern int sym;

void f(void)
{
 __asm__ volatile("br sym");
}
```

```console
$ clang --target=wasm32 -c test.c
```

### Actual behavior

clang 23.1.3 segfaults in `MCAssembler::layout()`. An assertions build (trunk) fails with:

```console
unexpected symbolic operand kind
UNREACHABLE executed at llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp:265!
...
#9 (anonymous namespace)::WebAssemblyMCCodeEmitter::encodeInstruction(...)
#10 llvm::MCObjectStreamer::emitInstToData(...)
#11 llvm::MCObjectStreamer::emitInstruction(...)
#12 (anonymous namespace)::WebAssemblyAsmParser::matchAndEmitInstruction(...)
...
#16 llvm::AsmPrinter::emitInlineAsm(...)
```

Crash reproducer files:

test-cf24ad.c
```c
# 1 "<built-in>"
# 1 "test.c"
extern int sym;

void f(void)
{
    __asm__ volatile("br sym");
}
```

test-cf24ad.sh
```sh
# Crash reproducer for clang version 23.1.3 (https://github.com/llvm/llvm-project 0d261d1ca552c95a8f007e061c787ac7132fbcbc)
# Driver args: "--target=wasm32" "-c" "test.c"
# Original command:  "/opt/llvm/bin/clang-23" "-cc1" "-triple" "wasm32" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.c" "-mrelocation-model" "static" "-mframe-pointer=none" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-target-cpu" "generic" "-fvisibility=hidden" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/w" "-fcoverage-compilation-dir=/w" "-resource-dir" "/opt/llvm/lib/clang/23" "-internal-isystem" "/opt/llvm/lib/clang/23/include" "-internal-isystem" "/include" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-o" "test.o" "-x" "c" "test.c"
 "/opt/llvm/bin/clang-23" "-cc1" "-triple" "wasm32" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.c" "-mrelocation-model" "static" "-mframe-pointer=none" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-target-cpu" "generic" "-fvisibility=hidden" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/w" "-fcoverage-compilation-dir=/w" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-x" "c" "test-cf24ad.c"
```

### Expected behavior

clang reports an error, as it does when the same instruction is assembled from a `.s` file:

```console
$ cat test.s
	.functype	f () -> ()
	.globl	f
f:
	.functype	f () -> ()
	br	sym
	end_function

$ clang --target=wasm32 -c test.s
test.s:5:5: error: depth should be an integer
        br      sym
                ^
```

clang (assertions trunk): https://godbolt.org/z/Kbadjeqfn
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to