[clang] [clang][CodeGen] add addr space cast if needed when storing ptrs (PR #154380)

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 20 10:50:03 PDT 2025


================
@@ -2209,6 +2209,18 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr,
     }
   }
 
+  // When storing a pointer, perform address space cast if needed.
----------------
macurtis-amd wrote:

Thanks for the explanation.

I actually did some more investigation and determined that the mismatched address space originates in the [the `NVRO` branch](https://github.com/llvm/llvm-project/blob/35be64a416813c91bd267cfe11f31ef024c7143b/clang/lib/CodeGen/CGDecl.cpp#L1566) of  [`EmitAutoVarAlloca`](https://github.com/llvm/llvm-project/blob/35be64a416813c91bd267cfe11f31ef024c7143b/clang/lib/CodeGen/CGDecl.cpp#L1483).

While `AllocaAddr` is ok in `addrspace(5)`, `address` is really expected to be in the default address space and the `NVRO` branch needs something like the code [here](https://github.com/llvm/llvm-project/blob/35be64a416813c91bd267cfe11f31ef024c7143b/clang/lib/CodeGen/CGExpr.cpp#L124).

Does this sound right to you?

https://github.com/llvm/llvm-project/pull/154380


More information about the cfe-commits mailing list