[llvm] e96f652 - [NFC][IR] Add SetNoSanitize helpers (#86772)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 27 10:35:40 PDT 2024


Author: Vitaly Buka
Date: 2024-03-27T10:35:37-07:00
New Revision: e96f652bd02b6b8e11c390564267ec7634ab6205

URL: https://github.com/llvm/llvm-project/commit/e96f652bd02b6b8e11c390564267ec7634ab6205
DIFF: https://github.com/llvm/llvm-project/commit/e96f652bd02b6b8e11c390564267ec7634ab6205.diff

LOG: [NFC][IR] Add SetNoSanitize helpers (#86772)

This will be used by #86775

Added: 
    

Modified: 
    llvm/include/llvm/IR/GlobalValue.h
    llvm/include/llvm/IR/IRBuilder.h
    llvm/lib/IR/Globals.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h
index aa8188cd99fee1..c61d502aa332b0 100644
--- a/llvm/include/llvm/IR/GlobalValue.h
+++ b/llvm/include/llvm/IR/GlobalValue.h
@@ -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;

diff  --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index a6165ef13fd790..2a0c1e9e8c446b 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -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.

diff  --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 481a1d802e66b6..40f854a2c90635 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -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];


        


More information about the llvm-commits mailing list