From f62b4e3ee3cc667020d5de91dfec69ce58c1d1ea Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Thu, 29 Nov 2012 12:30:18 +0000 Subject: [PATCH] [msan] Make sure that report callbacks do not get merged. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168873 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Instrumentation/MemorySanitizer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp index 57c50030850..bc9e709fd47 100644 --- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -183,6 +183,8 @@ private: MDNode *ColdCallWeights; /// \brief The blacklist. OwningPtr BL; + /// \brief An empty volatile inline asm that prevents callback merge. + InlineAsm *EmptyAsm; friend class MemorySanitizerVisitor; friend class VarArgAMD64Helper; @@ -295,6 +297,11 @@ bool MemorySanitizer::doInitialization(Module &M) { OriginTLS = new GlobalVariable( M, IRB.getInt32Ty(), false, GlobalVariable::ExternalLinkage, 0, "__msan_origin_tls", 0, GlobalVariable::GeneralDynamicTLSModel); + + // We insert an empty inline asm after __msan_report* to avoid callback merge. + EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false), + StringRef(""), StringRef(""), + /*hasSideEffects=*/true); return true; } @@ -391,6 +398,7 @@ struct MemorySanitizerVisitor : public InstVisitor { } CallInst *Call = IRB.CreateCall(MS.WarningFn); Call->setDebugLoc(OrigIns->getDebugLoc()); + IRB.CreateCall(MS.EmptyAsm); DEBUG(dbgs() << " CHECK: " << *Cmp << "\n"); } DEBUG(dbgs() << "DONE:\n" << F);