From 3ec6882bc4510468e3b7cd1848bc72c426173808 Mon Sep 17 00:00:00 2001 From: "Celina G. Val" Date: Fri, 29 Oct 2021 13:26:17 -0700 Subject: [PATCH] Fix rmc codegen to check for no-codegen option (#601) RMC code generation was creating artifacts even if rustc was run with -Z no-codegen. I changed the codegen to check for this option before writing the json files. This issue was uncovered by my change to move the rmc flags to rmc-rustc. This script is used during compiletest. In the check stage, the test runs rustc with --no-codegen. --- .../src/compiler_interface.rs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_codegen_rmc/src/compiler_interface.rs b/compiler/rustc_codegen_rmc/src/compiler_interface.rs index 9bdce920549c0..c48fcc5e5c257 100644 --- a/compiler/rustc_codegen_rmc/src/compiler_interface.rs +++ b/compiler/rustc_codegen_rmc/src/compiler_interface.rs @@ -147,7 +147,7 @@ impl CodegenBackend for GotocCodegenBackend { fn link( &self, - _sess: &Session, + sess: &Session, codegen_results: Box, outputs: &OutputFilenames, ) -> Result<(), ErrorReported> { @@ -157,18 +157,21 @@ impl CodegenBackend for GotocCodegenBackend { .downcast::() .expect("in link: codegen_results is not a GotocCodegenResult"); - // "path.o" - let base_filename = outputs.path(OutputType::Object); + // No output should be generated if user selected no_codegen. + if !sess.opts.debugging_opts.no_codegen && sess.opts.output_types.should_codegen() { + // "path.o" + let base_filename = outputs.path(OutputType::Object); - let symtab_filename = base_filename.with_extension("symtab.json"); - debug!("output to {:?}", symtab_filename); - let mut out_file = ::std::fs::File::create(&symtab_filename).unwrap(); - write!(out_file, "{}", result.symtab.to_irep().to_json().pretty().to_string()).unwrap(); + let symtab_filename = base_filename.with_extension("symtab.json"); + debug!("output to {:?}", symtab_filename); + let mut out_file = ::std::fs::File::create(&symtab_filename).unwrap(); + write!(out_file, "{}", result.symtab.to_irep().to_json().pretty().to_string()).unwrap(); - let type_map_filename = base_filename.with_extension("type_map.json"); - debug!("type_map to {:?}", type_map_filename); - let mut out_file = ::std::fs::File::create(&type_map_filename).unwrap(); - write!(out_file, "{}", result.type_map.to_json().pretty().to_string()).unwrap(); + let type_map_filename = base_filename.with_extension("type_map.json"); + debug!("type_map to {:?}", type_map_filename); + let mut out_file = ::std::fs::File::create(&type_map_filename).unwrap(); + write!(out_file, "{}", result.type_map.to_json().pretty().to_string()).unwrap(); + } Ok(()) }