Skip to content

Commit a4ef284

Browse files
maleadtkpamnany
authored andcommitted
Preserve LLVM function attributes during address space removal pass. (#49551)
(cherry picked from commit 4289264)
1 parent cfe6378 commit a4ef284

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/llvm-remove-addrspaces.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)
323323

324324
Function *NF = Function::Create(
325325
NFTy, F->getLinkage(), F->getAddressSpace(), Name, &M);
326-
// no need to copy attributes here, that's done by CloneFunctionInto
326+
NF->copyAttributesFrom(F);
327327
VMap[F] = NF;
328328
}
329329

@@ -385,8 +385,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)
385385
&TypeRemapper,
386386
&Materializer);
387387

388-
// CloneFunctionInto unconditionally copies the attributes from F to NF,
389-
// without considering e.g. the byval attribute type.
388+
// Update function attributes that contain types
390389
AttributeList Attrs = F->getAttributes();
391390
LLVMContext &C = F->getContext();
392391
for (unsigned i = 0; i < Attrs.getNumAttrSets(); ++i) {

test/llvmpasses/remove-addrspaces.ll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ top:
4747
%list = type { i64, %list* }
4848

4949
; COM: There's nothing to remove in this function; but remove-addrspaces shouldn't crash.
50-
define i64 @sum.linked.list() #0 {
50+
define i64 @sum.linked.list() {
5151
; CHECK-LABEL: @sum.linked.list
5252
top:
5353
%a = alloca %list
@@ -109,3 +109,9 @@ define void @byval_type([1 x {} addrspace(10)*] addrspace(11)* byval([1 x {} add
109109
; CHECK: define void @byval_type([1 x {}*]* byval([1 x {}*]) %0)
110110
ret void
111111
}
112+
113+
114+
; COM: check that other function attributes are preserved
115+
declare void @convergent_function() #0
116+
attributes #0 = { convergent }
117+
; CHECK: attributes #0 = { convergent }

0 commit comments

Comments
 (0)