Imported Upstream version 3.1.11 upstream/3.1.11
authorJinWang An <jinwang.an@samsung.com>
Tue, 3 Aug 2021 07:15:54 +0000 (16:15 +0900)
committerJinWang An <jinwang.an@samsung.com>
Tue, 3 Aug 2021 07:15:54 +0000 (16:15 +0900)
16 files changed:
AUTHORS.html
INSTALL.html
LICENSE.html
MANUAL.html
NEWS.html
NEWS.txt
README.html
ccache.1
ccache.c
hashutil.c
hashutil.h
macroskip.h [new file with mode: 0644]
stats.c
test.sh
test/test_hashutil.c
version.c

index 4585f50604448479e0775295190094a5dabaebfe..6962ad84796269576384773a97482447522cc9ac 100644 (file)
@@ -734,7 +734,7 @@ asciidoc.install(2);
 <body class="article">\r
 <div id="header">\r
 <h1>ccache authors</h1>\r
-<span id="revnumber">version 3.1.10</span>\r
+<span id="revnumber">version 3.1.11</span>\r
 <div id="toc">
   <div id="toctitle">Table of Contents</div>
   <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
@@ -915,8 +915,9 @@ Yiding Jia &lt;<a href="mailto:yiding@fb.com">yiding@fb.com</a>&gt;
 <div id="footnotes"><hr /></div>\r
 <div id="footer">\r
 <div id="footer-text">\r
-Version 3.1.10<br />\r
-Last updated 2014-10-19 19:05:10 CEST\r
+Version 3.1.11<br />\r
+Last updated\r
+ 2015-03-07 16:37:34 CET\r
 </div>\r
 </div>\r
 </body>\r
index f129d6281dcf9935956f45f01a3e816892fd1bc0..b681d57179f3dd2f80a1f5d0b02ef7f700ed305f 100644 (file)
@@ -734,7 +734,7 @@ asciidoc.install(2);
 <body class="article">\r
 <div id="header">\r
 <h1>ccache installation</h1>\r
-<span id="revnumber">version 3.1.10</span>\r
+<span id="revnumber">version 3.1.11</span>\r
 <div id="toc">
   <div id="toctitle">Table of Contents</div>
   <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
@@ -843,8 +843,9 @@ above.</p></div>
 <div id="footnotes"><hr /></div>\r
 <div id="footer">\r
 <div id="footer-text">\r
-Version 3.1.10<br />\r
-Last updated 2014-10-19 19:02:09 CEST\r
+Version 3.1.11<br />\r
+Last updated\r
+ 2015-03-07 16:37:34 CET\r
 </div>\r
 </div>\r
 </body>\r
index 06a9df310f3ec130d83533c69c78de83d75481dd..14cf6f901ca04249a285aaad85a6f87ce6081430 100644 (file)
@@ -734,7 +734,7 @@ asciidoc.install(2);
 <body class="article">\r
 <div id="header">\r
 <h1>ccache copyright and license</h1>\r
-<span id="revnumber">version 3.1.10</span>\r
+<span id="revnumber">version 3.1.11</span>\r
 <div id="toc">
   <div id="toctitle">Table of Contents</div>
   <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
@@ -1210,8 +1210,9 @@ following license:</p></div>
 <div id="footnotes"><hr /></div>\r
 <div id="footer">\r
 <div id="footer-text">\r
-Version 3.1.10<br />\r
-Last updated 2014-10-19 19:02:09 CEST\r
+Version 3.1.11<br />\r
+Last updated\r
+ 2015-03-07 16:37:34 CET\r
 </div>\r
 </div>\r
 </body>\r
index 494fd8ac65c21c822c67b1fb3ef67344db08a451..b0d173b2aa9cc3bc287247364cf0b1a3785e1680 100644 (file)
@@ -734,7 +734,7 @@ asciidoc.install(2);
 <body class="article">\r
 <div id="header">\r
 <h1>CCACHE(1)</h1>\r
-<span id="revnumber">version 3.1.10</span>\r
+<span id="revnumber">version 3.1.11</span>\r
 <div id="toc">
   <div id="toctitle">Table of Contents</div>
   <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
@@ -2014,8 +2014,9 @@ maintained by Joel Rosdahl. See AUTHORS.txt or AUTHORS.html and
 <div id="footnotes"><hr /></div>\r
 <div id="footer">\r
 <div id="footer-text">\r
-Version 3.1.10<br />\r
-Last updated 2014-10-19 19:02:09 CEST\r
+Version 3.1.11<br />\r
+Last updated\r
+ 2015-03-07 16:37:34 CET\r
 </div>\r
 </div>\r
 </body>\r
index 98d86bd2720cc792cc5ebac7010f46610aba335e..5e972f39f93957e4f123295625b08f35e77b1e05 100644 (file)
--- a/NEWS.html
+++ b/NEWS.html
@@ -734,7 +734,7 @@ asciidoc.install(2);
 <body class="article">\r
 <div id="header">\r
 <h1>ccache news</h1>\r
