Skip to content

Commit

Permalink
Ensure LLVM function attributes are preserved by always calling Clone…
Browse files Browse the repository at this point in the history
…FunctionInto.

(cherry picked from commit f77ad0a)
  • Loading branch information
maleadt authored and KristofferC committed May 8, 2023
1 parent d78c5f8 commit 055bf82
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 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);
NF->copyAttributesFrom(F);
// no need to copy attributes here, that's done by CloneFunctionInto
VMap[F] = NF;
}

Expand Down Expand Up @@ -356,11 +356,9 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)

// Similarly, copy over and rewrite function bodies
for (Function *F : Functions) {
if (F->isDeclaration())
continue;

Function *NF = cast<Function>(VMap[F]);
LLVM_DEBUG(dbgs() << "Processing function " << NF->getName() << "\n");
// we also need this to run for declarations, or attributes won't be copied

Function::arg_iterator DestI = NF->arg_begin();
for (Function::const_arg_iterator I = F->arg_begin(); I != F->arg_end();
Expand Down
2 changes: 1 addition & 1 deletion test/llvmpasses/remove-addrspaces.ll
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ define void @byval_type([1 x {} addrspace(10)*] addrspace(11)* byval([1 x {} add
}


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

0 comments on commit 055bf82

Please sign in to comment.