Multiple output files created with -o foo --emit=bar -C codegen-units=1 when incremental compilation is enabled

7a5a587
Opened by Will Chandler at 2020-04-20 22:11:05

rustc will not warn that the requested value for codegen-units is ignored when incremental compilation is enabled. If also using -o foo --emit=bar, this results in multiple foo.bar files being created.

It would be useful to have a warning message that codegen-units is being overridden.

There is a similar warning present today that can be triggered with -C codegen-units=2 -o ir --emit=llvm-ir at config.rs#L1740-L1768.

        match codegen_units {
            Some(n) if n > 1 => {
                if matches.opt_present("o") {
                    for ot in &incompatible {
                        early_warn(error_format, &format!("--emit={} with -o incompatible with \
                                                         -C codegen-units=N for N > 1",
                                                        ot));
                    }
                    early_warn(error_format, "resetting to default -C codegen-units=1");

Example - With Incremental Compilation

I expect this to create a single .ll file, but instead four are received

$ cargo new --bin cgu-ignored && cd cgu-ignored
$ cargo rustc -- -o ir --emit=llvm-ir -C codegen-units=1

    warning: ignoring emit path because multiple .ll files were produced

    Finished dev [unoptimized + debuginfo] target(s) in 0.44 secs

$ ls *.ll
ir-a806d54fb39b2862.1y16o1qfye96o7m0.rcgu.ll  ir-a806d54fb39b2862.3rngp6bm2u2q5z0y.rcgu.ll
ir-a806d54fb39b2862.3yvk9x00s7w2trum.rcgu.ll  ir-a806d54fb39b2862.4xq48u46a1pwiqn7.rcgu.ll

Example - Without Incremental Compilation

With incremental compilation turned off, a single file is created as expected

$ CARGO_INCREMENTAL=0 cargo rustc -- -o ir --emit=llvm-ir -C codegen-units=1

    Finished dev [unoptimized + debuginfo] target(s) in 0.31 secs

$ ls *.ll
ir-a806d54fb39b2862.ll

Issue recreated on rustc 1.25.0-nightly (45fba43b3 2018-02-10)

  1. Good catch, thanks for the bug report, @chandlore!

    Michael Woerister at 2018-02-12 14:15:04