-<span id="revnumber">version 3.1.10</span>\r
+<span id="revnumber">version 3.1.11</span>\r
 <div id="toc">
   <div id="toctitle">Table of Contents</div>
   <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
@@ -742,6 +742,37 @@ asciidoc.install(2);
 </div>\r
 <div id="content">\r
 <div class="sect1">\r
+<h2 id="_ccache_3_1_11">ccache 3.1.11</h2>\r
+<div class="sectionbody">\r
+<div class="paragraph"><p>Release date: 2015-03-07</p></div>\r
+<div class="sect2">\r
+<h3 id="_bug_fixes">Bug fixes</h3>\r
+<div class="ulist"><ul>\r
+<li>\r
+<p>\r
+Fixed bug which could result in false cache hits when source code contains\r
+  <code>'"'</code> followed by <code>" /*"</code> or <code>" //"</code> (with variations).\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Made hash of cached result created with and without <code>CCACHE_CPP2</code> different.\r
+  This makes it possible to rebuild with <code>CCACHE_CPP2</code> set without having to\r
+  clear the cache to get new results.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Don&#8217;t try to reset a non-existing stats file. This avoids &#8220;No such file or\r
+  directory&#8221; messages in the ccache log when the cache directory doesn&#8217;t\r
+  exist.\r
+</p>\r
+</li>\r
+</ul></div>\r
+</div>\r
+</div>\r
+</div>\r
+<div class="sect1">\r
 <h2 id="_ccache_3_1_10">ccache 3.1.10</h2>\r
 <div class="sectionbody">\r
 <div class="paragraph"><p>Release date: 2014-10-19</p></div>\r
@@ -785,7 +816,7 @@ Added note in documentation that <code>--ccache-skip</code> currently does not m
 <p>\r
 To enable support for precompiled headers (PCH), <code>CCACHE_SLOPPINESS</code> now also\r
   needs to include the new <code>pch_defines</code> sloppiness. This is because ccache\r
-  can&#8217;t detect changes in the source code when only `#define`s have been\r
+  can&#8217;t detect changes in the source code when only defined macros have been\r
   changed.\r
 </p>\r
 </li>\r
