Skip to content

Commit f225b07

Browse files
authored
Utils: Preserve address space for global_ctors (#112532)
1 parent 5d08625 commit f225b07

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

llvm/lib/Transforms/Utils/CtorUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ static void removeGlobalCtors(GlobalVariable *GCL, const BitVector &CtorsToRemov
4545
}
4646

4747
// Create the new global and insert it next to the existing list.
48-
GlobalVariable *NGV =
49-
new GlobalVariable(CA->getType(), GCL->isConstant(), GCL->getLinkage(),
50-
CA, "", GCL->getThreadLocalMode());
48+
GlobalVariable *NGV = new GlobalVariable(
49+
CA->getType(), GCL->isConstant(), GCL->getLinkage(), CA, "",
50+
GCL->getThreadLocalMode(), GCL->getAddressSpace());
5151
GCL->getParent()->insertGlobalVariable(GCL->getIterator(), NGV);
5252
NGV->takeName(GCL);
5353

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5
2+
; RUN: opt -S -passes=globalopt < %s | FileCheck %s
3+
4+
; Make sure the address space of global_ctors is preserved
5+
6+
%ini = type { i32, ptr, ptr }
7+
8+
@llvm.global_ctors = appending addrspace(1) global [1 x %ini] [%ini { i32 65534, ptr @ctor1, ptr null }]
9+
10+
;.
11+
; CHECK: @llvm.global_ctors = appending addrspace(1) global [0 x %ini] zeroinitializer
12+
;.
13+
define void @ctor1() {
14+
; CHECK-LABEL: define void @ctor1() local_unnamed_addr {
15+
; CHECK-NEXT: ret void
16+
;
17+
ret void
18+
}
19+

0 commit comments

Comments
 (0)