Skip to content

Commit

Permalink
Strip address information from typed function parameters attributes. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt authored Sep 30, 2021
1 parent 6a335e3 commit dc627e7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/llvm-remove-addrspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ bool RemoveAddrspacesPass::runOnModule(Module &M)

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 @@ -387,6 +387,22 @@ bool RemoveAddrspacesPass::runOnModule(Module &M)
&TypeRemapper,
&Materializer);

// CloneFunctionInto unconditionally copies the attributes from F to NF,
// without considering e.g. the byval attribute type.
AttributeList Attrs = F->getAttributes();
LLVMContext &C = F->getContext();
for (unsigned i = 0; i < Attrs.getNumAttrSets(); ++i) {
for (Attribute::AttrKind TypedAttr :
{Attribute::ByVal, Attribute::StructRet, Attribute::ByRef}) {
if (Type *Ty = Attrs.getAttribute(i, TypedAttr).getValueAsType()) {
Attrs = Attrs.replaceAttributeType(C, i, TypedAttr,
TypeRemapper.remapType(Ty));
break;
}
}
}
NF->setAttributes(Attrs);

if (F->hasPersonalityFn())
NF->setPersonalityFn(MapValue(F->getPersonalityFn(), VMap));

Expand Down
7 changes: 7 additions & 0 deletions test/llvmpasses/remove-addrspaces.ll
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@ loop:
exit:
ret i64 %sum
}


; COM: check that address spaces in byval types are processed correctly
define void @byval_type([1 x {} addrspace(10)*] addrspace(11)* byval([1 x {} addrspace(10)*]) %0) {
; CHECK: define void @byval_type([1 x {}*]* byval([1 x {}*]) %0)
ret void
}

0 comments on commit dc627e7

Please sign in to comment.