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

[Clang] Fix argument extensions in CGBlocks.cpp #111740

Closed
wants to merge 3 commits into from
Closed
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
9 changes: 7 additions & 2 deletions clang/lib/CodeGen/CGBlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,10 @@ llvm::FunctionCallee CodeGenModule::getBlockObjectDispose() {
llvm::Type *args[] = { Int8PtrTy, Int32Ty };
llvm::FunctionType *fty
= llvm::FunctionType::get(VoidTy, args, false);
BlockObjectDispose = CreateRuntimeFunction(fty, "_Block_object_dispose");
llvm::AttributeList AL =
getTargetExtAttrs({AttrKind::None, AttrKind::None, AttrKind::SExt});
BlockObjectDispose = CreateRuntimeFunction(fty, "_Block_object_dispose", AL);
// FIXME: Correct signedness of extension??
configureBlocksRuntimeObject(
*this, cast<llvm::Constant>(BlockObjectDispose.getCallee()));
return BlockObjectDispose;
Expand All @@ -2854,7 +2857,9 @@ llvm::FunctionCallee CodeGenModule::getBlockObjectAssign() {
llvm::Type *args[] = { Int8PtrTy, Int8PtrTy, Int32Ty };
llvm::FunctionType *fty
= llvm::FunctionType::get(VoidTy, args, false);
BlockObjectAssign = CreateRuntimeFunction(fty, "_Block_object_assign");
llvm::AttributeList AL = getTargetExtAttrs(
{AttrKind::None, AttrKind::None, AttrKind::None, AttrKind::SExt});
BlockObjectAssign = CreateRuntimeFunction(fty, "_Block_object_assign", AL);
configureBlocksRuntimeObject(
*this, cast<llvm::Constant>(BlockObjectAssign.getCallee()));
return BlockObjectAssign;
Expand Down
43 changes: 43 additions & 0 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4755,6 +4755,15 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
llvm::AttrBuilder B(F->getContext(), ExtraAttrs.getFnAttrs());
F->addFnAttrs(B);
}
if (ExtraAttrs.hasRetAttrs()) {
llvm::AttrBuilder B(F->getContext(), ExtraAttrs.getRetAttrs());
F->addRetAttrs(B);
}
for (unsigned i = 0; i < F->arg_size(); ++i)
if (ExtraAttrs.hasParamAttrs(i)) {
llvm::AttrBuilder B(F->getContext(), ExtraAttrs.getParamAttrs(i));
F->addParamAttrs(i, B);
}

if (!DontDefer) {
// All MSVC dtors other than the base dtor are linkonce_odr and delegate to
Expand Down Expand Up @@ -4938,6 +4947,40 @@ CodeGenModule::CreateRuntimeFunction(llvm::FunctionType *FTy, StringRef Name,
return {FTy, C};
}

llvm::AttributeList
CodeGenModule::getTargetExtAttrs(ArrayRef<AttrKind> Extensions) {
using AttrIndex = llvm::AttributeList::AttrIndex;
assert(Extensions.size() && "Empty array not expected.");
const auto &T = getTarget().getTriple();
llvm::AttributeList AL;

bool IsSigned;
auto isExtension = [&IsSigned](AttrKind AK) -> bool {
assert((AK == AttrKind::None || AK == AttrKind::SExt ||
AK == AttrKind::ZExt) &&
"Unhandled extension attribute.");
if (AK != AttrKind::SExt && AK != AttrKind::ZExt)
return false;
IsSigned = (AK == AttrKind::SExt);
return true;
};

if (isExtension(Extensions[0])) { // Returned value at index 0.
AttrKind AK = llvm::TargetLibraryInfo::getExtAttrForI32Return(T, IsSigned);
if (AK != AttrKind::None)
AL = AL.addAttributeAtIndex(getLLVMContext(), AttrIndex::ReturnIndex, AK);
}
for (unsigned i = 1; i < Extensions.size(); ++i)
if (isExtension(Extensions[i])) {
AttrKind AK = llvm::TargetLibraryInfo::getExtAttrForI32Param(T, IsSigned);
if (AK != AttrKind::None)
AL = AL.addAttributeAtIndex(getLLVMContext(),
AttrIndex::FirstArgIndex + i - 1, AK);
}

return AL;
}

/// GetOrCreateLLVMGlobal - If the specified mangled name is not in the module,
/// create and return an llvm GlobalVariable with the specified type and address
/// space. If there is something in the module with the specified name, return
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/CodeGen/CodeGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,12 @@ class CodeGenModule : public CodeGenTypeCache {
llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
bool Local = false, bool AssumeConvergent = false);

/// Return the extension attributes as an AttributeList after any needed
/// adjustments for target. The \Param Extensions list begins with the
/// return value and then continues with the arguments.
using AttrKind = llvm::Attribute::AttrKind;
llvm::AttributeList getTargetExtAttrs(ArrayRef<AttrKind> Extensions);

/// Create a new runtime global variable with the specified type and name.
llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
StringRef Name);
Expand Down
Loading