Skip to content

Commit 3ec6882

Browse files
celinvaltedinski
authored andcommitted
Fix rmc codegen to check for no-codegen option (rust-lang#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.
1 parent a60612d commit 3ec6882

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

compiler/rustc_codegen_rmc/src/compiler_interface.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl CodegenBackend for GotocCodegenBackend {
147147

148148
fn link(
149149
&self,
150-
_sess: &Session,
150+
sess: &Session,
151151
codegen_results: Box<dyn Any>,
152152
outputs: &OutputFilenames,
153153
) -> Result<(), ErrorReported> {
@@ -157,18 +157,21 @@ impl CodegenBackend for GotocCodegenBackend {
157157
.downcast::<GotocCodegenResult>()
158158
.expect("in link: codegen_results is not a GotocCodegenResult");
159159

160-
// "path.o"
161-
let base_filename = outputs.path(OutputType::Object);
160+
// No output should be generated if user selected no_codegen.
161+
if !sess.opts.debugging_opts.no_codegen && sess.opts.output_types.should_codegen() {
162+
// "path.o"
163+
let base_filename = outputs.path(OutputType::Object);
162164

163-
let symtab_filename = base_filename.with_extension("symtab.json");
164-
debug!("output to {:?}", symtab_filename);
165-
let mut out_file = ::std::fs::File::create(&symtab_filename).unwrap();
166-
write!(out_file, "{}", result.symtab.to_irep().to_json().pretty().to_string()).unwrap();
165+
let symtab_filename = base_filename.with_extension("symtab.json");
166+
debug!("output to {:?}", symtab_filename);
167+
let mut out_file = ::std::fs::File::create(&symtab_filename).unwrap();
168+
write!(out_file, "{}", result.symtab.to_irep().to_json().pretty().to_string()).unwrap();
167169

168-
let type_map_filename = base_filename.with_extension("type_map.json");
169-
debug!("type_map to {:?}", type_map_filename);
170-
let mut out_file = ::std::fs::File::create(&type_map_filename).unwrap();
171-
write!(out_file, "{}", result.type_map.to_json().pretty().to_string()).unwrap();
170+
let type_map_filename = base_filename.with_extension("type_map.json");
171+
debug!("type_map to {:?}", type_map_filename);
172+
let mut out_file = ::std::fs::File::create(&type_map_filename).unwrap();
173+
write!(out_file, "{}", result.type_map.to_json().pretty().to_string()).unwrap();
174+
}
172175

173176
Ok(())
174177
}

0 commit comments

Comments
 (0)