From 0fd28b40a4cec1d3a813924cc0003b8f58a400e6 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 3 Dec 2014 23:28:26 +0000 Subject: [PATCH] [msan] allow -fsanitize-coverage=N together with -fsanitize=memory, llvm part git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223312 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Instrumentation/MemorySanitizer.cpp | 2 +- lib/Transforms/Instrumentation/SanitizerCoverage.cpp | 5 ++++- test/Instrumentation/SanitizerCoverage/coverage.ll | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp index d97332621e6..35f9fd7cce3 100644 --- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1036,7 +1036,7 @@ struct MemorySanitizerVisitor : public InstVisitor { IRBuilder<> IRB(I.getNextNode()); Type *ShadowTy = getShadowTy(&I); Value *Addr = I.getPointerOperand(); - if (PropagateShadow) { + if (PropagateShadow && !I.getMetadata("nosanitize")) { Value *ShadowPtr = getShadowPtr(Addr, ShadowTy, IRB); setShadow(&I, IRB.CreateAlignedLoad(ShadowPtr, I.getAlignment(), "_msld")); diff --git a/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/lib/Transforms/Instrumentation/SanitizerCoverage.cpp index 60d7f9f69d7..34f5ae96b13 100644 --- a/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -166,7 +166,8 @@ bool SanitizerCoverageModule::runOnModule(Module &M) { 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 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, LoadInst *Load = IRB.CreateLoad(Guard); Load->setAtomic(Monotonic); Load->setAlignment(1); + Load->setMetadata(F.getParent()->getMDKindID("nosanitize"), + MDNode::get(*C, ArrayRef())); Value *Cmp = IRB.CreateICmpEQ(Constant::getNullValue(Int8Ty), Load); Instruction *Ins = SplitBlockAndInsertIfThen( Cmp, IP, false, MDBuilder(*C).createBranchWeights(1, 100000)); diff --git a/test/Instrumentation/SanitizerCoverage/coverage.ll b/test/Instrumentation/SanitizerCoverage/coverage.ll index 2d9a56ac1fe..aa3ba5c7202 100644 --- a/test/Instrumentation/SanitizerCoverage/coverage.ll +++ b/test/Instrumentation/SanitizerCoverage/coverage.ll @@ -33,7 +33,7 @@ entry: ; CHECK0-NOT: call void @__sanitizer_cov_module_init( ; CHECK1-LABEL: define void @foo -; CHECK1: %0 = load atomic i8* @__sancov_gen_cov_foo monotonic, align 1 +; CHECK1: %0 = load atomic i8* @__sancov_gen_cov_foo monotonic, align 1, !nosanitize ; CHECK1: %1 = icmp eq i8 0, %0 ; CHECK1: br i1 %1, label %2, label %3 ; CHECK1: call void @__sanitizer_cov(i8*{{.*}}) -- 2.34.1