Skip to content

[IR] Add a helper Function::isReturnNonNull #128107

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

Closed
wants to merge 1 commit 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
5 changes: 5 additions & 0 deletions llvm/include/llvm/IR/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,11 @@ class LLVM_ABI Function : public GlobalObject, public ilist_node<Function> {
/// create a Function) from the Function Src to this one.
void copyAttributesFrom(const Function *Src);

/// Return true if the return value is known to be not null.
/// This may be because it has the nonnull attribute, or because at least
/// one byte is dereferenceable and the pointer is in addrspace(0).
bool isReturnNonNull() const;

/// deleteBody - This method deletes the body of the function, and converts
/// the linkage to external.
///
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/IR/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,17 @@ void Function::copyAttributesFrom(const Function *Src) {
setPrologueData(Src->getPrologueData());
}

bool Function::isReturnNonNull() const {
if (hasRetAttribute(Attribute::NonNull))
return true;

if (AttributeSets.getRetDereferenceableBytes() > 0 &&
!NullPointerIsDefined(this, getReturnType()->getPointerAddressSpace()))
return true;

return false;
}

MemoryEffects Function::getMemoryEffects() const {
return getAttributes().getMemoryEffects();
}
Expand Down
Loading