@@ -798,7 +829,7 @@ Stale files in the internal temporary directory (<code>&lt;ccache_dir&gt;/tmp</c
 </ul></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes">Bug fixes</h3>\r
+<h3 id="_bug_fixes_2">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -838,7 +869,7 @@ Fixed problem with logging of current working directory.
 <div class="sectionbody">\r
 <div class="paragraph"><p>Release date: 2013-01-06</p></div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_2">Bug fixes</h3>\r
+<h3 id="_bug_fixes_3">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -909,7 +940,7 @@ Clang plugins are now hashed to catch plugin upgrades.
 </ul></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_3">Bug fixes</h3>\r
+<h3 id="_bug_fixes_4">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -957,7 +988,7 @@ Fixed <code>static_assert</code> macro definition clash with GCC 4.7.
 <div class="sectionbody">\r
 <div class="paragraph"><p>Release date: 2012-01-08</p></div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_4">Bug fixes</h3>\r
+<h3 id="_bug_fixes_5">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -1040,7 +1071,7 @@ Rewrite argument to <code>--sysroot</code> if <code>CCACHE_BASEDIR</code> is use
 </ul></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_5">Bug fixes</h3>\r
+<h3 id="_bug_fixes_6">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -1093,7 +1124,7 @@ Improved order of statistics counters in <code>ccache -s</code> output.
 </ul></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_6">Bug fixes</h3>\r
+<h3 id="_bug_fixes_7">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -1126,7 +1157,7 @@ Systems that lack (and don&#8217;t need to be linked with) libm are now supporte
 <div class="sectionbody">\r
 <div class="paragraph"><p>Release date: 2011-01-09</p></div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_7">Bug fixes</h3>\r
+<h3 id="_bug_fixes_8">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -1159,7 +1190,7 @@ The file handle in now correctly closed on write error when trying to create
 <div class="sectionbody">\r
 <div class="paragraph"><p>Release date: 2010-11-28</p></div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_8">Bug fixes</h3>\r
+<h3 id="_bug_fixes_9">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -1186,7 +1217,7 @@ Portability fixes for HP-UX 11.00 and other esoteric systems.
 <div class="sectionbody">\r
 <div class="paragraph"><p>Release date: 2010-11-21</p></div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_9">Bug fixes</h3>\r
+<h3 id="_bug_fixes_10">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -1234,7 +1265,7 @@ The test suite now also works on systems that lack a /dev/zero.
 <div class="sectionbody">\r
 <div class="paragraph"><p>Release date: 2010-11-07</p></div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_10">Bug fixes</h3>\r
+<h3 id="_bug_fixes_11">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -1356,7 +1387,7 @@ Added <code>-install_name</code> as an option known to take an argument. (This i
 </ul></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_11">Bug fixes</h3>\r
+<h3 id="_bug_fixes_12">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -1442,7 +1473,7 @@ New <code>HACKING.txt</code> file with some notes about ccache code conventions.
 <div class="sectionbody">\r
 <div class="paragraph"><p>Release date: 2010-07-15</p></div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_12">Bug fixes</h3>\r
+<h3 id="_bug_fixes_13">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -1631,7 +1662,7 @@ The following options are no longer hashed in the preprocessor mode:
 </ul></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_bug_fixes_13">Bug fixes</h3>\r
+<h3 id="_bug_fixes_14">Bug fixes</h3>\r
 <div class="ulist"><ul>\r
 <li>\r
 <p>\r
@@ -1776,8 +1807,9 @@ Statistics counters are now correctly updated for -E option failures and
 <div id="footnotes"><hr /></div>\r
 <div id="footer">\r
 <div id="footer-text">\r
-Version 3.1.10<br />\r
-Last updated 2014-10-19 19:03:56 CEST\r
+Version 3.1.11<br />\r
+Last updated\r
+ 2015-03-07 16:37:34 CET\r
 </div>\r
 </div>\r
 </body>\r
index 063cdc28c45fad0ab2efccbf9adaecc0bea556c2..849a10f1146f826365e99cb98a5274ee347d9db8 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -2,6 +2,26 @@ ccache news
 ===========
 
 
+ccache 3.1.11
+-------------
+Release date: 2015-03-07
+
+
+Bug fixes
+~~~~~~~~~
+
+- Fixed bug which could result in false cache hits when source code contains
+  `'"'` followed by `" /*"` or `" //"` (with variations).
+
+- Made hash of cached result created with and without `CCACHE_CPP2` different.
+  This makes it possible to rebuild with `CCACHE_CPP2` set without having to
+  clear the cache to get new results.
+
+- Don't try to reset a non-existing stats file. This avoids ``No such file or
+  directory'' messages in the ccache log when the cache directory doesn't
+  exist.
+
+
 ccache 3.1.10
 -------------
 Release date: 2014-10-19
@@ -27,7 +47,7 @@ New features and improvements
 
 - To enable support for precompiled headers (PCH), `CCACHE_SLOPPINESS` now also
   needs to include the new `pch_defines` sloppiness. This is because ccache
-  can't detect changes in the source code when only `#define`s have been
+  can't detect changes in the source code when only defined macros have been
   changed.
 
 - Stale files in the internal temporary directory (`<ccache_dir>/tmp`) are now
index 00bd6f67204785dd3e2e683c9483bb297cdf1cc6..7c5d01fc264b041046e43460a534115feb7913d4 100644 (file)
@@ -734,7 +734,7 @@ asciidoc.install(2);
 <body class="article">\r
 <div id="header">\r
 <h1>ccache README</h1>\r
-<span id="revnumber">version 3.1.10</span>\r
+<span id="revnumber">version 3.1.11</span>\r
 <div id="toc">
   <div id="toctitle">Table of Contents</div>
   <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
@@ -830,8 +830,9 @@ Thiele&#8217;s &#8220;compilercache&#8221; (see <a href="http://www.erikyyy.de/c
 <div id="footnotes"><hr /></div>\r
 <div id="footer">\r
 <div id="footer-text">\r
-Version 3.1.10<br />\r
-Last updated 2012-11-07 19:42:42 CET\r
+Version 3.1.11<br />\r
+Last updated\r
+ 2012-11-07 19:42:42 CET\r
 </div>\r
 </div>\r
 </body>\r
index 7c6af37dc8112e253df334729adeeb9e62819ce7..5d1f8bac4e46cc18d17e6d0d857d6c097189b9d5 100644 (file)
--- a/ccache.1
+++ b/ccache.1
@@ -2,12 +2,12 @@
 .\"     Title: ccache
 .\"    Author: [see the "Author" section]
 .\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
-.\"      Date: 10/19/2014
+.\"      Date: 03/07/2015
 .\"    Manual: ccache Manual
-.\"    Source: ccache 3.1.10
+.\"    Source: ccache 3.1.11
 .\"  Language: English
 .\"
-.TH "CCACHE" "1" "10/19/2014" "ccache 3\&.1\&.10" "ccache Manual"
+.TH "CCACHE" "1" "03/07/2015" "ccache 3\&.1\&.11" "ccache Manual"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
index f0dca22c7fc76b76ba716c3268241b328c6de5ef..1f182630d1b9f7bc26c844df0794f546963e4480 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -2,7 +2,7 @@
  * ccache -- a fast C/C++ compiler cache
  *
  * Copyright (C) 2002-2007 Andrew Tridgell
- * Copyright (C) 2009-2014 Joel Rosdahl
+ * Copyright (C) 2009-2015 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
@@ -36,7 +36,7 @@ static const char VERSION_TEXT[] =
 MYNAME " version %s\n"
 "\n"
 "Copyright (C) 2002-2007 Andrew Tridgell\n"
-"Copyright (C) 2009-2011 Joel Rosdahl\n"
+"Copyright (C) 2009-2015 Joel Rosdahl\n"
 "\n"
 "This program is free software; you can redistribute it and/or modify it under\n"
 "the terms of the GNU General Public License as published by the Free Software\n"
@@ -878,6 +878,8 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash)
                 */
                cpp_stderr = path_stderr;
        } else {
+               hash_delimiter(hash, "runsecondcpp");
+               hash_string(hash, "false");
                free(path_stderr);
        }
 
index 6cc9e6cb7adc4a5f417f39c7e4a354e95e7a267e..1ead7680e0c439c463e0514aad68c70b3d871b3f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2010, 2012 Joel Rosdahl
+ * Copyright (C) 2009-2015 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
@@ -18,6 +18,7 @@
 
 #include "ccache.h"
 #include "hashutil.h"
+#include "macroskip.h"
 #include "murmurhashneutral2.h"
 
 unsigned
@@ -56,124 +57,82 @@ file_hashes_equal(struct file_hash *fh1, struct file_hash *fh2)
        } while (0)
 
 /*
- * Hash a string ignoring comments. Returns a bitmask of HASH_SOURCE_CODE_*
- * results.
+ * Search for the strings "__DATE__" and "__TIME__" in str.
+ *
+ * Returns a bitmask with HASH_SOURCE_CODE_FOUND_DATE and
+ * HASH_SOURCE_CODE_FOUND_TIME set appropriately.
  */
 int
