]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Make calculate_object_hash handle argument-less -B etc. correctly
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 16 Jul 2016 18:04:37 +0000 (20:04 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 16 Jul 2016 18:17:39 +0000 (20:17 +0200)
Fixes issue #112.

NEWS.txt
ccache.c
compopt.c
test.sh

index 4b2d14421b34a36f9cc9fa5e68f91b732e577199..cfbfdf44c44cf3262bc1520d52fce6ba9862aeb8 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -2,6 +2,16 @@ ccache news
 ===========
 
 
+Unreleased ccache 3.2.7
+-----------------------
+
+Bug fixes
+~~~~~~~~~
+
+- Fixed a bug which could lead to false cache hits for compiler command lines
+  with a missing argument to an option that takes an argument.
+
+
 ccache 3.2.6
 ------------
 Release date: 2016-07-12
index 014c5a0d7886984f58d39d6639ba8ca797bc13f2..624036c85feec3d31ac01d2fa22a2e55b3b6f725 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -1623,6 +1623,11 @@ calculate_object_hash(struct args *args, struct mdfour *hash, int direct_mode)
                /* All other arguments are included in the hash. */
                hash_delimiter(hash, "arg");
                hash_string(hash, args->argv[i]);
+               if (i + 1 < args->argc && compopt_takes_arg(args->argv[i])) {
+                       i++;
+                       hash_delimiter(hash, "arg");
+                       hash_string(hash, args->argv[i]);
+               }
        }
 
        /*
index 1b8dc7055467af0be27ded2b5a34e269abc19d9c..78d646719fb9151463230e73eafc276be797a39d 100644 (file)
--- a/compopt.c
+++ b/compopt.c
@@ -36,6 +36,7 @@ static const struct compopt compopts[] = {
        {"--save-temps",    TOO_HARD},
        {"--serialize-diagnostics", TAKES_ARG | TAKES_PATH},
        {"-A",              TAKES_ARG},
+       {"-B",              TAKES_ARG | TAKES_CONCAT_ARG},
        {"-D",              AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG},
        {"-E",              TOO_HARD},
        {"-F",              AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
diff --git a/test.sh b/test.sh
index 27895a9a5c2b07731bb20a3e5fa495f7e6a4189a..2f3a45af2e459b96e779bf4102ebdaca95b00ac0 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -1477,6 +1477,27 @@ EOF
     else
         test_failed "unexpected output of --dump-manifest"
     fi
+
+    ##################################################################
+    testname="argument-less -B and -L"
+    $CCACHE -Cz > /dev/null
+    cat <<EOF >test.c
+#include <stdio.h>
+int main(void)
+{
+#ifdef FOO
+    puts("FOO");
+#endif
+    return 0;
+}
+EOF
+
+    $CCACHE $COMPILER -A -L -DFOO -c test.c
+    checkstat 'cache hit (direct)' 0
+    checkstat 'cache miss' 1
+    $CCACHE $COMPILER -A -L -DBAR -c test.c
+    checkstat 'cache hit (direct)' 0
+    checkstat 'cache miss' 2
 }
 
 basedir_suite() {