Skip to content

Commit 055bf82

Browse files
maleadtKristofferC
authored andcommitted
Ensure LLVM function attributes are preserved by always calling CloneFunctionInto.
(cherry picked from commit f77ad0a)
1 parent d78c5f8 commit 055bf82

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/llvm-remove-addrspaces.cpp

Lines changed: 2 additions & 4 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-
NF->copyAttributesFrom(F);
326+
// no need to copy attributes here, that's done by CloneFunctionInto
327327
VMap[F] = NF;
328328
}
329329

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

357357
// Similarly, copy over and rewrite function bodies
358358
for (Function *F : Functions) {
359-
if (F->isDeclaration())
360-
continue;
361-
362359
Function *NF = cast<Function>(VMap[F]);
363360
LLVM_DEBUG(dbgs() << "Processing function " << NF->getName() << "\n");
361+
// we also need this to run for declarations, or attributes won't be copied
364362

365363
Function::arg_iterator DestI = NF->arg_begin();
366364
for (Function::const_arg_iterator I = F->arg_begin(); I != F->arg_end();

test/llvmpasses/remove-addrspaces.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ define void @byval_type([1 x {} addrspace(10)*] addrspace(11)* byval([1 x {} add
111111
}
112112

113113

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

0 commit comments

Comments
 (0)