]> git.lizzy.rs Git - rust.git/commitdiff
When given `rustc -C codegen-units=4 -o output --emit=obj`, reset units back to 1.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Fri, 4 Dec 2015 18:35:16 +0000 (19:35 +0100)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Tue, 8 Dec 2015 04:37:04 +0000 (05:37 +0100)
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

index dbeb4c3ed734cee8d28b408c3198992b2a7b0211..e30f98119e8f2c470497d9b03aabdbc83156ff53 100644 (file)
@@ -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(