diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2022-07-17 21:55:06 +0200 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2022-07-18 13:59:06 +0200 |
commit | 96ec6c9d98b88f00e1a69bdd0214c237bc7ed04e (patch) | |
tree | 4b445784deec8d209390d8a0923d784ef353d9b0 /unittest | |
parent | 195011ad1b1f0a9c43794532571261d8c0c5e1c6 (diff) | |
download | ccache-96ec6c9d98b88f00e1a69bdd0214c237bc7ed04e.tar.gz |
fix: Avoid false success for -fcolor-diagnostics probe with GCC
Ccache will produce a false hit in the following scenario, if "cc" is
GCC without being a symlink to "gcc":
1. ccache cc -c example.c # adds a cache entry
2. ccache cc -c example.c -fcolor-diagnostics # unexpectedly succeeds
(Most major Linux distributions install cc as a symlink to gcc, and then
the problem doesn't show up since ccache then is able to guess that the
compiler is GCC.)
This bug was introduced by [1] which tried to make yet another tweak of
the color diagnostics guessing/probing by no longer rejecting
-fcolor-diagnostics for an unknown compiler, based on the assumption
that the probing call (speculatively adding -fdiagnostics-color) is only
made when we have guessed a GCC compiler. Unfortunately, this broke the
fix in [2] when the compiler is unknown.
All of this is inherently brittle and I don't see any good way to make
it better with the current compiler guessing approach and adding options
speculatively. The cure is to start doing proper compiler identification
instead (#958). Until that is done, the only reasonable fix is to avoid
doing anything related to color diagnostics flags when the compiler is
unknown. This means that an unknown compiler from now on won't produce
colors when used via ccache even if the compiler actually is GCC or
Clang.
[1]: 97a40af49f56e4be2db5e4318d8131e937bd5598
[2]: 61ce8c44c5b1da0be7a8d10c014f1a85b7967433
Closes #1116.
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/test_argprocessing.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/unittest/test_argprocessing.cpp b/unittest/test_argprocessing.cpp index 09c27b94..f5e86193 100644 --- a/unittest/test_argprocessing.cpp +++ b/unittest/test_argprocessing.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2010-2021 Joel Rosdahl and other contributors +// Copyright (C) 2010-2022 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -569,6 +569,8 @@ TEST_CASE("-Xclang") { TestContext test_context; Context ctx; + ctx.config.set_compiler_type(CompilerType::clang); + const std::string common_args = "-Xclang -fno-pch-timestamp" " -Xclang unsupported"; @@ -586,17 +588,17 @@ TEST_CASE("-Xclang") " -Xclang -include-pth -Xclang pth_path2"; ctx.orig_args = - Args::from_string("gcc -c foo.c " + common_args + " " + color_diag + " " + Args::from_string("clang -c foo.c " + common_args + " " + color_diag + " " + extra_args + " " + pch_pth_variants); Util::write_file("foo.c", ""); const ProcessArgsResult result = process_args(ctx); CHECK(result.preprocessor_args.to_string() - == "gcc " + common_args + " " + pch_pth_variants); + == "clang " + common_args + " " + pch_pth_variants); CHECK(result.extra_args_to_hash.to_string() == extra_args); CHECK(result.compiler_args.to_string() - == "gcc " + common_args + " " + color_diag + " " + extra_args + " " - + pch_pth_variants + " -c"); + == "clang " + common_args + " " + color_diag + " " + extra_args + " " + + pch_pth_variants + " -c -fcolor-diagnostics"); } TEST_CASE("-x") |