rust/compiler/rustc_codegen_llvm/src/debuginfo
Matthias Krüger 89f8abe8b4
Rollup merge of #135026 - Flakebi:global-addrspace, r=saethlin
Cast global variables to default address space

Pointers for variables all need to be in the same address space for correct compilation. Therefore ensure that even if a global variable 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 global variables is not 0.

For example `core` does not compile in debug mode when not casting the address space to the default one because it tries to emit the following (simplified) LLVM IR, containing a type mismatch:

```llvm
`@alloc_0` = addrspace(1) constant <{ [6 x i8] }> <{ [6 x i8] c"bit.rs" }>, align 1
`@alloc_1` = addrspace(1) constant <{ ptr }> <{ ptr addrspace(1) `@alloc_0` }>, align 8
; ^ here a struct containing a `ptr` is needed, but it is created using a `ptr addrspace(1)`
```

For this to compile, we need to insert a constant `addrspacecast` before we use a global variable:

```llvm
`@alloc_0` = addrspace(1) constant <{ [6 x i8] }> <{ [6 x i8] c"bit.rs" }>, align 1
`@alloc_1` = addrspace(1) constant <{ ptr }> <{ ptr addrspacecast (ptr addrspace(1) `@alloc_0` to ptr) }>, align 8
```

As vtables are global variables as well, they are also created with an `addrspacecast`. In the SSA backend, after a vtable global is created, metadata is added to it. To add metadata, we need the non-casted global variable. Therefore we strip away an addrspacecast if there is one, to get the underlying global.

Tracking issue: #135024
2025-01-30 20:47:02 +01:00
..
metadata Use gimli to get the values of DWARF constants needed by codegen 2025-01-05 22:07:48 +11:00
create_scope_map.rs When LLVM's location discriminator value limit is exceeded, emit locations with dummy spans instead of dropping them entirely 2025-01-19 07:17:33 -08:00
doc.md fix most compiler/ doctests 2022-05-02 17:40:30 -07:00
dwarf_const.rs Use constants for DWARF opcodes, instead of FFI calls 2025-01-05 22:16:25 +11:00
gdb.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
metadata.rs Rollup merge of #135026 - Flakebi:global-addrspace, r=saethlin 2025-01-30 20:47:02 +01:00
mod.rs When LLVM's location discriminator value limit is exceeded, emit locations with dummy spans instead of dropping them entirely 2025-01-19 07:17:33 -08:00
namespace.rs Use a type-safe helper to cast &str and &[u8] to *const c_char 2024-10-28 21:31:32 +11:00
utils.rs use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00