[clang] 6e09818 - [DFSan][NewPM] Handle dfsan under NPM

Arthur Eubanks via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 13 13:41:52 PST 2020


Author: Arthur Eubanks
Date: 2020-11-13T13:41:38-08:00
New Revision: 6e098189db7da11bc9c32dd483cd81765804c241

URL: https://github.com/llvm/llvm-project/commit/6e098189db7da11bc9c32dd483cd81765804c241
DIFF: https://github.com/llvm/llvm-project/commit/6e098189db7da11bc9c32dd483cd81765804c241.diff

LOG: [DFSan][NewPM] Handle dfsan under NPM

Make it required. Since it's a module pass, optnone won't test it, so
extend the clang test to also use opt-bisect now that it's supported.

14/16 check-dfsan tests failed with NPM enabled, now all pass.

Reviewed By: leonardchan

Differential Revision: https://reviews.llvm.org/D91385

Added: 
    clang/test/CodeGen/no-skipped-passes-O0-opt-bisect.c

Modified: 
    clang/lib/CodeGen/BackendUtil.cpp
    llvm/include/llvm/Transforms/Instrumentation/DataFlowSanitizer.h

Removed: 
    clang/test/CodeGen/O0-no-skipped-passes.c


################################################################################
diff  --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 37922882ae46..77759bb18146 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -65,6 +65,7 @@
 #include "llvm/Transforms/Instrumentation.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
 #include "llvm/Transforms/Instrumentation/BoundsChecking.h"
+#include "llvm/Transforms/Instrumentation/DataFlowSanitizer.h"
 #include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
 #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
 #include "llvm/Transforms/Instrumentation/InstrProfiling.h"
@@ -1295,6 +1296,14 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
     HWASanPass(SanitizerKind::HWAddress, false);
     HWASanPass(SanitizerKind::KernelHWAddress, true);
 
+    if (LangOpts.Sanitize.has(SanitizerKind::DataFlow)) {
+      PB.registerOptimizerLastEPCallback(
+          [this](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
+            MPM.addPass(
+                DataFlowSanitizerPass(LangOpts.SanitizerBlacklistFiles));
+          });
+    }
+
     if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts, LangOpts))
       PB.registerPipelineStartEPCallback(
           [Options](ModulePassManager &MPM,

diff  --git a/clang/test/CodeGen/O0-no-skipped-passes.c b/clang/test/CodeGen/O0-no-skipped-passes.c
deleted file mode 100644
index 01b579c87c80..000000000000
--- a/clang/test/CodeGen/O0-no-skipped-passes.c
+++ /dev/null
@@ -1,14 +0,0 @@
-// Test that no passes are skipped under -O0/NPM
-//
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fcoroutines-ts 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=address 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=hwaddress 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=memory 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=thread 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=local-bounds 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize-coverage-trace-pc-guard 2>&1 | FileCheck %s
-
-// CHECK-NOT: Skipping pass
-
-int func(int a) { return a; }

diff  --git a/clang/test/CodeGen/no-skipped-passes-O0-opt-bisect.c b/clang/test/CodeGen/no-skipped-passes-O0-opt-bisect.c
new file mode 100644
index 000000000000..8acba73f6653
--- /dev/null
+++ b/clang/test/CodeGen/no-skipped-passes-O0-opt-bisect.c
@@ -0,0 +1,25 @@
+// Test that no passes are skipped under NPM with -O0/opt-bisect
+//
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fcoroutines-ts 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=address 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=hwaddress 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=memory 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=thread 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=local-bounds 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=dataflow 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -enable-npm-optnone -O0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize-coverage-trace-pc-guard 2>&1 | FileCheck %s
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -opt-bisect-limit=0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -opt-bisect-limit=0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fcoroutines-ts 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -opt-bisect-limit=0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=address 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -opt-bisect-limit=0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=hwaddress 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -opt-bisect-limit=0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=memory 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -opt-bisect-limit=0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=thread 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -opt-bisect-limit=0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=local-bounds 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -opt-bisect-limit=0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize=dataflow 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -mllvm -opt-bisect-limit=0 -fexperimental-new-pass-manager %s -fdebug-pass-manager -emit-llvm -o /dev/null -fsanitize-coverage-trace-pc-guard 2>&1 | FileCheck %s
+
+// CHECK-NOT: Skipping pass
+
+int func(int a) { return a; }

diff  --git a/llvm/include/llvm/Transforms/Instrumentation/DataFlowSanitizer.h b/llvm/include/llvm/Transforms/Instrumentation/DataFlowSanitizer.h
index c43de78df592..9b57b1f9a9ea 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/DataFlowSanitizer.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/DataFlowSanitizer.h
@@ -24,6 +24,7 @@ class DataFlowSanitizerPass : public PassInfoMixin<DataFlowSanitizerPass> {
       const std::vector<std::string> &ABIListFiles = std::vector<std::string>())
       : ABIListFiles(ABIListFiles) {}
   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+  static bool isRequired() { return true; }
 };
 
 } // namespace llvm


        


More information about the cfe-commits mailing list