| Issue |
237977
|
| Summary |
[StackProtector] sspstrong/sspreq crash on an alloca of an array of scalable vectors
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
zjy-dev
|
`StackProtector::ContainsProtectableArray` compares `SSPBufferSize` with `DL.getTypeAllocSize(AT)` through the
implicit `TypeSize -> uint64_t` conversion. For `[N x <vscale x ...>]` that conversion aborts. In strong/req mode,
the non-char-array early return is skipped, so the comparison always runs.
```llvm
target triple = "aarch64-unknown-linux-gnu"
declare void @sink(ptr)
define void @f() sspstrong "target-features"="+sve" {
%a = alloca [2 x <vscale x 4 x i32>]
call void @sink(ptr %a)
ret void
}
```
Compile flag: `llc -O2 trigger.ll`
```
LLVM ERROR: Cannot implicitly convert a scalable size to a fixed-width size in `TypeSize::operator ScalarTy()`
Stack dump:
0. Program arguments: llc -O2 trigger.ll -o /dev/null
1. Running pass 'Function Pass Manager' on module 'trigger.ll'.
2. Running pass 'Insert stack protectors' on function '@f'
```
Without `sspstrong` the function compiles normally (`addvl sp, sp, #-2`). With `ssp` (non-strong) it also compiles,
because that path returns before the size comparison. `sspreq` crashes the same way, and so do the x86_64 and riscv64
triples (the pass is target-independent). Compiler Explorer llc trunk aborts with the same message.
**Root cause.** llvm/lib/CodeGen/StackProtector.cpp:250
`if (SSPBufferSize <= M->getDataLayout().getTypeAllocSize(AT))` uses `TypeSize::operator ScalarTy()`, which fails
for scalable sizes. The `Strong` early return (`:244`) is skipped, so strong/req mode always reaches this line.
**Suggested fix.** Compare with `TypeSize::isKnownGE(getTypeAllocSize(AT), TypeSize::getFixed(SSPBufferSize))`
(or use `getKnownMinValue()`). In strong mode the array is protected either way.
Environment: LLVM 23.1.2 (85ac560262434c9ccfc0c183ec22d4138ed647fb).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs