Skip to content

Commit 7d5bb94

Browse files
committed
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
1 parent b604544 commit 7d5bb94

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,15 @@ static void addSanitizersAtO0(ModulePassManager &MPM,
10021002
const Triple &TargetTriple,
10031003
const LangOptions &LangOpts,
10041004
const CodeGenOptions &CodeGenOpts) {
1005+
if (CodeGenOpts.SanitizeCoverageType ||
1006+
CodeGenOpts.SanitizeCoverageIndirectCalls ||
1007+
CodeGenOpts.SanitizeCoverageTraceCmp) {
1008+
auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
1009+
MPM.addPass(ModuleSanitizerCoveragePass(
1010+
SancovOpts, CodeGenOpts.SanitizeCoverageWhitelistFiles,
1011+
CodeGenOpts.SanitizeCoverageBlacklistFiles));
1012+
}
1013+
10051014
auto ASanPass = [&](SanitizerMask Mask, bool CompileKernel) {
10061015
MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
10071016
bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
@@ -1242,6 +1251,17 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
12421251
EntryExitInstrumenterPass(/*PostInlining=*/false)));
12431252
});
12441253

1254+
if (CodeGenOpts.SanitizeCoverageType ||
1255+
CodeGenOpts.SanitizeCoverageIndirectCalls ||
1256+
CodeGenOpts.SanitizeCoverageTraceCmp) {
1257+
PB.registerPipelineStartEPCallback([&](ModulePassManager &MPM) {
1258+
auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
1259+
MPM.addPass(ModuleSanitizerCoveragePass(
1260+
SancovOpts, CodeGenOpts.SanitizeCoverageWhitelistFiles,
1261+
CodeGenOpts.SanitizeCoverageBlacklistFiles));
1262+
});
1263+
}
1264+
12451265
// Register callbacks to schedule sanitizer passes at the appropriate part of
12461266
// the pipeline.
12471267
// FIXME: either handle asan/the remaining sanitizers or error out
@@ -1326,15 +1346,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
13261346
}
13271347
}
13281348

1329-
if (CodeGenOpts.SanitizeCoverageType ||
1330-
CodeGenOpts.SanitizeCoverageIndirectCalls ||
1331-
CodeGenOpts.SanitizeCoverageTraceCmp) {
1332-
auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
1333-
MPM.addPass(ModuleSanitizerCoveragePass(
1334-
SancovOpts, CodeGenOpts.SanitizeCoverageWhitelistFiles,
1335-
CodeGenOpts.SanitizeCoverageBlacklistFiles));
1336-
}
1337-
13381349
if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) {
13391350
bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::HWAddress);
13401351
MPM.addPass(HWAddressSanitizerPass(

0 commit comments

Comments
 (0)