Skip to content

Commit 33786cf

Browse files
committed
Backport of 088bb90
(Fix removal of globals with addrspaces in removeAddrspaces (#58322))
1 parent 3997241 commit 33786cf

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/llvm-remove-addrspaces.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)
270270
Name,
271271
(GlobalVariable *)nullptr,
272272
GV->getThreadLocalMode(),
273-
GV->getType()->getAddressSpace());
273+
cast<PointerType>(TypeRemapper.remapType(GV->getType()))->getAddressSpace());
274274
NGV->copyAttributesFrom(GV);
275275
VMap[GV] = NGV;
276276
}
@@ -290,7 +290,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)
290290

291291
auto *NGA = GlobalAlias::create(
292292
TypeRemapper.remapType(GA->getValueType()),
293-
GA->getType()->getPointerAddressSpace(),
293+
cast<PointerType>(TypeRemapper.remapType(GA->getType()))->getAddressSpace(),
294294
GA->getLinkage(),
295295
Name,
296296
&M);

test/llvmpasses/remove-addrspaces.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
; TYPED-SAME: {}* ({}***, {}*, [1 x i64]*)* null
1212
; OPAQUE-SAME: ptr null
1313

14+
; COM: check that the addrspace of the global itself is removed
15+
; OPAQUE: @ejl_enz_runtime_exc = external global {}
16+
@ejl_enz_runtime_exc = external addrspace(10) global {}
17+
1418
define i64 @getindex({} addrspace(10)* nonnull align 16 dereferenceable(40)) {
1519
; CHECK-LABEL: @getindex
1620
top:
@@ -121,6 +125,13 @@ define void @byval_type([1 x {} addrspace(10)*] addrspace(11)* byval([1 x {} add
121125
ret void
122126
}
123127

128+
define private fastcc void @diffejulia__mapreduce_97() {
129+
L6:
130+
; OPAQUE: store atomic ptr @ejl_enz_runtime_exc, ptr null unordered
131+
store atomic {} addrspace(10)* @ejl_enz_runtime_exc, {} addrspace(10)* addrspace(10)* null unordered, align 8
132+
unreachable
133+
}
134+
124135

125136
; COM: check that function attributes are preserved on declarations too
126137
declare void @convergent_function() #0

0 commit comments

Comments
 (0)