-hash_source_code_string(
-       struct mdfour *hash, const char *str, size_t len, const char *path)
+check_for_temporal_macros(const char *str, size_t len)
 {
-       const char *p;
-       const char *end;
-       char hashbuf[64];
-       size_t hashbuflen = 0;
-       int result = HASH_SOURCE_CODE_OK;
-       extern unsigned sloppiness;
-       bool seen_backslash;
+       int result = 0;
 
-       p = str;
-       end = str + len;
-       while (1) {
-               if (p >= end) {
-                       goto end;
-               }
-               switch (*p) {
-               /* Potential start of comment. */
-               case '/':
-                       if (p+1 == end) {
-                               break;
-                       }
-                       switch (*(p+1)) {
-                       case '*':
-                               HASH(' '); /* Don't paste tokens together when removing the comment. */
-                               p += 2;
-                               while (p+1 < end && (*p != '*' || *(p+1) != '/')) {
-                                       if (*p == '\n') {
-                                               /* Keep line numbers. */
-                                               HASH('\n');
-                                       }
-                                       p++;
-                               }
-                               if (p+1 == end) {
-                                       goto end;
-                               }
-                               p += 2;
-                               continue;
+       /*
+        * We're using the Boyer-Moore-Horspool algorithm, which searches starting
+        * from the *end* of the needle. Our needles are 8 characters long, so i
+        * starts at 7.
+        */
+       size_t i = 7;
 
-                       case '/':
-                               p += 2;
-                               while (p < end && (*p != '\n' || *(p-1) == '\\')) {
-                                       p++;
-                               }
-                               continue;
-
-                       default:
-                               break;
-                       }
-                       break;
-
-               /* Start of string. */
-               case '"':
-                       HASH(*p);
-                       p++;
-                       seen_backslash = false;
-                       while (p < end) {
-                               if (seen_backslash) {
-                                       seen_backslash = false;
-                               } else if (*p == '"') {
-                                       /* Found end of string. */
-                                       HASH(*p);
-                                       p++;
-                                       break;
-                               } else if (*p == '\\') {
-                                       seen_backslash = true;
-                               }
-                               HASH(*p);
-                               p++;
-                       }
-                       if (p == end) {
-                               goto end;
+       while (i < len) {
+               /*
+                * Check whether the substring ending at str[i] has the form "__...E__". On
+                * the assumption that 'E' is less common in source than '_', we check
+                * str[i-2] first.
+                */
+               if (str[i - 2] == 'E' &&
+                   str[i - 0] == '_' &&
+                   str[i - 7] == '_' &&
+                   str[i - 1] == '_' &&
+                   str[i - 6] == '_') {
+                       /*
+                        * Check the remaining characters to see if the substring is "__DATE__"
+                        * or "__TIME__".
+                        */
+                       if (str[i - 5] == 'D' && str[i - 4] == 'A' &&
+                           str[i - 3] == 'T') {
+                               result |= HASH_SOURCE_CODE_FOUND_DATE;
                        }
-                       break;
-
-               /* Potential start of volatile macro. */
-               case '_':
-                       if (p + 7 < end
-                           && p[1] == '_' && p[5] == 'E'
-                           && p[6] == '_' && p[7] == '_') {
-                               if (p[2] == 'D' && p[3] == 'A'
-                                   && p[4] == 'T') {
-                                       result |= HASH_SOURCE_CODE_FOUND_DATE;
-                               } else if (p[2] == 'T' && p[3] == 'I'
-                                          && p[4] == 'M') {
-                                       result |= HASH_SOURCE_CODE_FOUND_TIME;
-                               }
-                               /*
-                                * Of course, we can't be sure that we have found a __{DATE,TIME}__
-                                * that's actually used, but better safe than sorry. And if you do
-                                * something like
-                                *
-                                * #define TIME __TI ## ME__
-                                *
-                                * in your code, you deserve to get a false cache hit.
-                                */
+                       else if (str[i - 5] == 'T' && str[i - 4] == 'I' &&
+                                str[i - 3] == 'M') {
+                               result |= HASH_SOURCE_CODE_FOUND_TIME;
                        }
-                       break;
-
-               default:
-                       break;
                }
 
-               HASH(*p);
-               p++;
+               /*
+                * macro_skip tells us how far we can skip forward upon seeing str[i] at
+                * the end of a substring.
+                */
+               i += macro_skip[(uint8_t)str[i]];
        }
 
-end:
-       hash_buffer(hash, hashbuf, hashbuflen);
+       return result;
+}
 
-       if (sloppiness & SLOPPY_TIME_MACROS) {
-               return 0;
+/*
+ * Hash a string ignoring comments. Returns a bitmask of HASH_SOURCE_CODE_*
+ * results.
+ */
+int
+hash_source_code_string(
+       struct mdfour *hash, const char *str, size_t len, const char *path)
+{
+       int result = HASH_SOURCE_CODE_OK;
+       extern unsigned sloppiness;
+
+       /*
+        * Check for __DATE__ and __TIME__ if the sloppiness configuration tells us
+        * we should.
+        */
+       if (!(sloppiness & SLOPPY_TIME_MACROS)) {
+               result |= check_for_temporal_macros(str, len);
        }
+
+       /*
+        * Hash the source string.
+        */
+       hash_buffer(hash, str, len);
+
        if (result & HASH_SOURCE_CODE_FOUND_DATE) {
                /*
                 * Make sure that the hash sum changes if the (potential) expansion of
index a897b3e12dff3a96c05fce9b17d9be92f048457c..ec4e059fdac9876a6a431041f84a8e2b4d7aed25 100644 (file)
@@ -20,6 +20,7 @@ int file_hashes_equal(struct file_hash *fh1, struct file_hash *fh2);
 #define        HASH_SOURCE_CODE_FOUND_DATE 2
 #define        HASH_SOURCE_CODE_FOUND_TIME 4
 
+int check_for_temporal_macros(const char *str, size_t len);
 int hash_source_code_string(
        struct mdfour *hash, const char *str, size_t len, const char *path);
 int hash_source_code_file(struct mdfour *hash, const char *path);
diff --git a/macroskip.h b/macroskip.h
new file mode 100644 (file)
index 0000000..cb32ec4
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * A Boyer-Moore-Horspool skip table used for searching for the strings
+ * "__TIME__" and "__DATE__".
+ *
+ * macro_skip[c] = 8 for all c not in "__TIME__" and "__DATE__".
+ *
+ * The other characters map as follows:
+ *
+ *   _ -> 1
+ *   A -> 4
+ *   D -> 5
+ *   E -> 2
+ *   I -> 4
+ *   M -> 3
+ *   T -> 3
+ *
+ *
+ * This was generated with the following Python script:
+ *
+ * m = {'_': 1,
+ *      'A': 4,
+ *      'D': 5,
+ *      'E': 2,
+ *      'I': 4,
+ *      'M': 3,
+ *      'T': 3}
+ *
+ * for i in range(0, 256):
+ *     if chr(i) in m:
+ *         num = m[chr(i)]
+ *     else:
+ *         num = 8
+ *     print ("%d, " % num),
+ *
+ *     if i % 16 == 15:
+ *         print ""
+ */
+
+static const uint32_t macro_skip[] = {
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  4,  8,  8,  5,  2,  8,  8,  8,  4,  8,  8,  8,  3,  8,  8,
+       8,  8,  8,  8,  3,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  1,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+       8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+};
diff --git a/stats.c b/stats.c
index d7321265ce6952fc08196cbf9746a17ac010e92e..003a55450445b63d36c8a8c7cdfef4dbdd2d859f 100644 (file)
--- a/stats.c
+++ b/stats.c
@@ -347,7 +347,13 @@ stats_zero(void)
 
        for (dir = 0; dir <= 0xF; dir++) {
                struct counters *counters = counters_init(STATS_END);
+               struct stat st;
                fname = format("%s/%1x/stats", cache_dir, dir);
+               if (stat(fname, &st) != 0) {
+                       /* No point in trying to reset the stats file if it doesn't exist. */
+                       free(fname);
+                       continue;
+               }
                if (lockfile_acquire(fname, lock_staleness_limit)) {
                        stats_read(fname, counters);
                        for (i = 0; stats_info[i].message; i++) {
diff --git a/test.sh b/test.sh
index 4cad450d2c2727add3c68c4fd61e77cf01fe751e..5efbca4f78b6e2a8e122c1694c72101df019c96e 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-2014 Joel Rosdahl
+# Copyright (C) 2009-2015 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
@@ -219,7 +219,7 @@ base_tests() {
     mv $CCACHE_DIR $CCACHE_DIR.saved
     CCACHE_DISABLE=1 $CCACHE_COMPILE -c test1.c 2> /dev/null
     if [ -d $CCACHE_DIR ]; then
-        test_failed "$CCACHE_DIR created dispite CCACHE_DISABLE being set"
+        test_failed "$CCACHE_DIR created despite CCACHE_DISABLE being set"
     fi
     mv $CCACHE_DIR.saved $CCACHE_DIR
     checkstat 'cache hit (preprocessed)' 3
@@ -245,10 +245,10 @@ base_tests() {
     checkstat 'cache hit (preprocessed)' 5
     checkstat 'cache miss' 4
 
-    # strictly speaking should be 3 - RECACHE causes a double counting!
+    # strictly speaking should be 4 - RECACHE causes a double counting!
     checkstat 'files in cache' 4
     $CCACHE -c > /dev/null
-    checkstat 'files in cache' 3
+    checkstat 'files in cache' 4
 
     testname="CCACHE_HASHDIR"
     CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -O
@@ -258,7 +258,7 @@ base_tests() {
     CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -O
     checkstat 'cache hit (preprocessed)' 6
     checkstat 'cache miss' 5
-    checkstat 'files in cache' 4
+    checkstat 'files in cache' 5
 
     testname="comments"
     echo '/* a silly comment */' > test1-comment.c
@@ -286,7 +286,7 @@ base_tests() {
     done
     checkstat 'cache hit (preprocessed)' 8
     checkstat 'cache miss' 37
-    checkstat 'files in cache' 36
+    checkstat 'files in cache' 37
 
     $CCACHE -C >/dev/null
 
@@ -344,9 +344,15 @@ base_tests() {
             CCACHE_CPP2=1 $CCACHE_COMPILE -c -finput-charset=latin1 latin1.c
             checkstat 'cache hit (preprocessed)' 14
             checkstat 'cache miss' 40
-            $CCACHE_COMPILE -c -finput-charset=latin1 latin1.c
+            CCACHE_CPP2=1 $CCACHE_COMPILE -c -finput-charset=latin1 latin1.c
             checkstat 'cache hit (preprocessed)' 15
             checkstat 'cache miss' 40
+            $CCACHE_COMPILE -c -finput-charset=latin1 latin1.c
+            checkstat 'cache hit (preprocessed)' 15
+            checkstat 'cache miss' 41
+            $CCACHE_COMPILE -c -finput-charset=latin1 latin1.c
+            checkstat 'cache hit (preprocessed)' 16
+            checkstat 'cache miss' 41
         fi
     fi
 
@@ -897,45 +903,6 @@ EOF
     checkstat 'cache miss' 1
     checkfile stderr-mf.txt "`cat stderr-orig.txt`"
 
-    ##################################################################
-    # Check that changes in comments are ignored when hashing.
-    testname="changes in comments"
-    $CCACHE -C >/dev/null
-    $CCACHE -z >/dev/null
-    cat <<EOF >comments.h
-/*
- * /* foo comment
- */
-EOF
-    backdate comments.h
-    cat <<'EOF' >comments.c
-#include "comments.h"
-char test[] = "\
-/* apple */ // banana"; // foo comment
-EOF
-
-    $CCACHE $COMPILER -c comments.c
-    checkstat 'cache hit (direct)' 0
-    checkstat 'cache hit (preprocessed)' 0
-    checkstat 'cache miss' 1
-
-    sed_in_place 's/foo/ignored/' comments.h comments.c
-    backdate comments.h
-
-    $CCACHE $COMPILER -c comments.c
-    checkstat 'cache hit (direct)' 1
-    checkstat 'cache hit (preprocessed)' 0
-    checkstat 'cache miss' 1
-
-    # Check that comment-like string contents are hashed.
-    sed_in_place 's/apple/orange/' comments.c
-    backdate comments.h
-
-    $CCACHE $COMPILER -c comments.c
-    checkstat 'cache hit (direct)' 1
-    checkstat 'cache hit (preprocessed)' 0
-    checkstat 'cache miss' 2
-
     ##################################################################
     # Check that it's possible to compile and cache an empty source code file.
     testname="empty source file"
@@ -1203,6 +1170,23 @@ EOF
     checkstat 'cache hit (direct)' 2
     checkstat 'cache hit (preprocessed)' 0
     checkstat 'cache miss' 2
+
+    testname="comment in strings"
+    $CCACHE -Cz >/dev/null
+    echo 'char *comment = " /* \\\\u" "foo" " */";' >comment.c
+    $CCACHE $COMPILER -c comment.c
+    checkstat 'cache hit (direct)' 0
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 1
+    $CCACHE $COMPILER -c comment.c
+    checkstat 'cache hit (direct)' 1
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 1
+    echo 'char *comment = " /* \\\\u" "goo" " */";' >comment.c
+    $CCACHE $COMPILER -c comment.c
+    checkstat 'cache hit (direct)' 1
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 2
 }
 
 basedir_suite() {
@@ -1892,7 +1876,6 @@ all_suites="
 base
 link          !win32
 hardlink
-cpp2
 nlevels4
 nlevels1
 basedir       !win32
index 6ee9d4b8286d3f49b84598349b6840d629883df4..243af69af1651ec6f9a40f1eb39df71250220f10 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010, 2012 Joel Rosdahl
+ * Copyright (C) 2010-2015 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
@@ -109,83 +109,82 @@ TEST(hash_source_code_simple_case)
        CHECK_STR_EQ_FREE2("a448017aaf21d8525fc10ae87aa6729d-3", hash_result(&h));
 }
 
-TEST(hash_source_code_with_c_style_comment)
+TEST(check_for_temporal_macros)
 {
-       struct mdfour h;
-       char input[] = "a/*b*/c";
-       size_t input_len = strlen(input);
-
-       hash_start(&h);
-       hash_source_code_string(&h, input, input_len, "");
-       CHECK_STR_EQ_FREE2("1c2c87080ee03418fb1279e3b1f09a68-3", hash_result(&h));
-
-       input[3] = 'd';
-       hash_start(&h);
-       hash_source_code_string(&h, input, input_len, "");
-       CHECK_STR_EQ_FREE2("1c2c87080ee03418fb1279e3b1f09a68-3", hash_result(&h));
-}
-
-TEST(hash_source_code_with_cplusplus_style_comment)
-{
-       struct mdfour h;
-       char input[] = "a//b\nc";
-       size_t input_len = strlen(input);
-
-       hash_start(&h);
-       hash_source_code_string(&h, input, input_len, "");
-       CHECK_STR_EQ_FREE2("4a3fbbe3c140fa193227dba3814db6e6-3", hash_result(&h));
-
-       input[3] = 'd';
-       hash_start(&h);
-       hash_source_code_string(&h, input, input_len, "");
-       CHECK_STR_EQ_FREE2("4a3fbbe3c140fa193227dba3814db6e6-3", hash_result(&h));
-}
-
-TEST(hash_source_code_with_comment_inside_string)
-{
-       struct mdfour h;
-       char input[] = "a\"//b\"c";
-       size_t input_len = strlen(input);
-
-       hash_start(&h);
-       hash_source_code_string(&h, input, input_len, "");
-       CHECK_STR_EQ_FREE2("4c2fa74b0843d8f93df5c04c98ccb0a4-7", hash_result(&h));
-
-       input[4] = 'd';
-       hash_start(&h);
-       hash_source_code_string(&h, input, input_len, "");
-       CHECK_STR_EQ_FREE2("f0069218ec640008cbfa2d150c1061bb-7", hash_result(&h));
-}
-
-TEST(hash_source_code_with_quote_in_string)
-{
-       struct mdfour h;
-       char input[] = "a\"\\\"b//c\""; /* a"\"b//c" */
-       size_t input_len = strlen(input);
-
-       hash_start(&h);
-       hash_source_code_string(&h, input, input_len, "");
-       CHECK_STR_EQ_FREE2("c4e45e7a7f6f29b000a51f187dc4cf06-9", hash_result(&h));
-
-       hash_start(&h);
-       input[7] = 'd';
-       hash_source_code_string(&h, input, input_len, "");
-       CHECK_STR_EQ_FREE2("bef8fb852dddcee189b91b068a621c55-9", hash_result(&h));
-}
-
-TEST(hash_source_code_with_backslash_at_string_end)
-{
-       struct mdfour h;
-       char input[] = "a\"\\\\\"b//c"; /* a"\\"b//c */
-       size_t input_len = strlen(input);
-
-       hash_start(&h);
-       hash_source_code_string(&h, input, input_len, "");
-       CHECK_STR_EQ_FREE2("7f3ccf27edadad1b90cb2cffb59775d6-6", hash_result(&h));
-
-       input[input_len - 1] = 'd';
-       hash_source_code_string(&h, input, input_len, "");
-       CHECK_STR_EQ_FREE2("7f3ccf27edadad1b90cb2cffb59775d6-6", hash_result(&h));
+       const char time_start[] =
+               "__TIME__\n"
+               "int a;\n";
+       const char time_middle[] =
+               "#define a __TIME__\n"
+               "int a;\n";
+       const char time_end[] =
+               "#define a __TIME__";
+
+       const char date_start[] =
+               "__DATE__\n"
+               "int ab;\n";
+       const char date_middle[] =
+               "#define ab __DATE__\n"
+               "int ab;\n";
+       const char date_end[] =
+               "#define ab __DATE__";
+
+       const char no_temporal[] =
+               "#define ab _ _DATE__\n"
+               "#define ab __ DATE__\n"
+               "#define ab __D ATE__\n"
+               "#define ab __DA TE__\n"
+               "#define ab __DAT E__\n"
+               "#define ab __DATE __\n"
+               "#define ab __DATE_ _\n"
+               "#define ab _ _TIME__\n"
+               "#define ab __ TIME__\n"
+               "#define ab __T IME__\n"
+               "#define ab __TI ME__\n"
+               "#define ab __TIM E__\n"
+               "#define ab __TIME __\n"
+               "#define ab __TIME_ _\n";
+
+       CHECK(check_for_temporal_macros(time_start + 0, sizeof(time_start) - 0));
+       CHECK(!check_for_temporal_macros(time_start + 1, sizeof(time_start) - 1));
+
+       CHECK(check_for_temporal_macros(time_middle + 0, sizeof(time_middle) - 0));
+       CHECK(check_for_temporal_macros(time_middle + 1, sizeof(time_middle) - 1));
+       CHECK(check_for_temporal_macros(time_middle + 2, sizeof(time_middle) - 2));
+       CHECK(check_for_temporal_macros(time_middle + 3, sizeof(time_middle) - 3));
+       CHECK(check_for_temporal_macros(time_middle + 4, sizeof(time_middle) - 4));
+       CHECK(check_for_temporal_macros(time_middle + 5, sizeof(time_middle) - 5));
+       CHECK(check_for_temporal_macros(time_middle + 6, sizeof(time_middle) - 6));
+       CHECK(check_for_temporal_macros(time_middle + 7, sizeof(time_middle) - 7));
+
+       CHECK(check_for_temporal_macros(time_end + 0, sizeof(time_end) - 0));
+       CHECK(check_for_temporal_macros(time_end + sizeof(time_end) - 9, 9));
+       CHECK(!check_for_temporal_macros(time_end + sizeof(time_end) - 8, 8));
+
+       CHECK(check_for_temporal_macros(date_start + 0, sizeof(date_start) - 0));
+       CHECK(!check_for_temporal_macros(date_start + 1, sizeof(date_start) - 1));
+
+       CHECK(check_for_temporal_macros(date_middle + 0, sizeof(date_middle) - 0));
+       CHECK(check_for_temporal_macros(date_middle + 1, sizeof(date_middle) - 1));
+       CHECK(check_for_temporal_macros(date_middle + 2, sizeof(date_middle) - 2));
+       CHECK(check_for_temporal_macros(date_middle + 3, sizeof(date_middle) - 3));
+       CHECK(check_for_temporal_macros(date_middle + 4, sizeof(date_middle) - 4));
+       CHECK(check_for_temporal_macros(date_middle + 5, sizeof(date_middle) - 5));
+       CHECK(check_for_temporal_macros(date_middle + 6, sizeof(date_middle) - 6));
+       CHECK(check_for_temporal_macros(date_middle + 7, sizeof(date_middle) - 7));
+
+       CHECK(check_for_temporal_macros(date_end + 0, sizeof(date_end) - 0));
+       CHECK(check_for_temporal_macros(date_end + sizeof(date_end) - 9, 9));
+       CHECK(!check_for_temporal_macros(date_end + sizeof(date_end) - 8, 8));
+
+       CHECK(!check_for_temporal_macros(no_temporal + 0, sizeof(no_temporal) - 0));
+       CHECK(!check_for_temporal_macros(no_temporal + 1, sizeof(no_temporal) - 1));
+       CHECK(!check_for_temporal_macros(no_temporal + 2, sizeof(no_temporal) - 2));
+       CHECK(!check_for_temporal_macros(no_temporal + 3, sizeof(no_temporal) - 3));
+       CHECK(!check_for_temporal_macros(no_temporal + 4, sizeof(no_temporal) - 4));
+       CHECK(!check_for_temporal_macros(no_temporal + 5, sizeof(no_temporal) - 5));
+       CHECK(!check_for_temporal_macros(no_temporal + 6, sizeof(no_temporal) - 6));
+       CHECK(!check_for_temporal_macros(no_temporal + 7, sizeof(no_temporal) - 7));
 }
 
 TEST_SUITE_END
index beda7f9d7c1d8830eb7ee5358d0ed8d52af82083..c597956cd9961c8010c55b5fe0ae430fb7338a7e 100644 (file)
--- a/version.c
+++ b/version.c
@@ -1 +1 @@
-const char CCACHE_VERSION[] = "3.1.10";
+const char CCACHE_VERSION[] = "3.1.11";