Skip to content

Commit

Permalink
[NFC][IR] Add SetNoSanitize helpers (#86772)
Browse files Browse the repository at this point in the history
This will be used by #86775
  • Loading branch information
vitalybuka committed Mar 27, 2024
1 parent 96b3969 commit e96f652
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
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

0 comments on commit e96f652

Please sign in to comment.