]> 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>
Sat, 20 Aug 2022 12:06:24 +0000 (14:06 +0200)
Regression in #983.

Fixes #1120.

(cherry picked from commit 7ee6030bc7b2e6ef321c01854f88ce0fd81c4513)

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

index 94f7c89fe30496796e475670db44a6a6fb602845..d9a42c2b778f0a7d7848ddc16903d63fd7f62300 100644 (file)
@@ -465,8 +465,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):
@@ -570,14 +569,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 89cddf3e8bd926ba9bff22fefbf72c058a1ec347..8c4622fd8adb8036878d1e8bbe7c3da996aa9913 100644 (file)
@@ -1493,6 +1493,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
@@ -1500,7 +1509,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 {
@@ -1515,7 +1524,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