Skip to content

Commit

Permalink
Preserve LLVM function attributes during address space removal pass. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt authored Apr 28, 2023
1 parent ee7538e commit 4289264
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/llvm-remove-addrspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)

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

Expand Down Expand Up @@ -385,8 +385,7 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)
&TypeRemapper,
&Materializer);

// CloneFunctionInto unconditionally copies the attributes from F to NF,
// without considering e.g. the byval attribute type.
// Update function attributes that contain types
AttributeList Attrs = F->getAttributes();
LLVMContext &C = F->getContext();
for (unsigned i = 0; i < Attrs.getNumAttrSets(); ++i) {
Expand Down
8 changes: 7 additions & 1 deletion test/llvmpasses/remove-addrspaces.ll
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ top:
%list = type { i64, %list* }

; COM: There's nothing to remove in this function; but remove-addrspaces shouldn't crash.
define i64 @sum.linked.list() #0 {
define i64 @sum.linked.list() {
; CHECK-LABEL: @sum.linked.list
top:
%a = alloca %list
Expand Down Expand Up @@ -109,3 +109,9 @@ define void @byval_type([1 x {} addrspace(10)*] addrspace(11)* byval([1 x {} add
; CHECK: define void @byval_type([1 x {}*]* byval([1 x {}*]) %0)
ret void
}


; COM: check that other function attributes are preserved
declare void @convergent_function() #0
attributes #0 = { convergent }
; CHECK: attributes #0 = { convergent }

0 comments on commit 4289264

Please sign in to comment.