[llvm] r217098 - [asan] add -asan-coverage=3: instrument all blocks and critical edges.

Kostya Serebryany kcc at google.com
Wed Sep 3 15:37:38 PDT 2014


Author: kcc
Date: Wed Sep  3 17:37:37 2014
New Revision: 217098

URL: http://llvm.org/viewvc/llvm-project?rev=217098&view=rev
Log:
[asan] add -asan-coverage=3: instrument all blocks and critical edges. 

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

Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=217098&r1=217097&r2=217098&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Wed Sep  3 17:37:37 2014
@@ -40,6 +40,7 @@
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Endian.h"
+#include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Utils/ASanStackFrameLayout.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/Cloning.h"
@@ -134,7 +135,8 @@ static cl::opt<bool> ClUseAfterReturn("a
 static cl::opt<bool> ClGlobals("asan-globals",
        cl::desc("Handle global objects"), cl::Hidden, cl::init(true));
 static cl::opt<int> ClCoverage("asan-coverage",
-       cl::desc("ASan coverage. 0: none, 1: entry block, 2: all blocks"),
+       cl::desc("ASan coverage. 0: none, 1: entry block, 2: all blocks, "
+                "3: all blocks and critical edges"),
        cl::Hidden, cl::init(false));
 static cl::opt<int> ClCoverageBlockThreshold("asan-coverage-block-threshold",
        cl::desc("Add coverage instrumentation only to the entry block if there "
@@ -352,7 +354,9 @@ static size_t RedzoneSizeForScale(int Ma
 
 /// AddressSanitizer: instrument the code in module to find memory bugs.
 struct AddressSanitizer : public FunctionPass {
-  AddressSanitizer() : FunctionPass(ID) {}
+  AddressSanitizer() : FunctionPass(ID) {
+    initializeBreakCriticalEdgesPass(*PassRegistry::getPassRegistry());
+  }
   const char *getPassName() const override {
     return "AddressSanitizerFunctionPass";
   }
@@ -373,6 +377,11 @@ struct AddressSanitizer : public Functio
   bool doInitialization(Module &M) override;
   static char ID;  // Pass identification, replacement for typeid
 
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+    if (ClCoverage >= 3)
+      AU.addRequiredID(BreakCriticalEdgesID);
+  }
+
  private:
   void initializeCallbacks(Module &M);
 

Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/coverage.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/coverage.ll?rev=217098&r1=217097&r2=217098&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/coverage.ll (original)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/coverage.ll Wed Sep  3 17:37:37 2014
@@ -3,6 +3,7 @@
 ; RUN: opt < %s -asan -asan-module -asan-coverage=2 -S | FileCheck %s --check-prefix=CHECK2
 ; RUN: opt < %s -asan -asan-module -asan-coverage=2 -asan-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK2
 ; RUN: opt < %s -asan -asan-module -asan-coverage=2 -asan-coverage-block-threshold=1  -S | FileCheck %s --check-prefix=CHECK1
+; RUN: opt < %s -asan -asan-module -asan-coverage=3 -asan-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK3
 
 ; RUN: opt < %s -asan -asan-module -asan-coverage=0 -asan-globals=0 -S | \
 ; RUN:     FileCheck %s --check-prefix=CHECK0
@@ -58,3 +59,12 @@ entry:
 ; CHECK2-NOT: ret
 ; CHECK2: call void @__sanitizer_cov_module_init(i64 3)
 ; CHECK2: ret
+
+; CHECK3-LABEL: define void @foo
+; CHECK3: call void @__sanitizer_cov
+; CHECK3: call void @__sanitizer_cov
+; CHECK3: call void @__sanitizer_cov
+; CHECK3: call void @__sanitizer_cov
+; CHECK3-NOT: call void @__sanitizer_cov
+; CHECK3: ret void
+





More information about the llvm-commits mailing list