From: Joel Rosdahl Date: Wed, 8 Jan 2014 20:13:22 +0000 (+0100) Subject: Require CCACHE_SLOPPINESS=pch_defines,time_macros opt-in to enable PCH handling X-Git-Tag: v3.1.10~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=708d9110a103bd49437be7bff1e82697fff68d0b;p=thirdparty%2Fccache.git Require CCACHE_SLOPPINESS=pch_defines,time_macros opt-in to enable PCH handling The background is that since ccache runs the preprocessor on the header to be precompiled, the preprocessor removes #defines and ccache then hashes the output, which means that changes in #defines are not detected even though the resulting .gch file will have different behavior. --- diff --git a/MANUAL.txt b/MANUAL.txt index f38bd9d0f..5bc1ca395 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -375,6 +375,9 @@ WRAPPERS>>. Ignore *\_\_FILE__* being present in the source. *include_file_mtime*:: Don't check the modification time of include files in the direct mode. +*pch_defines*:: + Be sloppy about #defines when precompiling a header file. See + <<_precompiled_headers,PRECOMPILED HEADERS>> for more information. *time_macros*:: Ignore *\_\_DATE\__* and *\_\_TIME__* being present in the source code. -- @@ -570,9 +573,11 @@ Precompiled headers ccache has support for GCC's precompiled headers. However, you have to do some things to make it work properly: -* You must set *CCACHE_SLOPPINESS* to *time_macros*. The reason is that ccache - can't tell whether *\_\_TIME\__* or *\_\_DATE__* is used when using a - precompiled header. +* You must set *CCACHE_SLOPPINESS* to *pch_defines,time_macros*. The reason is + that ccache can't tell whether *\_\_TIME\__* or *\_\_DATE__* is used when + using a precompiled header. Further, it can't detect changes in #defines in + the source code because of how preprocessing works in combination with + precompiled headers. * You must either: + -- diff --git a/ccache.c b/ccache.c index 6069584a6..dc5498d67 100644 --- a/ccache.c +++ b/ccache.c @@ -1705,9 +1705,10 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, if (found_pch || found_fpch_preprocess) { using_precompiled_header = true; - if (!(sloppiness & SLOPPY_TIME_MACROS)) { - cc_log("You have to specify \"time_macros\" sloppiness when using" - " precompiled headers to get direct hits"); + if (!(sloppiness & SLOPPY_PCH_DEFINES) + || !(sloppiness & SLOPPY_TIME_MACROS)) { + cc_log("You have to specify \"pch_defines,time_macros\" sloppiness when" + " using precompiled headers to get direct hits"); cc_log("Disabling direct mode"); stats_update(STATS_CANTUSEPCH); result = false; @@ -1940,6 +1941,10 @@ parse_sloppiness(char *p) cc_log("Being sloppy about __DATE__ and __TIME__"); result |= SLOPPY_TIME_MACROS; } + if (str_eq(word, "pch_defines")) { + cc_log("Being sloppy about PCH #defines"); + result |= SLOPPY_PCH_DEFINES; + } q = NULL; } free(p); diff --git a/ccache.h b/ccache.h index 2bc7c8775..282f9811a 100644 --- a/ccache.h +++ b/ccache.h @@ -55,6 +55,7 @@ enum stats { #define SLOPPY_INCLUDE_FILE_MTIME 1 #define SLOPPY_FILE_MACRO 2 #define SLOPPY_TIME_MACROS 4 +#define SLOPPY_PCH_DEFINES 8 #define str_eq(s1, s2) (strcmp((s1), (s2)) == 0) #define str_startswith(s, p) (strncmp((s), (p), strlen((p))) == 0) diff --git a/test.sh b/test.sh index d74e520c6..b4360e81d 100755 --- a/test.sh +++ b/test.sh @@ -3,7 +3,7 @@ # A simple test suite for ccache. # # Copyright (C) 2002-2007 Andrew Tridgell -# Copyright (C) 2009-2013 Joel Rosdahl +# Copyright (C) 2009-2014 Joel Rosdahl # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software @@ -1102,11 +1102,11 @@ EOF #define time __TIME__ int test; EOF - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time.c + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c time.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time.c + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c time.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -1121,11 +1121,11 @@ EOF cat <time_h.c #include "time.h" EOF - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time_h.c + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c time_h.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time_h.c + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c time_h.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -1761,7 +1761,7 @@ EOF # trying to preprocess: checkstat 'preprocessor error' 1 - testname="no -fpch-preprocess, -include, no sloppy time macros" + testname="no -fpch-preprocess, -include, no sloppiness" $CCACHE -Cz >/dev/null $CCACHE $COMPILER -c -include pch.h pch2.c 2>/dev/null checkstat 'cache hit (direct)' 0 @@ -1772,16 +1772,16 @@ EOF testname="no -fpch-preprocess, -include" $CCACHE -Cz >/dev/null - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -include pch.h pch2.c 2>/dev/null + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c -include pch.h pch2.c 2>/dev/null checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -include pch.h pch2.c 2>/dev/null + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c -include pch.h pch2.c 2>/dev/null checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - testname="-fpch-preprocess, #include, no sloppy time macros" + testname="-fpch-preprocess, #include, no sloppiness" $CCACHE -Cz >/dev/null $CCACHE $COMPILER -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 @@ -1789,13 +1789,13 @@ EOF # Must enable sloppy time macros: checkstat "can't use precompiled header" 1 - testname="-fpch-preprocess, #include, sloppy time macros" + testname="-fpch-preprocess, #include, sloppiness" $CCACHE -Cz >/dev/null - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -1803,18 +1803,18 @@ EOF testname="-fpch-preprocess, #include, file changed" echo "updated" >>pch.h.gch # GCC seems to cope with this... backdate pch.h.gch - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 2 testname="preprocessor mode" $CCACHE -Cz >/dev/null - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 1 checkstat 'cache miss' 1 @@ -1822,11 +1822,11 @@ EOF testname="preprocessor mode, file changed" echo "updated" >>pch.h.gch # GCC seems to cope with this... backdate pch.h.gch - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 1 checkstat 'cache miss' 2 - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 2 checkstat 'cache miss' 2