]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Avoid false positive cache hits for __asm__(".incbin" " \"file\"")
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 19 Jul 2022 07:52:00 +0000 (09:52 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 19 Jul 2022 08:13:18 +0000 (10:13 +0200)
Regression in #983.

Fixes #1120.

src/ccache.cpp
test/suites/base.bash

index 1bc23430d27d33f2c7a0b8a8630fe18551b9b848..f494378514a640589861879ed4b5267a5212d99e 100644 (file)
@@ -479,8 +479,7 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
       "# 32 \"<command-line>\" 2\n";
     // Note: Intentionally not using the string form to avoid false positive
     // match by ccache itself.
-    static const char incbin_prefix[] = {
-      '.', 'i', 'n', 'c', 'b', 'i', 'n', ' '};
+    static const char incbin_directive[] = {'.', 'i', 'n', 'c', 'b', 'i', 'n'};
 
     // Check if we look at a line containing the file name of an included file.
     // At least the following formats exist (where N is a positive integer):
@@ -584,14 +583,16 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
           Statistic::could_not_use_precompiled_header);
       }
       p = q; // Everything of interest between p and q has been hashed now.
-    } else if (strncmp(q, incbin_prefix, sizeof(incbin_prefix)) == 0
-               && (q[8] == '"' || (q[8] == '\\' && q[9] == '"'))) {
+    } else if (strncmp(q, incbin_directive, sizeof(incbin_directive)) == 0
+               && ((q[7] == ' '
+                    && (q[8] == '"' || (q[8] == '\\' && q[9] == '"')))
+                   || q[7] == '"')) {
       // An assembler .inc bin (without the space) statement, which could be
       // part of inline assembly, refers to an external file. If the file
       // changes, the hash should change as well, but finding out what file to
       // hash is too hard for ccache, so just bail out.
       LOG_RAW(
-        "Found unsupported .inc"
+        "Found potential unsupported .inc"
         "bin directive in source code");
       return nonstd::make_unexpected(
         Failure(Statistic::unsupported_code_directive));
index bb0644a62ebc3455b368b92e57900c9e65422974..5cbef4c37c207cea3fbf4d1316a23785a838246b 100644 (file)
@@ -1492,6 +1492,15 @@ EOF
     expect_stat cache_miss 0
     expect_stat unsupported_code_directive 1
 
+    cat <<EOF >incbin.c
+__asm__(".incbin" " \"empty.bin\"");
+EOF
+
+    $CCACHE_COMPILE -c incbin.c
+    expect_stat preprocessed_cache_hit 0
+    expect_stat cache_miss 0
+    expect_stat unsupported_code_directive 2
+
     cat <<EOF >incbin.s
 .incbin "empty.bin";
 EOF
@@ -1499,7 +1508,7 @@ EOF
     $CCACHE_COMPILE -c incbin.s
     expect_stat preprocessed_cache_hit 0
     expect_stat cache_miss 0
-    expect_stat unsupported_code_directive 2
+    expect_stat unsupported_code_directive 3
 
     cat <<EOF >incbin.cpp
       struct A {
@@ -1514,7 +1523,7 @@ EOF
     if $CCACHE_COMPILE -x c++ -c incbin.cpp 2>/dev/null; then
         expect_stat preprocessed_cache_hit 0
         expect_stat cache_miss 1
-        expect_stat unsupported_code_directive 2
+        expect_stat unsupported_code_directive 3
     fi
 fi