[msan] allow -fsanitize-coverage=N together with -fsanitize=memory, llvm part

llvm-svn: 223312
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 60d7f9f..34f5ae9 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -166,7 +166,8 @@
 bool SanitizerCoverageModule::runOnFunction(Function &F) {
   if (F.empty()) return false;
   // For now instrument only functions that will also be asan-instrumented.
-  if (!F.hasFnAttribute(Attribute::SanitizeAddress))
+  if (!F.hasFnAttribute(Attribute::SanitizeAddress) &&
+      !F.hasFnAttribute(Attribute::SanitizeMemory))
     return false;
   if (CoverageLevel >= 3)
     SplitAllCriticalEdges(F, this);
@@ -273,6 +274,8 @@
   LoadInst *Load = IRB.CreateLoad(Guard);
   Load->setAtomic(Monotonic);
   Load->setAlignment(1);
+  Load->setMetadata(F.getParent()->getMDKindID("nosanitize"),
+                    MDNode::get(*C, ArrayRef<llvm::Value *>()));
   Value *Cmp = IRB.CreateICmpEQ(Constant::getNullValue(Int8Ty), Load);
   Instruction *Ins = SplitBlockAndInsertIfThen(
       Cmp, IP, false, MDBuilder(*C).createBranchWeights(1, 100000));