Skip to content

Commit e96f652

Browse files
authored
[NFC][IR] Add SetNoSanitize helpers (#86772)
This will be used by #86775
1 parent 96b3969 commit e96f652

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

llvm/include/llvm/IR/GlobalValue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ class GlobalValue : public Constant {
360360
// storage is shared between `G1` and `G2`.
361361
void setSanitizerMetadata(SanitizerMetadata Meta);
362362
void removeSanitizerMetadata();
363+
void setNoSanitizeMetadata();
363364

364365
bool isTagged() const {
365366
return hasSanitizerMetadata() && getSanitizerMetadata().Memtag;

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ class IRBuilderBase {
221221
AddOrRemoveMetadataToCopy(LLVMContext::MD_dbg, L.getAsMDNode());
222222
}
223223

224+
/// Set nosanitize metadata.
225+
void SetNoSanitizeMetadata() {
226+
AddOrRemoveMetadataToCopy(llvm::LLVMContext::MD_nosanitize,
227+
llvm::MDNode::get(getContext(), std::nullopt));
228+
}
229+
224230
/// Collect metadata with IDs \p MetadataKinds from \p Src which should be
225231
/// added to all created instructions. Entries present in MedataDataToCopy but
226232
/// not on \p Src will be dropped from MetadataToCopy.

llvm/lib/IR/Globals.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ void GlobalValue::removeSanitizerMetadata() {
243243
HasSanitizerMetadata = false;
244244
}
245245

246+
void GlobalValue::setNoSanitizeMetadata() {
247+
SanitizerMetadata Meta;
248+
Meta.NoAddress = true;
249+
Meta.NoHWAddress = true;
250+
setSanitizerMetadata(Meta);
251+
}
252+
246253
StringRef GlobalObject::getSectionImpl() const {
247254
assert(hasSection());
248255
return getContext().pImpl->GlobalObjectSections[this];

0 commit comments

Comments
 (0)