[asan/coverage] change the way asan coverage instrumentation is done: instead of...
authorKostya Serebryany <kcc@google.com>
Mon, 24 Nov 2014 18:49:53 +0000 (18:49 +0000)
committerKostya Serebryany <kcc@google.com>
Mon, 24 Nov 2014 18:49:53 +0000 (18:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222675 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/SanitizerCoverage.cpp
test/Instrumentation/SanitizerCoverage/coverage-dbg.ll
test/Instrumentation/SanitizerCoverage/coverage.ll
test/Instrumentation/SanitizerCoverage/coverage2-dbg.ll

index f882072e6191c19feccaa10763988f6f2be20de3..60d7f9f69d7567f75757cf5213a54a0e5686bfbb 100644 (file)
@@ -13,9 +13,8 @@
 // We create a Guard boolean variable with the same linkage
 // as the function and inject this code into the entry block (CoverageLevel=1)
 // or all blocks (CoverageLevel>=2):
 // We create a Guard boolean variable with the same linkage
 // as the function and inject this code into the entry block (CoverageLevel=1)
 // or all blocks (CoverageLevel>=2):
-// if (*Guard) {
-//    __sanitizer_cov();
-//    *Guard = 1;
+// if (Guard) {
+//    __sanitizer_cov(&Guard);
 // }
 // The accesses to Guard are atomic. The rest of the logic is
 // in __sanitizer_cov (it's fine to call it more than once).
 // }
 // The accesses to Guard are atomic. The rest of the logic is
 // in __sanitizer_cov (it's fine to call it more than once).
@@ -132,6 +131,7 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
   DataLayoutPass *DLP = &getAnalysis<DataLayoutPass>();
   IntptrTy = Type::getIntNTy(*C, DLP->getDataLayout().getPointerSizeInBits());
   Type *VoidTy = Type::getVoidTy(*C);
   DataLayoutPass *DLP = &getAnalysis<DataLayoutPass>();
   IntptrTy = Type::getIntNTy(*C, DLP->getDataLayout().getPointerSizeInBits());
   Type *VoidTy = Type::getVoidTy(*C);
+  IRBuilder<> IRB(*C);
 
   Function *CtorFunc =
       Function::Create(FunctionType::get(VoidTy, false),
 
   Function *CtorFunc =
       Function::Create(FunctionType::get(VoidTy, false),
@@ -139,8 +139,8 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
   ReturnInst::Create(*C, BasicBlock::Create(*C, "", CtorFunc));
   appendToGlobalCtors(M, CtorFunc, kSanCtorAndDtorPriority);
 
   ReturnInst::Create(*C, BasicBlock::Create(*C, "", CtorFunc));
   appendToGlobalCtors(M, CtorFunc, kSanCtorAndDtorPriority);
 
-  SanCovFunction =
-      checkInterfaceFunction(M.getOrInsertFunction(kSanCovName, VoidTy, nullptr));
+  SanCovFunction = checkInterfaceFunction(
+      M.getOrInsertFunction(kSanCovName, VoidTy, IRB.getInt8PtrTy(), nullptr));
   SanCovIndirCallFunction = checkInterfaceFunction(M.getOrInsertFunction(
       kSanCovIndirCallName, VoidTy, IntptrTy, IntptrTy, nullptr));
   SanCovModuleInit = checkInterfaceFunction(M.getOrInsertFunction(
   SanCovIndirCallFunction = checkInterfaceFunction(M.getOrInsertFunction(
       kSanCovIndirCallName, VoidTy, IntptrTy, IntptrTy, nullptr));
   SanCovModuleInit = checkInterfaceFunction(M.getOrInsertFunction(
@@ -157,7 +157,7 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
   for (auto &F : M)
     runOnFunction(F);
 
   for (auto &F : M)
     runOnFunction(F);
 
-  IRBuilder<> IRB(CtorFunc->getEntryBlock().getTerminator());
+  IRB.SetInsertPoint(CtorFunc->getEntryBlock().getTerminator());
   IRB.CreateCall(SanCovModuleInit,
                  ConstantInt::get(IntptrTy, SanCovFunction->getNumUses()));
   return true;
   IRB.CreateCall(SanCovModuleInit,
                  ConstantInt::get(IntptrTy, SanCovFunction->getNumUses()));
   return true;
@@ -279,10 +279,7 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F,
   IRB.SetInsertPoint(Ins);
   IRB.SetCurrentDebugLocation(EntryLoc);
   // __sanitizer_cov gets the PC of the instruction using GET_CALLER_PC.
   IRB.SetInsertPoint(Ins);
   IRB.SetCurrentDebugLocation(EntryLoc);
   // __sanitizer_cov gets the PC of the instruction using GET_CALLER_PC.
-  IRB.CreateCall(SanCovFunction);
-  StoreInst *Store = IRB.CreateStore(ConstantInt::get(Int8Ty, 1), Guard);
-  Store->setAtomic(Monotonic);
-  Store->setAlignment(1);
+  IRB.CreateCall(SanCovFunction, Guard);
 }
 
 char SanitizerCoverageModule::ID = 0;
 }
 
 char SanitizerCoverageModule::ID = 0;
index eea93b8a44b67dc9fa6904165d6e028e3bb00ace..3520f8a2e2038f285594605703ec4ead5ad7db49 100644 (file)
@@ -15,7 +15,7 @@
 ; and add sanitize_address to @_ZN1A1fEv
 
 ; Test that __sanitizer_cov call has !dbg pointing to the opening { of A::f().
 ; and add sanitize_address to @_ZN1A1fEv
 
 ; Test that __sanitizer_cov call has !dbg pointing to the opening { of A::f().
-; CHECK: call void @__sanitizer_cov(), !dbg [[A:!.*]]
+; CHECK: call void @__sanitizer_cov(i8*{{.*}}), !dbg [[A:!.*]]
 ; CHECK: [[A]] = metadata !{i32 6, i32 0, metadata !{{.*}}, null}
 
 
 ; CHECK: [[A]] = metadata !{i32 6, i32 0, metadata !{{.*}}, null}
 
 
index da0498db6429eb35aaf7a906e82989134c5c02a0..2d9a56ac1fe0acab9324b009ebc53c7bc0a34b48 100644 (file)
@@ -36,9 +36,9 @@ entry:
 ; CHECK1: %0 = load atomic i8* @__sancov_gen_cov_foo monotonic, align 1
 ; CHECK1: %1 = icmp eq i8 0, %0
 ; CHECK1: br i1 %1, label %2, label %3
 ; CHECK1: %0 = load atomic i8* @__sancov_gen_cov_foo monotonic, align 1
 ; CHECK1: %1 = icmp eq i8 0, %0
 ; CHECK1: br i1 %1, label %2, label %3
-; CHECK1: call void @__sanitizer_cov
+; CHECK1: call void @__sanitizer_cov(i8*{{.*}})
 ; CHECK1-NOT: call void @__sanitizer_cov
 ; CHECK1-NOT: call void @__sanitizer_cov
-; CHECK1: store atomic i8 1, i8* @__sancov_gen_cov_foo monotonic, align 1
+; CHECK1: ret void
 
 ; CHECK1-LABEL: define internal void @sancov.module_ctor
 ; CHECK1-NOT: ret
 
 ; CHECK1-LABEL: define internal void @sancov.module_ctor
 ; CHECK1-NOT: ret
index 9b263293bf425a41c3a782cf48c33dd529ab75e5..f351fe15d425bb03b88195c09e18245ffb5e9696 100644 (file)
@@ -17,9 +17,9 @@ target triple = "x86_64-unknown-linux-gnu"
 ; Check that __sanitizer_cov call has !dgb pointing to the beginning
 ; of appropriate basic blocks.
 ; CHECK-LABEL:_Z3fooPi
 ; Check that __sanitizer_cov call has !dgb pointing to the beginning
 ; of appropriate basic blocks.
 ; CHECK-LABEL:_Z3fooPi
-; CHECK: call void @__sanitizer_cov(), !dbg [[A:!.*]]
-; CHECK: call void @__sanitizer_cov(), !dbg [[B:!.*]]
-; CHECK: call void @__sanitizer_cov(), !dbg [[C:!.*]]
+; CHECK: call void @__sanitizer_cov(i8*{{.*}}), !dbg [[A:!.*]]
+; CHECK: call void @__sanitizer_cov(i8*{{.*}}), !dbg [[B:!.*]]
+; CHECK: call void @__sanitizer_cov(i8*{{.*}}), !dbg [[C:!.*]]
 ; CHECK: ret void
 ; CHECK: [[A]] = metadata !{i32 1, i32 0, metadata !{{.*}}, null}
 ; CHECK: [[B]] = metadata !{i32 3, i32 5, metadata !{{.*}}, null}
 ; CHECK: ret void
 ; CHECK: [[A]] = metadata !{i32 1, i32 0, metadata !{{.*}}, null}
 ; CHECK: [[B]] = metadata !{i32 3, i32 5, metadata !{{.*}}, null}