From: Raihaan Shouhell Date: Tue, 4 Oct 2022 19:21:42 +0000 (+0800) Subject: feat: Add sloppiness for -frandom-seed (#1168) X-Git-Tag: v4.7~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=923e0b95a3833a17adf889a9a2abec3396b2524e;p=thirdparty%2Fccache.git feat: Add sloppiness for -frandom-seed (#1168) --- diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index 8577ac1f2..d979818e0 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -1002,6 +1002,9 @@ preprocessing first. *time_macros*:: Ignore `+__DATE__+`, `+__TIME__+` and `+__TIMESTAMP__+` being present in the source code. +*random_seed*:: + By default, ccache will respect argument changes with `-frandom-seed`. This + sloppiness will allow cache hits even if the seed value is different. -- + See the discussion under _<>_ for more information. diff --git a/src/Config.cpp b/src/Config.cpp index 9d2b3ae44..520557e10 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -304,6 +304,8 @@ parse_sloppiness(const std::string& value) result.enable(core::Sloppy::modules); } else if (token == "pch_defines") { result.enable(core::Sloppy::pch_defines); + } else if (token == "random_seed") { + result.enable(core::Sloppy::random_seed); } else if (token == "system_headers" || token == "no_system_headers") { result.enable(core::Sloppy::system_headers); } else if (token == "time_macros") { @@ -348,6 +350,9 @@ format_sloppiness(core::Sloppiness sloppiness) if (sloppiness.is_enabled(core::Sloppy::pch_defines)) { result += "pch_defines, "; } + if (sloppiness.is_enabled(core::Sloppy::random_seed)) { + result += "random_seed, "; + } if (sloppiness.is_enabled(core::Sloppy::system_headers)) { result += "system_headers, "; } diff --git a/src/ccache.cpp b/src/ccache.cpp index 2ae809327..29e90de7b 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1555,6 +1555,15 @@ hash_argument(const Context& ctx, return {}; } + // If we treat random_seed sloppily we ignore the argument when + // hashing. + if (util::starts_with(args[i], "-frandom-seed=") + && ctx.config.sloppiness().is_enabled(core::Sloppy::random_seed)) { + hash.hash_delimiter("arg"); + hash.hash("-frandom-seed="); + return {}; + } + // When using the preprocessor, some arguments don't contribute to the hash. // The theory is that these arguments will change the output of -E if they are // going to have any effect at all. For precompiled headers this might not be diff --git a/src/core/Sloppiness.hpp b/src/core/Sloppiness.hpp index 69d3dface..a7aa08eea 100644 --- a/src/core/Sloppiness.hpp +++ b/src/core/Sloppiness.hpp @@ -49,6 +49,8 @@ enum class Sloppy : uint32_t { ivfsoverlay = 1U << 10, // Allow us to include incorrect working directory in .gcno files. gcno_cwd = 1U << 11, + // Ignore changes in -frandom-seed + random_seed = 1U << 12, }; class Sloppiness