Skip to content

change LLVMBuildPointerCast to LLVMBuildAddrSpaceCast#289

Merged
FractalFir merged 1 commit intoRust-GPU:mainfrom
PMQ9:bugfix/issue_264_casting_between_address_space_using_bitcasts_is_undefined_behavior
Oct 14, 2025
Merged

change LLVMBuildPointerCast to LLVMBuildAddrSpaceCast#289
FractalFir merged 1 commit intoRust-GPU:mainfrom
PMQ9:bugfix/issue_264_casting_between_address_space_using_bitcasts_is_undefined_behavior

Conversation

@PMQ9
Copy link
Copy Markdown
Contributor

@PMQ9 PMQ9 commented Oct 12, 2025

Description:

Explained in this issue:
#264

Changes Made

Fixed undefined behavior where LLVMBuildPointerCast and LLVMBuildBitCast were being used to change pointer address spaces.

Modified two locations in builder.rs:

  1. alloca() method: Now uses LLVMBuildAddrSpaceCast when address spaces differ
  2. pointercast() method: Detects address space changes and routes to the correct cast instruction

All other bitcast/pointer cast uses in the codebase lgtm (either already handle address spaces correctly or don't change address spaces).

Test:

  • cargo fmt --all -- --check -> passes
  • cargo clippy -p rustc_codegen_nvvm -> passes

Note: Some GPU kernel examples (vecadd, gemm, sha2_crates_io) fail during workspace compilation due to runtime DLL loading issues on Windows (unrelated to these changes). Mentioned in: .github/workflows/ci_windows.yml:104.

@LegNeato
Copy link
Copy Markdown
Contributor

Thanks for the PR, and welcome to the project! 🍻 . I'll let @FractalFir review as he is mroe familiar with this stuff.

@FractalFir
Copy link
Copy Markdown
Collaborator

The code looks fine to me. Merging.

@FractalFir FractalFir merged commit 2e763da into Rust-GPU:main Oct 14, 2025
12 checks passed
@PMQ9 PMQ9 deleted the bugfix/issue_264_casting_between_address_space_using_bitcasts_is_undefined_behavior branch November 11, 2025 21:10
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.

3 participants