Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/rust
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: dfd5add
Choose a base ref
...
head repository: rust-lang/rust
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cde7e80
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Feb 10, 2025

  1. Cast allocas to default address space

    Pointers for variables all need to be in the same address space for
    correct compilation. Therefore ensure that even if an `alloca` is
    created in a different address space, it is casted to the default
    address space before its value is used.
    
    This is necessary for the amdgpu target and others where the default
    address space for `alloca`s is not 0.
    
    For example the following code compiles incorrectly when not casting the
    address space to the default one:
    
    ```rust
    fn f(p: *const i8 /* addrspace(0) */) -> *const i8 /* addrspace(0) */ {
        let local = 0i8; /* addrspace(5) */
        let res = if cond { p } else { &raw const local };
        res
    }
    ```
    
    results in
    
    ```llvm
        %local = alloca addrspace(5) i8
        %res = alloca addrspace(5) ptr
    
    if:
        ; Store 64-bit flat pointer
        store ptr %p, ptr addrspace(5) %res
    
    else:
        ; Store 32-bit scratch pointer
        store ptr addrspace(5) %local, ptr addrspace(5) %res
    
    ret:
        ; Load and return 64-bit flat pointer
        %res.load = load ptr, ptr addrspace(5) %res
        ret ptr %res.load
    ```
    
    For amdgpu, `addrspace(0)` are 64-bit pointers, `addrspace(5)` are
    32-bit pointers.
    The above code may store a 32-bit pointer and read it back as a 64-bit
    pointer, which is obviously wrong and cannot work. Instead, we need to
    `addrspacecast %local to ptr addrspace(0)`, then we store and load the
    correct type.
    Flakebi committed Feb 10, 2025
    Configuration menu
    Copy the full SHA
    cde7e80 View commit details
    Browse the repository at this point in the history
Loading