[clang] e261b03 - [sanitizers] Add experimental flag to insert sanitizers earlier
Vitaly Buka via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 8 19:05:32 PDT 2022
Author: Vitaly Buka
Date: 2022-09-08T19:05:17-07:00
New Revision: e261b03396078feba2246340f81160f76f7d5e92
URL: https://github.com/llvm/llvm-project/commit/e261b03396078feba2246340f81160f76f7d5e92
DIFF: https://github.com/llvm/llvm-project/commit/e261b03396078feba2246340f81160f76f7d5e92.diff
LOG: [sanitizers] Add experimental flag to insert sanitizers earlier
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index ccde687eba09c..64b21ef608bb1 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -97,6 +97,11 @@ using namespace llvm;
namespace llvm {
extern cl::opt<bool> DebugInfoCorrelate;
+
+// Experiment to move sanitizers earlier.
+static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP(
+ "sanitizer-early-opt-ep", cl::Optional,
+ cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
}
namespace {
@@ -632,8 +637,9 @@ static OptimizationLevel mapToLevel(const CodeGenOptions &Opts) {
static void addSanitizers(const Triple &TargetTriple,
const CodeGenOptions &CodeGenOpts,
const LangOptions &LangOpts, PassBuilder &PB) {
- PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM,
- OptimizationLevel Level) {
+
+ auto SanitizersCallback = [&](ModulePassManager &MPM,
+ OptimizationLevel Level) {
if (CodeGenOpts.hasSanitizeCoverage()) {
auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
MPM.addPass(SanitizerCoveragePass(
@@ -708,7 +714,11 @@ static void addSanitizers(const Triple &TargetTriple,
if (LangOpts.Sanitize.has(SanitizerKind::DataFlow)) {
MPM.addPass(DataFlowSanitizerPass(LangOpts.NoSanitizeFiles));
}
- });
+ };
+ if (ClSanitizeOnOptimizerEarlyEP)
+ PB.registerOptimizerEarlyEPCallback(SanitizersCallback);
+ else
+ PB.registerOptimizerLastEPCallback(SanitizersCallback);
}
void EmitAssemblyHelper::RunOptimizationPipeline(
More information about the cfe-commits
mailing list