From bc97d547288e046978b18130d2ddcb404f9ca45b Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sun, 9 Jan 2022 22:13:02 +0100 Subject: [PATCH] fix: Make src/ccache.cpp cacheable by ccache itself MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit “.incbin” should not be present verbatim in the source code since that makes ccache consider the code uncacheable. Regression in 2d2de82bb9231b981b40486b093a2c0002200c40. --- src/ccache.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ccache.cpp b/src/ccache.cpp index 422d97695..939189b3c 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2002-2007 Andrew Tridgell -// Copyright (C) 2009-2021 Joel Rosdahl and other contributors +// Copyright (C) 2009-2022 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -460,6 +460,10 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path) "# 31 \"\"\n"; static const string_view hash_32_command_line_2_newline = "# 32 \"\" 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', ' '}; // 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): @@ -572,8 +576,8 @@ 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 \\\"", 10) == 0 - || strncmp(q, ".incbin \"", 9) == 0) { + } else if (strncmp(q, incbin_prefix, sizeof(incbin_prefix)) == 0 + && (q[8] == '"' || (q[8] == '\\' && q[9] == '"'))) { // 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 -- 2.47.2