Skip to content

Commit 3b45626

Browse files
committed
Create sanitizer passes in a separate function
1 parent 5024d14 commit 3b45626

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

src/librustc_codegen_llvm/back/write.rs

+26-20
Original file line numberDiff line numberDiff line change
@@ -363,26 +363,7 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,
363363
}
364364
}
365365

366-
if let Some(sanitizer) = &config.sanitizer {
367-
let recover = config.sanitizer_recover.contains(sanitizer);
368-
match sanitizer {
369-
Sanitizer::Address => {
370-
extra_passes.push(llvm::LLVMRustCreateAddressSanitizerFunctionPass(
371-
recover));
372-
extra_passes.push(llvm::LLVMRustCreateModuleAddressSanitizerPass(
373-
recover));
374-
}
375-
Sanitizer::Memory => {
376-
let track_origins = config.sanitizer_memory_track_origins as c_int;
377-
extra_passes.push(llvm::LLVMRustCreateMemorySanitizerPass(
378-
track_origins, recover));
379-
}
380-
Sanitizer::Thread => {
381-
extra_passes.push(llvm::LLVMRustCreateThreadSanitizerPass());
382-
}
383-
_ => {}
384-
}
385-
}
366+
add_sanitizer_passes(config, &mut extra_passes);
386367

387368
for pass_name in &cgcx.plugin_passes {
388369
if let Some(pass) = find_pass(pass_name) {
@@ -469,6 +450,31 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,
469450
Ok(())
470451
}
471452

453+
unsafe fn add_sanitizer_passes(config: &ModuleConfig,
454+
passes: &mut Vec<&'static mut llvm::Pass>) {
455+
456+
let sanitizer = match &config.sanitizer {
457+
None => return,
458+
Some(s) => s,
459+
};
460+
461+
let recover = config.sanitizer_recover.contains(sanitizer);
462+
match sanitizer {
463+
Sanitizer::Address => {
464+
passes.push(llvm::LLVMRustCreateAddressSanitizerFunctionPass(recover));
465+
passes.push(llvm::LLVMRustCreateModuleAddressSanitizerPass(recover));
466+
}
467+
Sanitizer::Memory => {
468+
let track_origins = config.sanitizer_memory_track_origins as c_int;
469+
passes.push(llvm::LLVMRustCreateMemorySanitizerPass(track_origins, recover));
470+
}
471+
Sanitizer::Thread => {
472+
passes.push(llvm::LLVMRustCreateThreadSanitizerPass());
473+
}
474+
Sanitizer::Leak => {}
475+
}
476+
}
477+
472478
pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>,
473479
diag_handler: &Handler,
474480
module: ModuleCodegen<ModuleLlvm>,

0 commit comments

Comments
 (0)