| Issue |
235468
|
| Summary |
[X86][GlobalISel] musttail call is lowered as an ordinary call
|
| Labels |
miscompilation,
llvm:globalisel,
generated by fuzzer
|
| Assignees |
|
| Reporter |
ChoKyuWon
|
### reproducer
godbolt: https://godbolt.org/z/xW5shzhGq
```llvm
target triple = "x86_64-unknown-linux-gnu"
define i64 @f(i64 %n) {
%z = icmp eq i64 %n, 0
br i1 %z, label %done, label %recur
done:
ret i64 7
recur:
%m = add i64 %n, -1
%r = musttail call i64 @f(i64 %m)
ret i64 %r
}
define i32 @main() {
%r = call i64 @f(i64 100000000)
%t = trunc i64 %r to i32
ret i32 %t
}
```
```console
$ llc -O2 -global-isel -global-isel-abort=1 repro.ll -o -
f: # @f
...
# %bb.2: # %recur
pushq %rax
...
decq %rdi
callq f
popq %rcx
...
retq
...
$ llc -O2 repro.ll -o -
f: # @f
...
# %bb.2: # %recur
decq %rdi
jmp f@PLT # TAILCALL
...
$ clang -O0 -mllvm -global-isel repro.ll -o gisel && ./gisel; echo $?
Segmentation fault
139
$ clang -O0 repro.ll -o sdag && ./sdag; echo $?
7
```
### suggested fix
`X86CallLowering::lowerCall` accepts this direct x86-64 call and emits `ADJCALLSTACKDOWN64` + `CALL64pcrel32` + `ADJCALLSTACKUP64` without checking `Info.IsMustTailCall`.
Until X86 GlobalISel implements tail-call lowering, return `false` for `Info.IsMustTailCall` beside the Linux/calling-convention check; this enables SelectionDAG fallback when allowed, or a translation error with `-global-isel-abort=1`.
Current `AArch64CallLowering::lowerCall` rejects `Info.IsMustTailCall && !CanTailCallOpt`; `af0bd41e064f` (D66842) introduced its earlier unconditional musttail rejection.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs