Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip address information from byval type parameters. #42395

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}