From: Evgeniy Stepanov Date: Fri, 7 Dec 2012 09:08:32 +0000 (+0000) Subject: [msan] Remove readonly/readnone attributes from all called functions. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=ece6db5f16a83ff4cab3544643d226eeb8a15784;p=oota-llvm.git [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 --- diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp index a3b293eed6f..65c894bee24 100644 --- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1182,6 +1182,19 @@ struct MemorySanitizerVisitor : public InstVisitor { Call->setTailCall(false); assert(!isa(&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;