Browse Source

[NewPM] Add -fsanitize={memory,thread} handling to clang

Summary: This is the missing bit to drive thread and memory sanitizers through clang using the new PassManager.

Reviewers: chandlerc, fedor.sergeev, vitalybuka, leonardchan

Subscribers: bollu, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351423 91177308-0d34-0410-b5e6-96231b3b80d8
Philip Pfaffe 6 years ago
parent
commit
f4a17e789b
1 changed files with 11 additions and 0 deletions
  1. 11 0
      lib/CodeGen/BackendUtil.cpp

+ 11 - 0
lib/CodeGen/BackendUtil.cpp

@@ -1015,11 +1015,22 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
 
 
       // Register callbacks to schedule sanitizer passes at the appropriate part of
       // Register callbacks to schedule sanitizer passes at the appropriate part of
       // the pipeline.
       // the pipeline.
+      // FIXME: either handle asan/the remaining sanitizers or error out
       if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
       if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
         PB.registerScalarOptimizerLateEPCallback(
         PB.registerScalarOptimizerLateEPCallback(
             [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
             [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
               FPM.addPass(BoundsCheckingPass());
               FPM.addPass(BoundsCheckingPass());
             });
             });
+      if (LangOpts.Sanitize.has(SanitizerKind::Memory))
+        PB.registerOptimizerLastEPCallback(
+            [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
+              FPM.addPass(MemorySanitizerPass());
+            });
+      if (LangOpts.Sanitize.has(SanitizerKind::Thread))
+        PB.registerOptimizerLastEPCallback(
+            [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
+              FPM.addPass(ThreadSanitizerPass());
+            });
       if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts))
       if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts))
         PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
         PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
           MPM.addPass(GCOVProfilerPass(*Options));
           MPM.addPass(GCOVProfilerPass(*Options));