Skip to content

[NFC][IR] Add SetNoSanitize helpers #86772

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

Merged
merged 9 commits into from
Mar 27, 2024
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
1 change: 1 addition & 0 deletions llvm/include/llvm/IR/GlobalValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ class GlobalValue : public Constant {
// storage is shared between `G1` and `G2`.
void setSanitizerMetadata(SanitizerMetadata Meta);
void removeSanitizerMetadata();
void setNoSanitizeMetadata();

bool isTagged() const {
return hasSanitizerMetadata() && getSanitizerMetadata().Memtag;
Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/IR/IRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ class IRBuilderBase {
AddOrRemoveMetadataToCopy(LLVMContext::MD_dbg, L.getAsMDNode());
}

/// Set nosanitize metadata.
void SetNoSanitizeMetadata() {
AddOrRemoveMetadataToCopy(llvm::LLVMContext::MD_nosanitize,
llvm::MDNode::get(getContext(), std::nullopt));
}

/// Collect metadata with IDs \p MetadataKinds from \p Src which should be
/// added to all created instructions. Entries present in MedataDataToCopy but
/// not on \p Src will be dropped from MetadataToCopy.
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/IR/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ void GlobalValue::removeSanitizerMetadata() {
HasSanitizerMetadata = false;
}

void GlobalValue::setNoSanitizeMetadata() {
SanitizerMetadata Meta;
Meta.NoAddress = true;
Meta.NoHWAddress = true;
setSanitizerMetadata(Meta);
}

StringRef GlobalObject::getSectionImpl() const {
assert(hasSection());
return getContext().pImpl->GlobalObjectSections[this];
Expand Down