[PATCH] D85259: [msan] Remove readnone and friends from call sites.

Evgenii Stepanov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 10:41:12 PDT 2020


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf2c04239955a: [msan] Remove readnone and friends from call sites. (authored by eugenis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85259/new/

https://reviews.llvm.org/D85259

Files:
  llvm/include/llvm/IR/InstrTypes.h
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/test/Instrumentation/MemorySanitizer/attributes.ll


Index: llvm/test/Instrumentation/MemorySanitizer/attributes.ll
===================================================================
--- llvm/test/Instrumentation/MemorySanitizer/attributes.ll
+++ llvm/test/Instrumentation/MemorySanitizer/attributes.ll
@@ -13,24 +13,28 @@
 define void @a() sanitize_memory readnone {
 entry:
   call void @a_()
+  call void @a_() readnone
   ret void
 }
 
 define void @b() sanitize_memory readonly {
 entry:
   call void @b_()
+  call void @b_() readonly
   ret void
 }
 
 define void @c() sanitize_memory writeonly {
 entry:
   call void @c_()
+  call void @c_() writeonly
   ret void
 }
 
 define void @d(i32* %p) sanitize_memory writeonly argmemonly {
 entry:
   call void @d_(i32* %p)
+  call void @d_(i32* %p) writeonly argmemonly
   ret void
 }
 
Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -3584,14 +3584,15 @@
       // will become a non-readonly function after it is instrumented by us. To
       // prevent this code from being optimized out, mark that function
       // non-readonly in advance.
+      AttrBuilder B;
+      B.addAttribute(Attribute::ReadOnly)
+          .addAttribute(Attribute::ReadNone)
+          .addAttribute(Attribute::WriteOnly)
+          .addAttribute(Attribute::ArgMemOnly)
+          .addAttribute(Attribute::Speculatable);
+
+      Call->removeAttributes(AttributeList::FunctionIndex, B);
       if (Function *Func = Call->getCalledFunction()) {
-        // Clear out readonly/readnone attributes.
-        AttrBuilder B;
-        B.addAttribute(Attribute::ReadOnly)
-            .addAttribute(Attribute::ReadNone)
-            .addAttribute(Attribute::WriteOnly)
-            .addAttribute(Attribute::ArgMemOnly)
-            .addAttribute(Attribute::Speculatable);
         Func->removeAttributes(AttributeList::FunctionIndex, B);
       }
 
Index: llvm/include/llvm/IR/InstrTypes.h
===================================================================
--- llvm/include/llvm/IR/InstrTypes.h
+++ llvm/include/llvm/IR/InstrTypes.h
@@ -1451,6 +1451,12 @@
     setAttributes(PAL);
   }
 
+  void removeAttributes(unsigned i, const AttrBuilder &Attrs) {
+    AttributeList PAL = getAttributes();
+    PAL = PAL.removeAttributes(getContext(), i, Attrs);
+    setAttributes(PAL);
+  }
+
   /// Removes the attribute from the given argument
   void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
     assert(ArgNo < getNumArgOperands() && "Out of bounds");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85259.283297.patch
Type: text/x-patch
Size: 2646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200805/d6362234/attachment.bin>


More information about the llvm-commits mailing list