ZigLLVMTargetMachineEmitToFile: schedule sancov pass depending on mode

In debug mode, schedule it early. In release modes, schedule it late.
This commit is contained in:
Andrew Kelley 2025-02-11 11:13:41 -08:00
parent 4162f401cb
commit 31c1320818

View File

@ -311,19 +311,35 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi
} }
}); });
//pass_builder.registerOptimizerEarlyEPCallback([&](ModulePassManager &module_pm, OptimizationLevel OL) { const bool early_san = options->is_debug;
//});
pass_builder.registerOptimizerEarlyEPCallback([&](ModulePassManager &module_pm, OptimizationLevel OL) {
if (early_san) {
// Code coverage instrumentation.
if (options->sancov) {
module_pm.addPass(SanitizerCoveragePass(getSanCovOptions(options->coverage)));
}
// Thread sanitizer
if (options->tsan) {
module_pm.addPass(ModuleThreadSanitizerPass());
module_pm.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
}
}
});
pass_builder.registerOptimizerLastEPCallback([&](ModulePassManager &module_pm, OptimizationLevel level) { pass_builder.registerOptimizerLastEPCallback([&](ModulePassManager &module_pm, OptimizationLevel level) {
// Code coverage instrumentation. if (!early_san) {
if (options->sancov) { // Code coverage instrumentation.
module_pm.addPass(SanitizerCoveragePass(getSanCovOptions(options->coverage))); if (options->sancov) {
} module_pm.addPass(SanitizerCoveragePass(getSanCovOptions(options->coverage)));
}
// Thread sanitizer // Thread sanitizer
if (options->tsan) { if (options->tsan) {
module_pm.addPass(ModuleThreadSanitizerPass()); module_pm.addPass(ModuleThreadSanitizerPass());
module_pm.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); module_pm.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
}
} }
// Verify the output // Verify the output