Skip to content

Commit 088bb90

Browse files
authored
Fix removal of globals with addrspaces in removeAddrspaces (#58322)
1 parent c894e04 commit 088bb90

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/llvm-remove-addrspaces.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)
256256
Name,
257257
(GlobalVariable *)nullptr,
258258
GV->getThreadLocalMode(),
259-
GV->getType()->getAddressSpace());
259+
cast<PointerType>(TypeRemapper.remapType(GV->getType()))->getAddressSpace());
260260
NGV->copyAttributesFrom(GV);
261261
VMap[GV] = NGV;
262262
}
@@ -276,7 +276,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)
276276

277277
auto *NGA = GlobalAlias::create(
278278
TypeRemapper.remapType(GA->getValueType()),
279-
GA->getType()->getPointerAddressSpace(),
279+
cast<PointerType>(TypeRemapper.remapType(GA->getType()))->getAddressSpace(),
280280
GA->getLinkage(),
281281
Name,
282282
&M);

test/llvmpasses/remove-addrspaces.ll

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
; RUN: opt --load-pass-plugin=libjulia-codegen%shlibext -passes='RemoveJuliaAddrspaces' -S %s | FileCheck %s --check-prefixes=CHECK,OPAQUE
44

5+
; COM: check that the addrspace of the global itself is removed
6+
; OPAQUE: @ejl_enz_runtime_exc = external global {}
7+
@ejl_enz_runtime_exc = external addrspace(10) global {}
58

69
; COM: check that package image fptrs work
710
@pjlsys_BoundsError_32 = internal global {} addrspace(10)* ({}***, {} addrspace(10)*, [1 x i64] addrspace(11)*)* null
@@ -111,6 +114,13 @@ define void @byval_type([1 x {} addrspace(10)*] addrspace(11)* byval([1 x {} add
111114
}
112115

113116

117+
define private fastcc void @diffejulia__mapreduce_97() {
118+
L6:
119+
; OPAQUE: store atomic ptr @ejl_enz_runtime_exc, ptr null unordered
120+
store atomic {} addrspace(10)* @ejl_enz_runtime_exc, {} addrspace(10)* addrspace(10)* null unordered, align 8
121+
unreachable
122+
}
123+
114124
; COM: check that function attributes are preserved on declarations too
115125
declare void @convergent_function() #0
116126
attributes #0 = { convergent }

0 commit comments

Comments
 (0)