Skip to content

Commit d4593af

Browse files
committed
Change registered "program name" for -Cllvm-args usage messages
While debugging a codegen issue, I tried adding LLVM options with the rustc -Cllvm-args option, and was confused by the error and usage messaging. The LLVM "program name" argument is set to "rustc", and command line error messages make it look like invalid arguments are "rustc" arguments, not LLVM. I changed this argument so error messages and the "-help" usage feedback is easier to understand and react to. (Clang does something similar.)
1 parent 3cfc7fe commit d4593af

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Diff for: src/librustc_codegen_llvm/llvm_util.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ unsafe fn configure_llvm(sess: &Session) {
7373
llvm_c_strs.push(s);
7474
}
7575
};
76-
add("rustc", true); // fake program name
76+
// Set the llvm "program name" to make usage and invalid argument messages more clear.
77+
add("rustc -Cllvm-args=\"...\" with", true);
7778
if sess.time_llvm_passes() {
7879
add("-time-passes", false);
7980
}

Diff for: src/test/ui/unknown-llvm-arg.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// compile-flags: -Cllvm-args=-not-a-real-llvm-arg
2+
// normalize-stderr-test "--help" -> "-help"
3+
// normalize-stderr-test "\n(\n|.)*" -> ""
4+
5+
// I'm seeing "--help" locally, but "-help" in CI, so I'm normalizing it to just "-help".
6+
7+
// Note that the rustc-supplied "program name", given when invoking LLVM, is used by LLVM to
8+
// generate user-facing error messages and a usage (--help) messages. If the program name is
9+
// `rustc`, the usage message in response to `--llvm-args="--help"` starts with:
10+
// ```
11+
// USAGE: rustc [options]
12+
// ```
13+
// followed by the list of options not to `rustc` but to `llvm`.
14+
//
15+
// On the other hand, if the program name is set to `rustc -Cllvm-args="..." with`, the usage
16+
// message is more clear:
17+
// ```
18+
// USAGE: rustc -Cllvm-args="..." with [options]
19+
// ```
20+
// This test captures the effect of the current program name setting on LLVM command line
21+
// error messages.
22+
fn main() {}

Diff for: src/test/ui/unknown-llvm-arg.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rustc -Cllvm-args="..." with: Unknown command line argument '-not-a-real-llvm-arg'. Try: 'rustc -Cllvm-args="..." with -help'

0 commit comments

Comments
 (0)