diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2012-12-07 09:08:32 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2012-12-07 09:08:32 +0000 |
commit | ece6db5f16a83ff4cab3544643d226eeb8a15784 (patch) | |
tree | f2f3afb9abae1aa6c0324d8d2b53c1ca7701d4e3 /lib/Transforms/Instrumentation/MemorySanitizer.cpp | |
parent | 06180bf3f25f2a9828e4c39f63a883aaa6c9452d (diff) |
[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).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169591 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation/MemorySanitizer.cpp')
-rw-r--r-- | lib/Transforms/Instrumentation/MemorySanitizer.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp index a3b293eed6..65c894bee2 100644 --- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1182,6 +1182,19 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> { 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; |