Author: Arthur Eubanks Date: 2020-05-11T12:59:09-07:00 New Revision: 7d5bb94d78386e4653535c35d3e8258bf4502340
URL: https://github.com/llvm/llvm-project/commit/7d5bb94d78386e4653535c35d3e8258bf4502340 DIFF: https://github.com/llvm/llvm-project/commit/7d5bb94d78386e4653535c35d3e8258bf4502340.diff LOG: Run Coverage pass before other *San passes under new pass manager Summary: This fixes compiler-rt/test/msan/coverage-levels.cpp under the new pass manager (final check-msan test!). Under the old pass manager, the coverage pass would run before the MSan pass. The opposite happened under the new pass manager. The MSan pass adds extra basic blocks, changing the number of coverage callbacks. Reviewers: vitalybuka, leonardchan Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D79698 Added: Modified: clang/lib/CodeGen/BackendUtil.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index ba4b48d8bd5f..0dc6c08eafe3 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1002,6 +1002,15 @@ static void addSanitizersAtO0(ModulePassManager &MPM, const Triple &TargetTriple, const LangOptions &LangOpts, const CodeGenOptions &CodeGenOpts) { + if (CodeGenOpts.SanitizeCoverageType || + CodeGenOpts.SanitizeCoverageIndirectCalls || + CodeGenOpts.SanitizeCoverageTraceCmp) { + auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts); + MPM.addPass(ModuleSanitizerCoveragePass( + SancovOpts, CodeGenOpts.SanitizeCoverageWhitelistFiles, + CodeGenOpts.SanitizeCoverageBlacklistFiles)); + } + auto ASanPass = [&](SanitizerMask Mask, bool CompileKernel) { MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>()); bool Recover = CodeGenOpts.SanitizeRecover.has(Mask); @@ -1242,6 +1251,17 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( EntryExitInstrumenterPass(/*PostInlining=*/false))); }); + if (CodeGenOpts.SanitizeCoverageType || + CodeGenOpts.SanitizeCoverageIndirectCalls || + CodeGenOpts.SanitizeCoverageTraceCmp) { + PB.registerPipelineStartEPCallback([&](ModulePassManager &MPM) { + auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts); + MPM.addPass(ModuleSanitizerCoveragePass( + SancovOpts, CodeGenOpts.SanitizeCoverageWhitelistFiles, + CodeGenOpts.SanitizeCoverageBlacklistFiles)); + }); + } + // Register callbacks to schedule sanitizer passes at the appropriate part of // the pipeline. // FIXME: either handle asan/the remaining sanitizers or error out @@ -1326,15 +1346,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( } } - if (CodeGenOpts.SanitizeCoverageType || - CodeGenOpts.SanitizeCoverageIndirectCalls || - CodeGenOpts.SanitizeCoverageTraceCmp) { - auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts); - MPM.addPass(ModuleSanitizerCoveragePass( - SancovOpts, CodeGenOpts.SanitizeCoverageWhitelistFiles, - CodeGenOpts.SanitizeCoverageBlacklistFiles)); - } - if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) { bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::HWAddress); MPM.addPass(HWAddressSanitizerPass( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits