]> granicus.if.org Git - clang/commitdiff
[NewPM] Add -fsanitize={memory,thread} handling to clang
authorPhilip Pfaffe <philip.pfaffe@gmail.com>
Thu, 17 Jan 2019 10:10:47 +0000 (10:10 +0000)
committerPhilip Pfaffe <philip.pfaffe@gmail.com>
Thu, 17 Jan 2019 10:10:47 +0000 (10:10 +0000)
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

lib/CodeGen/BackendUtil.cpp

index b927acabac5921c07390edf25aff92a0fde41136..3536bf029394b1ab7a234715e94a98d1bfc554b8 100644 (file)
@@ -1015,11 +1015,22 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
 
       // Register callbacks to schedule sanitizer passes at the appropriate part of
       // the pipeline.
+      // FIXME: either handle asan/the remaining sanitizers or error out
       if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
         PB.registerScalarOptimizerLateEPCallback(
             [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
               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))
         PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
           MPM.addPass(GCOVProfilerPass(*Options));