Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Utils/CtorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ static void removeGlobalCtors(GlobalVariable *GCL, const BitVector &CtorsToRemov
}

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

Expand Down
19 changes: 19 additions & 0 deletions llvm/test/Transforms/GlobalOpt/ctor-list-preserve-addrspace.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5
; RUN: opt -S -passes=globalopt < %s | FileCheck %s

; Make sure the address space of global_ctors is preserved

%ini = type { i32, ptr, ptr }

@llvm.global_ctors = appending addrspace(1) global [1 x %ini] [%ini { i32 65534, ptr @ctor1, ptr null }]

;.
; CHECK: @llvm.global_ctors = appending addrspace(1) global [0 x %ini] zeroinitializer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it become [0 x %ini] afterwards?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It decided to remove the one entry (I guess this is a pass optimization bug, it should probably just delete the whole thing in this case)

;.
define void @ctor1() {
; CHECK-LABEL: define void @ctor1() local_unnamed_addr {
; CHECK-NEXT: ret void
;
ret void
}