Skip to content

Commit 01f6c4c

Browse files
authored
Fix remove-addrspaces pass in the presence of globals with addrspaces (#51782)
This fixes an assertion that might trigger if we run this pass on sysimg modules.
1 parent ef3bf66 commit 01f6c4c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/llvm-remove-addrspaces.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)
335335

336336
GlobalVariable *NGV = cast<GlobalVariable>(VMap[GV]);
337337
if (GV->hasInitializer())
338-
NGV->setInitializer(MapValue(GV->getInitializer(), VMap));
338+
NGV->setInitializer(MapValue(GV->getInitializer(), VMap, RF_None, &TypeRemapper, &Materializer));
339339

340340
SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
341341
GV->getAllMetadata(MDs);
@@ -400,7 +400,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)
400400
for (GlobalAlias *GA : Aliases) {
401401
GlobalAlias *NGA = cast<GlobalAlias>(VMap[GA]);
402402
if (const Constant *C = GA->getAliasee())
403-
NGA->setAliasee(MapValue(C, VMap));
403+
NGA->setAliasee(MapValue(C, VMap, RF_None, &TypeRemapper, &Materializer));
404404

405405
GA->setAliasee(nullptr);
406406
}

test/llvmpasses/remove-addrspaces.ll

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
; RUN: opt -enable-new-pm=1 --opaque-pointers=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='RemoveJuliaAddrspaces' -S %s | FileCheck %s --check-prefixes=CHECK,OPAQUE
66

77

8+
; COM: check that package image fptrs work
9+
@pjlsys_BoundsError_32 = internal global {} addrspace(10)* ({}***, {} addrspace(10)*, [1 x i64] addrspace(11)*)* null
10+
; CHECK: @pjlsys_BoundsError_32 = internal global
11+
; TYPED-SAME: {}* ({}***, {}*, [1 x i64]*)* null
12+
; OPAQUE-SAME: ptr null
13+
814
define i64 @getindex({} addrspace(10)* nonnull align 16 dereferenceable(40)) {
915
; CHECK-LABEL: @getindex
1016
top:

0 commit comments

Comments
 (0)