Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e4b36ba

Browse files
committed
Remove an unnecessary block scope.
1 parent 47c8f3f commit e4b36ba

File tree

1 file changed

+79
-89
lines changed

1 file changed

+79
-89
lines changed

src/librustc_codegen_llvm/back/write.rs

Lines changed: 79 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -686,100 +686,90 @@ pub(crate) unsafe fn codegen(
686686
embed_bitcode(cgcx, llcx, llmod, None);
687687
}
688688

689-
{
690-
if config.emit_ir {
691-
let _timer = cgcx
692-
.prof
693-
.generic_activity_with_arg("LLVM_module_codegen_emit_ir", &module.name[..]);
694-
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
695-
let out_c = path_to_c_string(&out);
696-
697-
extern "C" fn demangle_callback(
698-
input_ptr: *const c_char,
699-
input_len: size_t,
700-
output_ptr: *mut c_char,
701-
output_len: size_t,
702-
) -> size_t {
703-
let input = unsafe {
704-
slice::from_raw_parts(input_ptr as *const u8, input_len as usize)
705-
};
706-
707-
let input = match str::from_utf8(input) {
708-
Ok(s) => s,
709-
Err(_) => return 0,
710-
};
711-
712-
let output = unsafe {
713-
slice::from_raw_parts_mut(output_ptr as *mut u8, output_len as usize)
714-
};
715-
let mut cursor = io::Cursor::new(output);
716-
717-
let demangled = match rustc_demangle::try_demangle(input) {
718-
Ok(d) => d,
719-
Err(_) => return 0,
720-
};
721-
722-
if write!(cursor, "{:#}", demangled).is_err() {
723-
// Possible only if provided buffer is not big enough
724-
return 0;
725-
}
726-
727-
cursor.position() as size_t
689+
if config.emit_ir {
690+
let _timer = cgcx
691+
.prof
692+
.generic_activity_with_arg("LLVM_module_codegen_emit_ir", &module.name[..]);
693+
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
694+
let out_c = path_to_c_string(&out);
695+
696+
extern "C" fn demangle_callback(
697+
input_ptr: *const c_char,
698+
input_len: size_t,
699+
output_ptr: *mut c_char,
700+
output_len: size_t,
701+
) -> size_t {
702+
let input =
703+
unsafe { slice::from_raw_parts(input_ptr as *const u8, input_len as usize) };
704+
705+
let input = match str::from_utf8(input) {
706+
Ok(s) => s,
707+
Err(_) => return 0,
708+
};
709+
710+
let output = unsafe {
711+
slice::from_raw_parts_mut(output_ptr as *mut u8, output_len as usize)
712+
};
713+
let mut cursor = io::Cursor::new(output);
714+
715+
let demangled = match rustc_demangle::try_demangle(input) {
716+
Ok(d) => d,
717+
Err(_) => return 0,
718+
};
719+
720+
if write!(cursor, "{:#}", demangled).is_err() {
721+
// Possible only if provided buffer is not big enough
722+
return 0;
728723
}
729724

730-
let result = llvm::LLVMRustPrintModule(llmod, out_c.as_ptr(), demangle_callback);
731-
result.into_result().map_err(|()| {
732-
let msg = format!("failed to write LLVM IR to {}", out.display());
733-
llvm_err(diag_handler, &msg)
734-
})?;
725+
cursor.position() as size_t
735726
}
736727

737-
if config.emit_asm || (config.emit_obj && config.no_integrated_as) {
738-
let _timer = cgcx
739-
.prof
740-
.generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]);
741-
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
742-
743-
// We can't use the same module for asm and binary output, because that triggers
744-
// various errors like invalid IR or broken binaries, so we might have to clone the
745-
// module to produce the asm output
746-
let llmod = if config.emit_obj { llvm::LLVMCloneModule(llmod) } else { llmod };
747-
with_codegen(tm, llmod, config.no_builtins, |cpm| {
748-
write_output_file(
749-
diag_handler,
750-
tm,
751-
cpm,
752-
llmod,
753-
&path,
754-
llvm::FileType::AssemblyFile,
755-
)
756-
})?;
757-
}
728+
let result = llvm::LLVMRustPrintModule(llmod, out_c.as_ptr(), demangle_callback);
729+
result.into_result().map_err(|()| {
730+
let msg = format!("failed to write LLVM IR to {}", out.display());
731+
llvm_err(diag_handler, &msg)
732+
})?;
733+
}
758734

759-
if config.emit_obj && !config.obj_is_bitcode && !config.no_integrated_as {
760-
let _timer = cgcx
761-
.prof
762-
.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]);
763-
with_codegen(tm, llmod, config.no_builtins, |cpm| {
764-
write_output_file(
765-
diag_handler,
766-
tm,
767-
cpm,
768-
llmod,
769-
&obj_out,
770-
llvm::FileType::ObjectFile,
771-
)
772-
})?;
773-
} else if config.emit_obj && config.no_integrated_as {
774-
let _timer = cgcx
775-
.prof
776-
.generic_activity_with_arg("LLVM_module_codegen_asm_to_obj", &module.name[..]);
777-
let assembly = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
778-
run_assembler(cgcx, diag_handler, &assembly, &obj_out);
779-
780-
if !config.emit_asm && !cgcx.save_temps {
781-
drop(fs::remove_file(&assembly));
782-
}
735+
if config.emit_asm || (config.emit_obj && config.no_integrated_as) {
736+
let _timer = cgcx
737+
.prof
738+
.generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]);
739+
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
740+
741+
// We can't use the same module for asm and binary output, because that triggers
742+
// various errors like invalid IR or broken binaries, so we might have to clone the
743+
// module to produce the asm output
744+
let llmod = if config.emit_obj { llvm::LLVMCloneModule(llmod) } else { llmod };
745+
with_codegen(tm, llmod, config.no_builtins, |cpm| {
746+
write_output_file(diag_handler, tm, cpm, llmod, &path, llvm::FileType::AssemblyFile)
747+
})?;
748+
}
749+
750+
if config.emit_obj && !config.obj_is_bitcode && !config.no_integrated_as {
751+
let _timer = cgcx
752+
.prof
753+
.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]);
754+
with_codegen(tm, llmod, config.no_builtins, |cpm| {
755+
write_output_file(
756+
diag_handler,
757+
tm,
758+
cpm,
759+
llmod,
760+
&obj_out,
761+
llvm::FileType::ObjectFile,
762+
)
763+
})?;
764+
} else if config.emit_obj && config.no_integrated_as {
765+
let _timer = cgcx
766+
.prof
767+
.generic_activity_with_arg("LLVM_module_codegen_asm_to_obj", &module.name[..]);
768+
let assembly = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
769+
run_assembler(cgcx, diag_handler, &assembly, &obj_out);
770+
771+
if !config.emit_asm && !cgcx.save_temps {
772+
drop(fs::remove_file(&assembly));
783773
}
784774
}
785775

0 commit comments

Comments
 (0)