Skip to content

[Fix][LLVM] Preserve 64-bit AllocBuffer extents - #20141

Draft
fallenmi wants to merge 1 commit into
apache:mainfrom
fallenmi:agent/fix-llvm-allocbuffer-size
Draft

[Fix][LLVM] Preserve 64-bit AllocBuffer extents#20141
fallenmi wants to merge 1 commit into
apache:mainfrom
fallenmi:agent/fix-llvm-allocbuffer-size

Conversation

@fallenmi

Copy link
Copy Markdown

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 Draft 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

LLVM code generation narrowed constant AllocBuffer extents to int32 before creating stack allocations. Preserve the signed 64-bit extent through alignment calculation and LLVM alloca emission, while avoiding overflow in the alignment helper.

Add compile-only regression coverage for large extents that previously wrapped to one or four elements.

Generated-by: OpenAI Codex
@yongwww yongwww closed this Aug 17, 2026
@yongwww yongwww reopened this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] LLVM backend truncates large AllocBuffer size from int64 to int32

2 participants