authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-10 15:42:57-07:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-02-12 11:18:23+01:00
logf293fbbeaf6c48e6ce1410743181f89f359eb697
treea9df71d5e092872e8ba68a03337a03c3481f486b
parentbeb275b371cd50ee1d57528d2792f2f267e6013d

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.

1 files changed, 5 insertions(+), 1 deletions(-)

src/codegen/llvm.zig+5-1
...@@ -661,7 +661,11 @@ pub const DeclGen = struct {...@@ -661,7 +661,11 @@ pub const DeclGen = struct {
661 new_global.setUnnamedAddr(global.getUnnamedAddress());661 new_global.setUnnamedAddr(global.getUnnamedAddress());
662 new_global.setAlignment(global.getAlignment());662 new_global.setAlignment(global.getAlignment());
663 new_global.setInitializer(llvm_init);663 new_global.setInitializer(llvm_init);
664 global.replaceAllUsesWith(new_global);664 // replaceAllUsesWith requires the type to be unchanged. So we bitcast
665 // the new global to the old type and use that as the thing to replace
666 // old uses.
667 const new_global_ptr = new_global.constBitCast(global.typeOf());
668 global.replaceAllUsesWith(new_global_ptr);
665 dg.object.decl_map.putAssumeCapacity(decl, new_global);669 dg.object.decl_map.putAssumeCapacity(decl, new_global);
666 new_global.takeName(global);670 new_global.takeName(global);
667 global.deleteGlobal();671 global.deleteGlobal();