[llvm] r231333 - [sanitizer] add nosanitize metadata to more coverage instrumentation instructions

Kostya Serebryany kcc at google.com
Wed Mar 4 17:20:05 PST 2015


Author: kcc
Date: Wed Mar  4 19:20:05 2015
New Revision: 231333

URL: http://llvm.org/viewvc/llvm-project?rev=231333&view=rev
Log:
[sanitizer] add nosanitize metadata to more coverage instrumentation instructions

Modified:
    llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
    llvm/trunk/test/Instrumentation/SanitizerCoverage/coverage.ll

Modified: llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp?rev=231333&r1=231332&r2=231333&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp Wed Mar  4 19:20:05 2015
@@ -109,6 +109,7 @@ class SanitizerCoverageModule : public M
                                       ArrayRef<Instruction *> IndirCalls);
   bool InjectCoverage(Function &F, ArrayRef<BasicBlock *> AllBlocks,
                       ArrayRef<Instruction *> IndirCalls);
+  void SetNoSanitizeMetada(Instruction *I);
   void InjectCoverageAtBlock(Function &F, BasicBlock &BB, bool UseCalls);
   Function *SanCovFunction;
   Function *SanCovWithCheckFunction;
@@ -306,6 +307,12 @@ void SanitizerCoverageModule::InjectCove
   }
 }
 
+void SanitizerCoverageModule::SetNoSanitizeMetada(Instruction *I) {
+  I->setMetadata(
+      I->getParent()->getParent()->getParent()->getMDKindID("nosanitize"),
+      MDNode::get(*C, None));
+}
+
 void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
                                                     bool UseCalls) {
   BasicBlock::iterator IP = BB.getFirstInsertionPt(), BE = BB.end();
@@ -335,8 +342,7 @@ void SanitizerCoverageModule::InjectCove
     LoadInst *Load = IRB.CreateLoad(GuardP);
     Load->setAtomic(Monotonic);
     Load->setAlignment(4);
-    Load->setMetadata(F.getParent()->getMDKindID("nosanitize"),
-                      MDNode::get(*C, None));
+    SetNoSanitizeMetada(Load);
     Value *Cmp = IRB.CreateICmpSGE(Constant::getNullValue(Load->getType()), Load);
     Instruction *Ins = SplitBlockAndInsertIfThen(
         Cmp, IP, false, MDBuilder(*C).createBranchWeights(1, 100000));
@@ -353,9 +359,11 @@ void SanitizerCoverageModule::InjectCove
         IRB.CreatePointerCast(EightBitCounterArray, IntptrTy),
         ConstantInt::get(IntptrTy, SanCovFunction->getNumUses() - 1));
     P = IRB.CreateIntToPtr(P, IRB.getInt8PtrTy());
-    Value *LI = IRB.CreateLoad(P);
+    LoadInst *LI = IRB.CreateLoad(P);
     Value *Inc = IRB.CreateAdd(LI, ConstantInt::get(IRB.getInt8Ty(), 1));
-    IRB.CreateStore(Inc, P);
+    StoreInst *SI = IRB.CreateStore(Inc, P);
+    SetNoSanitizeMetada(LI);
+    SetNoSanitizeMetada(SI);
   }
 
   if (ClExperimentalTracing) {

Modified: llvm/trunk/test/Instrumentation/SanitizerCoverage/coverage.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/SanitizerCoverage/coverage.ll?rev=231333&r1=231332&r2=231333&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/SanitizerCoverage/coverage.ll (original)
+++ llvm/trunk/test/Instrumentation/SanitizerCoverage/coverage.ll Wed Mar  4 19:20:05 2015
@@ -79,18 +79,18 @@ entry:
 ; test -sanitizer-coverage-8bit-counters=1
 ; CHECK-8BIT-LABEL: define void @foo
 
-; CHECK-8BIT: [[V11:%[0-9]*]] = load i8
+; CHECK-8BIT: [[V11:%[0-9]*]] = load i8{{.*}}!nosanitize
 ; CHECK-8BIT: [[V12:%[0-9]*]] = add i8 [[V11]], 1
-; CHECK-8BIT: store i8 [[V12]]
-; CHECK-8BIT: [[V21:%[0-9]*]] = load i8
+; CHECK-8BIT: store i8 [[V12]]{{.*}}!nosanitize
+; CHECK-8BIT: [[V21:%[0-9]*]] = load i8{{.*}}!nosanitize
 ; CHECK-8BIT: [[V22:%[0-9]*]] = add i8 [[V21]], 1
-; CHECK-8BIT: store i8 [[V22]]
-; CHECK-8BIT: [[V31:%[0-9]*]] = load i8
+; CHECK-8BIT: store i8 [[V22]]{{.*}}!nosanitize
+; CHECK-8BIT: [[V31:%[0-9]*]] = load i8{{.*}}!nosanitize
 ; CHECK-8BIT: [[V32:%[0-9]*]] = add i8 [[V31]], 1
-; CHECK-8BIT: store i8 [[V32]]
-; CHECK-8BIT: [[V41:%[0-9]*]] = load i8
+; CHECK-8BIT: store i8 [[V32]]{{.*}}!nosanitize
+; CHECK-8BIT: [[V41:%[0-9]*]] = load i8{{.*}}!nosanitize
 ; CHECK-8BIT: [[V42:%[0-9]*]] = add i8 [[V41]], 1
-; CHECK-8BIT: store i8 [[V42]]
+; CHECK-8BIT: store i8 [[V42]]{{.*}}!nosanitize
 
 ; CHECK-8BIT: ret void
 





More information about the llvm-commits mailing list