From 13c0624f23bbf63b31ae9b8f06aa2e32c1616e94 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Sat, 1 Jul 2023 20:25:25 +0200 Subject: llvm: cast optional null ptr representation to generic address space The panic handler expects that this value is represented with the generic address space, so cast the global to the generic address- space before caching and returning the value. --- src/codegen/llvm.zig | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/codegen') diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index d42195d7e9..24ff706711 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -2435,18 +2435,25 @@ pub const Object = struct { .ty = ty.toType(), .val = null_opt_usize.toValue(), }); + const llvm_wanted_addrspace = toLlvmAddressSpace(.generic, target); + const llvm_actual_addrspace = toLlvmGlobalAddressSpace(.generic, target); const global = o.llvm_module.addGlobalInAddressSpace( llvm_init.typeOf(), "", - toLlvmGlobalAddressSpace(.generic, target), + llvm_actual_addrspace, ); global.setLinkage(.Internal); global.setUnnamedAddr(.True); global.setAlignment(ty.toType().abiAlignment(mod)); global.setInitializer(llvm_init); - o.null_opt_addr = global; - return global; + const addrspace_casted_global = if (llvm_wanted_addrspace != llvm_actual_addrspace) + global.constAddrSpaceCast(o.context.pointerType(llvm_wanted_addrspace)) + else + global; + + o.null_opt_addr = addrspace_casted_global; + return addrspace_casted_global; } /// If the llvm function does not exist, create it. -- cgit v1.2.3