From f77ad0a93e283cf104fbc8c38380bfe062dfd765 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 2 May 2023 14:16:57 +0200 Subject: [PATCH 1/2] Ensure LLVM function attributes are preserved by always calling CloneFunctionInto. --- src/llvm-remove-addrspaces.cpp | 6 ++---- test/llvmpasses/remove-addrspaces.ll | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/llvm-remove-addrspaces.cpp b/src/llvm-remove-addrspaces.cpp index 4a3290da0ecf5..50c3be1b83444 100644 --- a/src/llvm-remove-addrspaces.cpp +++ b/src/llvm-remove-addrspaces.cpp @@ -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; } @@ -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(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(); diff --git a/test/llvmpasses/remove-addrspaces.ll b/test/llvmpasses/remove-addrspaces.ll index 26406d2ca7d98..a748b3843bacb 100644 --- a/test/llvmpasses/remove-addrspaces.ll +++ b/test/llvmpasses/remove-addrspaces.ll @@ -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 } From b815bb160932da5300a8db71cae8d8970faaa8d5 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 2 May 2023 14:19:42 +0200 Subject: [PATCH 2/2] Don't explicitly remap the personality function. LLVM does this already. --- src/llvm-remove-addrspaces.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/llvm-remove-addrspaces.cpp b/src/llvm-remove-addrspaces.cpp index 50c3be1b83444..32bd4e563ac92 100644 --- a/src/llvm-remove-addrspaces.cpp +++ b/src/llvm-remove-addrspaces.cpp @@ -408,9 +408,6 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper) } NF->setAttributes(Attrs); - if (F->hasPersonalityFn()) - NF->setPersonalityFn(MapValue(F->getPersonalityFn(), VMap)); - copyComdat(NF, F); RemoveNoopAddrSpaceCasts(NF);