[llvm-commits] [PATCH] Remove readonly/readnone attributes from all called functions

Evgeniy Stepanov eugenis at google.com
Wed Dec 5 06:22:46 PST 2012


Hi kcc, chandlerc,

MSan uses a TLS slot to pass shadow for function arguments and return values. This makes all instrumented functions not readonly, and at the same time requires that all callees of an instrumented function that may be MSan-instrumented do not have readonly attribute (otherwise some of the instrumentation may be optimized out).

As MSan is a function pass, we've got to remove readonly attributes from callees when we instrument the caller. 

Better fix, anyone?


http://llvm-reviews.chandlerc.com/D173

Files:
  lib/Transforms/Instrumentation/MemorySanitizer.cpp

Index: lib/Transforms/Instrumentation/MemorySanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -1126,6 +1126,19 @@
         visitInstruction(I);
         return;
       }
+
+      // We are going to insert code that relies on the fact that the callee
+      // 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.
+      if (Function *Func = Call->getCalledFunction()) {
+        // Clear out readonly/readnone attributes.
+        AttrBuilder B;
+        B.addAttribute(Attributes::ReadOnly)
+          .addAttribute(Attributes::ReadNone);
+        Func->removeAttribute(AttrListPtr::FunctionIndex,
+                              Attributes::get(Func->getContext(), B));
+      }
     }
     IRBuilder<> IRB(&I);
     unsigned ArgOffset = 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D173.1.patch
Type: text/x-patch
Size: 1013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121205/e69e79c6/attachment.bin>


More information about the llvm-commits mailing list