Repository navigation
Commit 920faa8
authored
[Fix][LLVM] Preserve 64-bit AllocBuffer extents (#20141)
Fixes #20125.
## What changed
LLVM CPU code generation now keeps constant `AllocBuffer` extents as
signed 64-bit values through stack allocation emission instead of
narrowing them to `int32_t`. The temporary-allocation alignment helper
accepts the same width and avoids multiplying when a large allocation
cannot reduce the requested alignment, preventing overflow in that
calculation.
This change is intentionally limited to the CPU `CodeGenLLVM` path. The
separate NVPTX and AMDGPU overrides described in the issue remain out of
scope.
## Why
An extent of `2**32 + 1` previously wrapped to one before
`CreateAlloca`, producing a one-element stack allocation followed by an
`i64 4294967296` element access in unoptimized TIR-X LLVM IR. The
generated module could therefore contain an out-of-bounds access even
though the original extent was valid as an `int64_t`.
The regression test only compiles and inspects LLVM IR; it does not
execute or materialize the very large allocation. It covers extents that
previously wrapped to one and four elements.
## Validation
- New regression on the unmodified base: 2 failures
- New regression after the fix: 2 passed
- `tests/python/codegen/test_target_codegen_llvm.py`: 380 passed
- Rebuilt all 65 affected C++ units, including the NVPTX and AMDGPU
callers of the alignment helper
- Changed-file pre-commit hooks and `git diff --check`: passed
- Compile-only boundary probes through `INT64_MAX - 3`: exact `i64`
allocation counts, with no allocation executed
## AI assistance
This PR was prepared with OpenAI Codex. The patch was derived from the
repository and the issue's documented failure mode; no external
third-party code was copied into the change.
Generated-by: OpenAI Codex
Co-authored-by: Igor Stadnyk <[email protected]>1 parent d8fcef2 commit 920faa8
3 files changed
Lines changed: 34 additions & 6 deletions
File tree
- src
- target/llvm
- tirx/transform
- tests/python/codegen
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2191 | 2191 | | |
2192 | 2192 | | |
2193 | 2193 | | |
2194 | | - | |
| 2194 | + | |
2195 | 2195 | | |
2196 | 2196 | | |
2197 | 2197 | | |
| |||
2206 | 2206 | | |
2207 | 2207 | | |
2208 | 2208 | | |
2209 | | - | |
| 2209 | + | |
2210 | 2210 | | |
2211 | 2211 | | |
2212 | 2212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
188 | | - | |
189 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
190 | 195 | | |
191 | 196 | | |
192 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
957 | 957 | | |
958 | 958 | | |
959 | 959 | | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
960 | 983 | | |
961 | 984 | | |
962 | 985 | | |
| |||
0 commit comments