Skip to content

Commit 63e63e0

Browse files
committed
ZigLLVMTargetMachineEmitToFile: make sancov enable the options
1 parent 62452ee commit 63e63e0

File tree

1 file changed

+41
-26
lines changed

1 file changed

+41
-26
lines changed

src/zig_llvm.cpp

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,27 @@ struct TimeTracerRAII {
189189
};
190190
} // end anonymous namespace
191191

192+
static SanitizerCoverageOptions getSanCovOptions(void) {
193+
SanitizerCoverageOptions o;
194+
o.CoverageType = SanitizerCoverageOptions::SCK_Edge;
195+
o.IndirectCalls = true;
196+
o.TraceBB = false;
197+
o.TraceCmp = true;
198+
o.TraceDiv = false;
199+
o.TraceGep = false;
200+
o.Use8bitCounters = false;
201+
o.TracePC = false;
202+
o.TracePCGuard = false;
203+
o.Inline8bitCounters = true;
204+
o.InlineBoolFlag = false;
205+
o.PCTable = true;
206+
o.NoPrune = false;
207+
o.StackDepth = true;
208+
o.TraceLoads = false;
209+
o.TraceStores = false;
210+
o.CollectControlFlow = false;
211+
return o;
212+
}
192213

193214
bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
194215
char **error_message, bool is_debug,
@@ -279,36 +300,23 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
279300
pass_builder.registerCGSCCAnalyses(cgscc_am);
280301
pass_builder.registerFunctionAnalyses(function_am);
281302
pass_builder.registerLoopAnalyses(loop_am);
282-
pass_builder.crossRegisterProxies(loop_am, function_am,
283-
cgscc_am, module_am);
284-
285-
// IR verification
286-
if (assertions_on) {
287-
// Verify the input
288-
pass_builder.registerPipelineStartEPCallback(
289-
[](ModulePassManager &module_pm, OptimizationLevel OL) {
290-
module_pm.addPass(VerifierPass());
291-
});
292-
// Verify the output
293-
pass_builder.registerOptimizerLastEPCallback(
294-
[](ModulePassManager &module_pm, OptimizationLevel OL) {
295-
module_pm.addPass(VerifierPass());
296-
});
297-
}
303+
pass_builder.crossRegisterProxies(loop_am, function_am, cgscc_am, module_am);
298304

299-
// Passes specific for release build
300-
if (!is_debug) {
301-
pass_builder.registerPipelineStartEPCallback(
302-
[](ModulePassManager &module_pm, OptimizationLevel OL) {
303-
module_pm.addPass(
304-
createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
305-
});
306-
}
305+
pass_builder.registerPipelineStartEPCallback([&](ModulePassManager &module_pm, OptimizationLevel OL) {
306+
// Verify the input
307+
if (assertions_on) {
308+
module_pm.addPass(VerifierPass());
309+
}
307310

308-
pass_builder.registerOptimizerLastEPCallback([&](ModulePassManager &module_pm, OptimizationLevel level) {
311+
if (!is_debug) {
312+
module_pm.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
313+
}
314+
});
315+
316+
pass_builder.registerOptimizerEarlyEPCallback([&](ModulePassManager &module_pm, OptimizationLevel OL) {
309317
// Code coverage instrumentation.
310318
if (sancov) {
311-
module_pm.addPass(SanitizerCoveragePass());
319+
module_pm.addPass(SanitizerCoveragePass(getSanCovOptions()));
312320
}
313321

314322
// Thread sanitizer
@@ -318,6 +326,13 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
318326
}
319327
});
320328

329+
pass_builder.registerOptimizerLastEPCallback([&](ModulePassManager &module_pm, OptimizationLevel level) {
330+
// Verify the output
331+
if (assertions_on) {
332+
module_pm.addPass(VerifierPass());
333+
}
334+
});
335+
321336
ModulePassManager module_pm;
322337
OptimizationLevel opt_level;
323338
// Setting up the optimization level

0 commit comments

Comments
 (0)