Skip to content

Commit 56a1f51

Browse files
committed
Auto merge of #30208 - pnkfelix:fix-issue-30063, r=alexcrichton
When given `rustc -C codegen-units=4 --emit=obj`, reset units back to 1. Fix #30063 Note: while this code is careful to handle the case of mutliple emit types (e.g. `--emit=asm,obj`) by reporting all the emit types that conflict with codegen units in its warnings, an invocation with multiple emit types *and* `-o PATH` will continue to ignore the requested target path (with a warning), as it already does today, since the code that checks for that is further downstream. (Multiple emit types without `-o PATH` will "work", though it will downgrade codegen-units to 1 just like all the other cases.) r? @alexcrichton
2 parents 462ec05 + 9b5b2e3 commit 56a1f51

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

src/librustc/session/config.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ pub enum OutputType {
7171
DepInfo,
7272
}
7373

74+
impl OutputType {
75+
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
76+
match *self {
77+
OutputType::Exe |
78+
OutputType::DepInfo => true,
79+
OutputType::Bitcode |
80+
OutputType::Assembly |
81+
OutputType::LlvmAssembly |
82+
OutputType::Object => false,
83+
}
84+
}
85+
86+
fn shorthand(&self) -> &'static str {
87+
match *self {
88+
OutputType::Bitcode => "llvm-bc",
89+
OutputType::Assembly => "asm",
90+
OutputType::LlvmAssembly => "llvm-ir",
91+
OutputType::Object => "obj",
92+
OutputType::Exe => "link",
93+
OutputType::DepInfo => "dep-info",
94+
}
95+
}
96+
}
97+
7498
#[derive(Clone)]
7599
pub struct Options {
76100
// The crate config requested for the session, which may be combined
@@ -933,7 +957,28 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
933957
output_types.insert(OutputType::Exe, None);
934958
}
935959

936-
let cg = build_codegen_options(matches, color);
960+
let mut cg = build_codegen_options(matches, color);
961+
962+
// Issue #30063: if user requests llvm-related output to one
963+
// particular path, disable codegen-units.
964+
if matches.opt_present("o") && cg.codegen_units != 1 {
965+
let incompatible: Vec<_> = output_types.iter()
966+
.map(|ot_path| ot_path.0)
967+
.filter(|ot| {
968+
!ot.is_compatible_with_codegen_units_and_single_output_file()
969+
}).collect();
970+
if !incompatible.is_empty() {
971+
for ot in &incompatible {
972+
early_warn(color, &format!("--emit={} with -o incompatible with \
973+
-C codegen-units=N for N > 1",
974+
ot.shorthand()));
975+
}
976+
early_warn(color, "resetting to default -C codegen-units=1");
977+
cg.codegen_units = 1;
978+
}
979+
}
980+
981+
let cg = cg;
937982

938983
let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::from(&m));
939984
let target = matches.opt_str("target").unwrap_or(
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-include ../tools.mk
2+
3+
all:
4+
rm -f $(TMPDIR)/foo-output
5+
$(RUSTC) -C codegen-units=4 -o $(TMPDIR)/foo-output foo.rs
6+
rm $(TMPDIR)/foo-output
7+
8+
rm -f $(TMPDIR)/asm-output
9+
$(RUSTC) -C codegen-units=4 --emit=asm -o $(TMPDIR)/asm-output foo.rs
10+
rm $(TMPDIR)/asm-output
11+
12+
rm -f $(TMPDIR)/bc-output
13+
$(RUSTC) -C codegen-units=4 --emit=llvm-bc -o $(TMPDIR)/bc-output foo.rs
14+
rm $(TMPDIR)/bc-output
15+
16+
rm -f $(TMPDIR)/ir-output
17+
$(RUSTC) -C codegen-units=4 --emit=llvm-ir -o $(TMPDIR)/ir-output foo.rs
18+
rm $(TMPDIR)/ir-output
19+
20+
rm -f $(TMPDIR)/link-output
21+
$(RUSTC) -C codegen-units=4 --emit=link -o $(TMPDIR)/link-output foo.rs
22+
rm $(TMPDIR)/link-output
23+
24+
rm -f $(TMPDIR)/obj-output
25+
$(RUSTC) -C codegen-units=4 --emit=obj -o $(TMPDIR)/obj-output foo.rs
26+
rm $(TMPDIR)/obj-output
27+
28+
rm -f $(TMPDIR)/dep-output
29+
$(RUSTC) -C codegen-units=4 --emit=dep-info -o $(TMPDIR)/dep-output foo.rs
30+
rm $(TMPDIR)/dep-output
31+
32+
# # (This case doesn't work yet, and may be fundamentally wrong-headed anyway.)
33+
# rm -f $(TMPDIR)/multi-output
34+
# $(RUSTC) -C codegen-units=4 --emit=asm,obj -o $(TMPDIR)/multi-output foo.rs
35+
# rm $(TMPDIR)/multi-output

src/test/run-make/issue-30063/foo.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() { }

0 commit comments

Comments
 (0)