From f90c21a417b8279196ec65077863f9ecc5b05e39 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 4 Dec 2015 19:35:16 +0100 Subject: [PATCH 1/2] When given `rustc -C codegen-units=4 -o output --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. --- src/librustc/session/config.rs | 47 +++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index dbeb4c3ed73..e30f98119e8 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -71,6 +71,30 @@ pub enum OutputType { DepInfo, } +impl OutputType { + fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool { + match *self { + OutputType::Exe | + OutputType::DepInfo => true, + OutputType::Bitcode | + OutputType::Assembly | + OutputType::LlvmAssembly | + OutputType::Object => false, + } + } + + fn shorthand(&self) -> &'static str { + match *self { + OutputType::Bitcode => "llvm-bc", + OutputType::Assembly => "asm", + OutputType::LlvmAssembly => "llvm-ir", + OutputType::Object => "obj", + OutputType::Exe => "link", + OutputType::DepInfo => "dep-info", + } + } +} + #[derive(Clone)] pub struct Options { // The crate config requested for the session, which may be combined @@ -933,7 +957,28 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { output_types.insert(OutputType::Exe, None); } - let cg = build_codegen_options(matches, color); + let mut cg = build_codegen_options(matches, color); + + // Issue #30063: if user requests llvm-related output to one + // particular path, disable codegen-units. + if matches.opt_present("o") && cg.codegen_units != 1 { + let incompatible: Vec<_> = output_types.iter() + .map(|ot_path| ot_path.0) + .filter(|ot| { + !ot.is_compatible_with_codegen_units_and_single_output_file() + }).collect(); + if !incompatible.is_empty() { + for ot in &incompatible { + early_warn(color, &format!("--emit={} with -o incompatible with \ + -C codegen-units=N for N > 1", + ot.shorthand())); + } + early_warn(color, "resetting to default -C codegen-units=1"); + cg.codegen_units = 1; + } + } + + let cg = cg; let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::from(&m)); let target = matches.opt_str("target").unwrap_or( From 9b5b2e3f5950ba771defb03b6628e7f88b21c136 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 4 Dec 2015 19:38:00 +0100 Subject: [PATCH 2/2] regression test for issue #30063 --- src/test/run-make/issue-30063/Makefile | 35 ++++++++++++++++++++++++++ src/test/run-make/issue-30063/foo.rs | 11 ++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/test/run-make/issue-30063/Makefile create mode 100644 src/test/run-make/issue-30063/foo.rs diff --git a/src/test/run-make/issue-30063/Makefile b/src/test/run-make/issue-30063/Makefile new file mode 100644 index 00000000000..a76051dc81e --- /dev/null +++ b/src/test/run-make/issue-30063/Makefile @@ -0,0 +1,35 @@ +-include ../tools.mk + +all: + rm -f $(TMPDIR)/foo-output + $(RUSTC) -C codegen-units=4 -o $(TMPDIR)/foo-output foo.rs + rm $(TMPDIR)/foo-output + + rm -f $(TMPDIR)/asm-output + $(RUSTC) -C codegen-units=4 --emit=asm -o $(TMPDIR)/asm-output foo.rs + rm $(TMPDIR)/asm-output + + rm -f $(TMPDIR)/bc-output + $(RUSTC) -C codegen-units=4 --emit=llvm-bc -o $(TMPDIR)/bc-output foo.rs + rm $(TMPDIR)/bc-output + + rm -f $(TMPDIR)/ir-output + $(RUSTC) -C codegen-units=4 --emit=llvm-ir -o $(TMPDIR)/ir-output foo.rs + rm $(TMPDIR)/ir-output + + rm -f $(TMPDIR)/link-output + $(RUSTC) -C codegen-units=4 --emit=link -o $(TMPDIR)/link-output foo.rs + rm $(TMPDIR)/link-output + + rm -f $(TMPDIR)/obj-output + $(RUSTC) -C codegen-units=4 --emit=obj -o $(TMPDIR)/obj-output foo.rs + rm $(TMPDIR)/obj-output + + rm -f $(TMPDIR)/dep-output + $(RUSTC) -C codegen-units=4 --emit=dep-info -o $(TMPDIR)/dep-output foo.rs + rm $(TMPDIR)/dep-output + +# # (This case doesn't work yet, and may be fundamentally wrong-headed anyway.) +# rm -f $(TMPDIR)/multi-output +# $(RUSTC) -C codegen-units=4 --emit=asm,obj -o $(TMPDIR)/multi-output foo.rs +# rm $(TMPDIR)/multi-output diff --git a/src/test/run-make/issue-30063/foo.rs b/src/test/run-make/issue-30063/foo.rs new file mode 100644 index 00000000000..45f7a2c2aa6 --- /dev/null +++ b/src/test/run-make/issue-30063/foo.rs @@ -0,0 +1,11 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { }