]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Disambiguate manifest and result hash for MSVC depend mode
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 27 Apr 2026 16:44:32 +0000 (18:44 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 27 Apr 2026 16:44:32 +0000 (18:44 +0200)
When using depend mode with MSVC and the source file doesn't include any
file, the result hash becomes identical to the manifest hash. Fix this
by adding a "result" hash delimiter, similar to how it's done in the
non-MSVC case (result_key_from_depfile).

This bug has existed since the addition of depend mode support for MSVC
(b1348e5f5ebe10b486b4e86f0114884a04f9531a). It's not a big deal, but the
storage layer will use the same key, so manifest or result parsing might
fail and fall back to just running the compiler.

src/ccache/ccache.cpp

index 39cdd53aad242c00a23edf2e87f7d77e30851b47..d4fe5de4aab57a3a90bbc7a11a1eb290a2fd4cfd 100644 (file)
@@ -728,9 +728,8 @@ process_preprocessed_file(Context& ctx, Hash& hash, const fs::path& path)
 static tl::expected<Hash::Digest, Failure>
 result_key_from_depfile(Context& ctx, Hash& hash)
 {
-  // Make sure that result hash will always be different from the manifest hash
-  // since there otherwise may a storage key collision (in case the dependency
-  // file is empty).
+  // Ensure the result hash always differs from the manifest hash to avoid
+  // storage key collisions when the dependency file is empty.
   hash.hash_delimiter("result");
 
   const auto file_content =
@@ -804,6 +803,10 @@ struct DoExecuteResult
 static tl::expected<Hash::Digest, Failure>
 result_key_from_includes(Context& ctx, Hash& hash, std::string_view stdout_data)
 {
+  // Ensure the result hash always differs from the manifest hash to avoid
+  // storage key collisions when there are no included files.
+  hash.hash_delimiter("result");
+
   for (std::string_view include :
        compiler::get_includes_from_msvc_show_includes(
          stdout_data, ctx.config.msvc_dep_prefix())) {