]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Require CCACHE_SLOPPINESS=pch_defines,time_macros opt-in to enable PCH handling
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 8 Jan 2014 20:13:22 +0000 (21:13 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 8 Jan 2014 20:13:22 +0000 (21:13 +0100)
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.

MANUAL.txt
ccache.c
ccache.h
test.sh

index f38bd9d0f4ce29b21dcc8150600ce37128efff8a..5bc1ca3950943e87ded72f04b2d79b1be8685ed2 100644 (file)
@@ -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:
 +
 --
index 6069584a6363110f645c8498eebd3b60d8f7f6ff..dc5498d67a1a6685ac4e1fbd673bcb11fc0d5706 100644 (file)
--- 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);
index 2bc7c8775249f9e1940ea2aeb9f251cf87952ff5..282f9811a86537e15ecc792c8233eed48a6bdfba 100644 (file)
--- 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 d74e520c622898e49f2c2ccf95c3e609ba233b53..b4360e81da89968df685e561e765672c56f01ce6 100755 (executable)
--- 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 <<EOF >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