zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit f293fbbeaf6c48e6ce1410743181f89f359eb697 (tree)
parent beb275b371cd50ee1d57528d2792f2f267e6013d
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu, 10 Feb 2022 15:42:57 -0700

stage2: LLVM backend: adjust replaceAllUsesWith usage

replaceAllUsesWith requires the type to be unchanged. So we bitcast
the new global to the old type and use that as the thing to replace
old uses.

Fixes an LLVM assertion found while troubleshooting #10837.

Diffstat:
Msrc/codegen/llvm.zig | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig @@ -661,7 +661,11 @@ pub const DeclGen = struct { new_global.setUnnamedAddr(global.getUnnamedAddress()); new_global.setAlignment(global.getAlignment()); new_global.setInitializer(llvm_init); - global.replaceAllUsesWith(new_global); + // replaceAllUsesWith requires the type to be unchanged. So we bitcast + // the new global to the old type and use that as the thing to replace + // old uses. + const new_global_ptr = new_global.constBitCast(global.typeOf()); + global.replaceAllUsesWith(new_global_ptr); dg.object.decl_map.putAssumeCapacity(decl, new_global); new_global.takeName(global); global.deleteGlobal();