From: Joel Rosdahl Date: Wed, 21 Feb 2018 19:58:45 +0000 (+0100) Subject: Hash preprocessed headers located in “.gch directories” correctly X-Git-Tag: v3.4.2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2280c55ce5575bce48b3699b075f0c6b074bb6a;p=thirdparty%2Fccache.git Hash preprocessed headers located in “.gch directories” correctly Previously, ccache would not pick up changes to such precompiled headers, risking false positive cache hits. --- diff --git a/doc/NEWS.txt b/doc/NEWS.txt index f8c7d98fc..e306fb340 100644 --- a/doc/NEWS.txt +++ b/doc/NEWS.txt @@ -1,6 +1,18 @@ ccache news =========== +ccache 3.4.2 +------------ +Release date: unknown + +Bug fixes +~~~~~~~~~ + +- Correctly hash preprocessed headers located in a ``.gch directory''. + Previously, ccache would not pick up changes to such precompiled headers, + risking false positive cache hits. + + ccache 3.4.1 ------------ Release date: 2018-02-11 diff --git a/src/ccache.c b/src/ccache.c index 9dfdbfc1b..950317414 100644 --- a/src/ccache.c +++ b/src/ccache.c @@ -2077,7 +2077,15 @@ bool is_precompiled_header(const char *path) { const char *ext = get_extension(path); - return str_eq(ext, ".gch") || str_eq(ext, ".pch") || str_eq(ext, ".pth"); + char *dir = dirname(path); + const char *dir_ext = get_extension(dir); + bool result = + str_eq(ext, ".gch") + || str_eq(ext, ".pch") + || str_eq(ext, ".pth") + || str_eq(dir_ext, ".gch"); // See "Precompiled Headers" in GCC docs. + free(dir); + return result; } static bool diff --git a/test/suites/pch.bash b/test/suites/pch.bash index 34c225bd5..c098e7f41 100644 --- a/test/suites/pch.bash +++ b/test/suites/pch.bash @@ -246,6 +246,50 @@ pch_suite_gcc() { expect_stat 'cache hit (direct)' 0 expect_stat 'cache hit (preprocessed)' 1 expect_stat 'cache miss' 2 + + # ------------------------------------------------------------------------- + TEST "Create and use .gch directory" + + mkdir pch.h.gch + + CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -x c-header -c pch.h -o pch.h.gch/foo + expect_stat 'cache hit (direct)' 0 + expect_stat 'cache hit (preprocessed)' 0 + expect_stat 'cache miss' 1 + rm pch.h.gch/foo + + CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -x c-header -c pch.h -o pch.h.gch/foo + expect_stat 'cache hit (direct)' 1 + expect_stat 'cache hit (preprocessed)' 0 + expect_stat 'cache miss' 1 + if [ ! -f pch.h.gch/foo ]; then + test_failed "pch.h.gch/foo missing" + fi + + backdate pch.h.gch/foo + + CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -c -include pch.h pch2.c + expect_stat 'cache hit (direct)' 1 + expect_stat 'cache hit (preprocessed)' 0 + expect_stat 'cache miss' 2 + + CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -c -include pch.h pch2.c + expect_stat 'cache hit (direct)' 2 + expect_stat 'cache hit (preprocessed)' 0 + expect_stat 'cache miss' 2 + + echo "updated" >>pch.h.gch/foo # GCC seems to cope with this... + backdate pch.h.gch/foo + + CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -c -include pch.h pch2.c + expect_stat 'cache hit (direct)' 2 + expect_stat 'cache hit (preprocessed)' 0 + expect_stat 'cache miss' 3 + + CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -c -include pch.h pch2.c + expect_stat 'cache hit (direct)' 3 + expect_stat 'cache hit (preprocessed)' 0 + expect_stat 'cache miss' 3 } pch_suite_clang() {