From: Joel Rosdahl Date: Wed, 30 Dec 2020 20:22:26 +0000 (+0100) Subject: Only accept -f(no-)color-diagnostics for Clang X-Git-Tag: v4.2~61 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=61ce8c44;p=thirdparty%2Fccache.git Only accept -f(no-)color-diagnostics for Clang If a non-Clang compiler gets -f(no-)color-diagnostics then bail out and just execute the compiler. The reason is that we don't include -f(no-)color-diagnostics in the hash so there can be a false cache hit in the following scenario: 1. ccache gcc -c example.c # adds a cache entry 2. ccache gcc -c example.c -fcolor-diagnostics # unexpectedly succeeds Closes: #740. --- diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 1783f9f03..983ccdb45 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -688,6 +688,19 @@ process_arg(Context& ctx, return nullopt; } + if (config.compiler_type() != CompilerType::clang + && (args[i] == "-fcolor-diagnostics" + || args[i] == "-fno-color-diagnostics")) { + // Special case: If a non-Clang compiler gets -f(no-)color-diagnostics we'll + // bail out and just execute the compiler. The reason is that we don't + // include -f(no-)color-diagnostics in the hash so there can be a false + // cache hit in the following scenario: + // + // 1. ccache gcc -c example.c # adds a cache entry + // 2. ccache gcc -c example.c -fcolor-diagnostics # unexpectedly succeeds + return Statistic::unsupported_compiler_option; + } + if (args[i] == "-fcolor-diagnostics" || args[i] == "-fdiagnostics-color" || args[i] == "-fdiagnostics-color=always") { state.color_diagnostics = ColorDiagnostics::always; diff --git a/test/suites/color_diagnostics.bash b/test/suites/color_diagnostics.bash index 64c7d4f18..4ec99f402 100644 --- a/test/suites/color_diagnostics.bash +++ b/test/suites/color_diagnostics.bash @@ -113,17 +113,32 @@ color_diagnostics_test() { expect_stat 'cache miss' 1 expect_stat 'cache hit (preprocessed)' 1 - # ------------------------------------------------------------------------- if $COMPILER_TYPE_GCC; then + # --------------------------------------------------------------------- TEST "-fcolor-diagnostics not accepted for GCC" generate_code 1 test.c + + if $CCACHE_COMPILE -fcolor-diagnostics -c test.c >&/dev/null; then + test_failed "-fcolor-diagnostics unexpectedly accepted by GCC" + fi + + # --------------------------------------------------------------------- + TEST "-fcolor-diagnostics not accepted for GCC for cached result" + + generate_code 1 test.c + + if ! $CCACHE_COMPILE -c test.c >&/dev/null; then + test_failed "unknown error compiling" + fi + if $CCACHE_COMPILE -fcolor-diagnostics -c test.c >&/dev/null; then test_failed "-fcolor-diagnostics unexpectedly accepted by GCC" fi fi while read -r case; do + # --------------------------------------------------------------------- TEST "Cache object shared across ${case} (run_second_cpp=$run_second_cpp)" color_diagnostics_generate_code test1.c