[llvm-commits] [llvm] r169591 - /llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
    Evgeniy Stepanov 
    eugeni.stepanov at gmail.com
       
    Fri Dec  7 01:08:33 PST 2012
    
    
  
Author: eugenis
Date: Fri Dec  7 03:08:32 2012
New Revision: 169591
URL: http://llvm.org/viewvc/llvm-project?rev=169591&view=rev
Log:
[msan] Remove readonly/readnone attributes from all called functions.
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).
Modified:
    llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
Modified: llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp?rev=169591&r1=169590&r2=169591&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp Fri Dec  7 03:08:32 2012
@@ -1182,6 +1182,19 @@
         Call->setTailCall(false);
 
       assert(!isa<IntrinsicInst>(&I) && "intrinsics are handled elsewhere");
+
+      // 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;
    
    
More information about the llvm-commits
mailing list