From f4a17e789b68f196bdac6eb88a7126988cee65f3 Mon Sep 17 00:00:00 2001 From: Philip Pfaffe Date: Thu, 17 Jan 2019 10:10:47 +0000 Subject: [PATCH] [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 --- lib/CodeGen/BackendUtil.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index b927acabac..3536bf0293 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -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 Options = getGCOVOptions(CodeGenOpts)) PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) { MPM.addPass(GCOVProfilerPass(*Options)); -- 2.40.0