for (const auto token : util::Tokenizer(value, ", ")) {
if (token == "clang_index_store") {
- result.enable(core::Sloppy::clang_index_store);
+ result.insert(core::Sloppy::clang_index_store);
} else if (token == "file_stat_matches") {
- result.enable(core::Sloppy::file_stat_matches);
+ result.insert(core::Sloppy::file_stat_matches);
} else if (token == "file_stat_matches_ctime") {
- result.enable(core::Sloppy::file_stat_matches_ctime);
+ result.insert(core::Sloppy::file_stat_matches_ctime);
} else if (token == "gcno_cwd") {
- result.enable(core::Sloppy::gcno_cwd);
+ result.insert(core::Sloppy::gcno_cwd);
} else if (token == "include_file_ctime") {
- result.enable(core::Sloppy::include_file_ctime);
+ result.insert(core::Sloppy::include_file_ctime);
} else if (token == "include_file_mtime") {
- result.enable(core::Sloppy::include_file_mtime);
+ result.insert(core::Sloppy::include_file_mtime);
} else if (token == "ivfsoverlay") {
- result.enable(core::Sloppy::ivfsoverlay);
+ result.insert(core::Sloppy::ivfsoverlay);
} else if (token == "locale") {
- result.enable(core::Sloppy::locale);
+ result.insert(core::Sloppy::locale);
} else if (token == "modules") {
- result.enable(core::Sloppy::modules);
+ result.insert(core::Sloppy::modules);
} else if (token == "pch_defines") {
- result.enable(core::Sloppy::pch_defines);
+ result.insert(core::Sloppy::pch_defines);
} else if (token == "random_seed") {
- result.enable(core::Sloppy::random_seed);
+ result.insert(core::Sloppy::random_seed);
} else if (token == "system_headers" || token == "no_system_headers") {
- result.enable(core::Sloppy::system_headers);
+ result.insert(core::Sloppy::system_headers);
} else if (token == "time_macros") {
- result.enable(core::Sloppy::time_macros);
+ result.insert(core::Sloppy::time_macros);
} // else: ignore unknown value for forward compatibility
}
format_sloppiness(core::Sloppiness sloppiness)
{
std::string result;
- if (sloppiness.is_enabled(core::Sloppy::clang_index_store)) {
+ if (sloppiness.contains(core::Sloppy::clang_index_store)) {
result += "clang_index_store, ";
}
- if (sloppiness.is_enabled(core::Sloppy::file_stat_matches)) {
+ if (sloppiness.contains(core::Sloppy::file_stat_matches)) {
result += "file_stat_matches, ";
}
- if (sloppiness.is_enabled(core::Sloppy::file_stat_matches_ctime)) {
+ if (sloppiness.contains(core::Sloppy::file_stat_matches_ctime)) {
result += "file_stat_matches_ctime, ";
}
- if (sloppiness.is_enabled(core::Sloppy::gcno_cwd)) {
+ if (sloppiness.contains(core::Sloppy::gcno_cwd)) {
result += "gcno_cwd, ";
}
- if (sloppiness.is_enabled(core::Sloppy::include_file_ctime)) {
+ if (sloppiness.contains(core::Sloppy::include_file_ctime)) {
result += "include_file_ctime, ";
}
- if (sloppiness.is_enabled(core::Sloppy::include_file_mtime)) {
+ if (sloppiness.contains(core::Sloppy::include_file_mtime)) {
result += "include_file_mtime, ";
}
- if (sloppiness.is_enabled(core::Sloppy::ivfsoverlay)) {
+ if (sloppiness.contains(core::Sloppy::ivfsoverlay)) {
result += "ivfsoverlay, ";
}
- if (sloppiness.is_enabled(core::Sloppy::locale)) {
+ if (sloppiness.contains(core::Sloppy::locale)) {
result += "locale, ";
}
- if (sloppiness.is_enabled(core::Sloppy::modules)) {
+ if (sloppiness.contains(core::Sloppy::modules)) {
result += "modules, ";
}
- if (sloppiness.is_enabled(core::Sloppy::pch_defines)) {
+ if (sloppiness.contains(core::Sloppy::pch_defines)) {
result += "pch_defines, ";
}
- if (sloppiness.is_enabled(core::Sloppy::random_seed)) {
+ if (sloppiness.contains(core::Sloppy::random_seed)) {
result += "random_seed, ";
}
- if (sloppiness.is_enabled(core::Sloppy::system_headers)) {
+ if (sloppiness.contains(core::Sloppy::system_headers)) {
result += "system_headers, ";
}
- if (sloppiness.is_enabled(core::Sloppy::time_macros)) {
+ if (sloppiness.contains(core::Sloppy::time_macros)) {
result += "time_macros, ";
}
if (!result.empty()) {
// Ignore clang -ivfsoverlay <arg> to not detect multiple input files.
if (arg == "-ivfsoverlay"
- && !(config.sloppiness().is_enabled(core::Sloppy::ivfsoverlay))) {
+ && !(config.sloppiness().contains(core::Sloppy::ivfsoverlay))) {
LOG_RAW(
"You have to specify \"ivfsoverlay\" sloppiness when using"
" -ivfsoverlay to get hits");
LOG("Compiler option {} is unsupported without direct depend mode",
args[i]);
return Statistic::could_not_use_modules;
- } else if (!(config.sloppiness().is_enabled(core::Sloppy::modules))) {
+ } else if (!(config.sloppiness().contains(core::Sloppy::modules))) {
LOG_RAW(
"You have to specify \"modules\" sloppiness when using"
" -fmodules to get hits");
}
if (arg == "-fprofile-abs-path") {
- if (!config.sloppiness().is_enabled(core::Sloppy::gcno_cwd)) {
+ if (!config.sloppiness().contains(core::Sloppy::gcno_cwd)) {
// -fprofile-abs-path makes the compiler include absolute paths based on
// the actual CWD in the .gcno file.
state.hash_actual_cwd = true;
return Statistic::none;
}
- if (config.sloppiness().is_enabled(core::Sloppy::clang_index_store)
+ if (config.sloppiness().contains(core::Sloppy::clang_index_store)
&& arg == "-index-store-path") {
// Xcode 9 or later calls Clang with this option. The given path includes a
// UUID that might lead to cache misses, especially when cache is shared
if (state.found_pch || state.found_fpch_preprocess) {
args_info.using_precompiled_header = true;
- if (!(config.sloppiness().is_enabled(core::Sloppy::time_macros))) {
+ if (!(config.sloppiness().contains(core::Sloppy::time_macros))) {
LOG_RAW(
"You have to specify \"time_macros\" sloppiness when using"
" precompiled headers to get direct hits");
}
if (args_info.output_is_precompiled_header
- && !(config.sloppiness().is_enabled(core::Sloppy::pch_defines))) {
+ && !(config.sloppiness().contains(core::Sloppy::pch_defines))) {
LOG_RAW(
"You have to specify \"pch_defines,time_macros\" sloppiness when"
" creating precompiled headers");
// The comparison using >= is intentional, due to a possible race between
// starting compilation and writing the include file. See also the notes under
// "Performance" in doc/MANUAL.adoc.
- if (!(ctx.config.sloppiness().is_enabled(core::Sloppy::include_file_mtime))
+ if (!(ctx.config.sloppiness().contains(core::Sloppy::include_file_mtime))
&& path_stat.mtime() >= ctx.time_of_compilation) {
LOG("Include file {} too new", path);
return true;
}
// The same >= logic as above applies to the change time of the file.
- if (!(ctx.config.sloppiness().is_enabled(core::Sloppy::include_file_ctime))
+ if (!(ctx.config.sloppiness().contains(core::Sloppy::include_file_ctime))
&& path_stat.ctime() >= ctx.time_of_compilation) {
LOG("Include file {} ctime too new", path);
return true;
}
if (system
- && (ctx.config.sloppiness().is_enabled(core::Sloppy::system_headers))) {
+ && (ctx.config.sloppiness().contains(core::Sloppy::system_headers))) {
// Don't remember this system header.
return true;
}
// so mtimes/ctimes are stored as a dummy value (-1) if not enabled. This
// reduces the number of file_info entries for the common case.
const bool save_timestamp =
- (ctx.config.sloppiness().is_enabled(core::Sloppy::file_stat_matches))
+ (ctx.config.sloppiness().contains(core::Sloppy::file_stat_matches))
|| ctx.args_info.output_is_precompiled_header;
const bool added = ctx.manifest.add_result(
}
}
- if (!(ctx.config.sloppiness().is_enabled(core::Sloppy::locale))) {
+ if (!(ctx.config.sloppiness().contains(core::Sloppy::locale))) {
// Hash environment variables that may affect localization of compiler
// warning messages.
const char* envvars[] = {
}
if (ctx.args_info.generating_coverage
- && !(ctx.config.sloppiness().is_enabled(core::Sloppy::gcno_cwd))) {
+ && !(ctx.config.sloppiness().contains(core::Sloppy::gcno_cwd))) {
// GCC 9+ includes $PWD in the .gcno file. Since we don't have knowledge
// about compiler version we always (unless sloppiness is wanted) include
// the directory in the hash for now.
}
if (util::starts_with(args[i], "-frandom-seed=")
- && ctx.config.sloppiness().is_enabled(core::Sloppy::random_seed)) {
+ && ctx.config.sloppiness().contains(core::Sloppy::random_seed)) {
LOG("Ignoring {} since random_seed sloppiness is requested", args[i]);
return {};
}
return false;
}
- if (ctx.config.sloppiness().is_enabled(core::Sloppy::file_stat_matches)) {
- if (!(ctx.config.sloppiness().is_enabled(
- core::Sloppy::file_stat_matches_ctime))) {
+ if (ctx.config.sloppiness().contains(core::Sloppy::file_stat_matches)) {
+ if (!ctx.config.sloppiness().contains(
+ core::Sloppy::file_stat_matches_ctime)) {
if (fi.mtime == fs.mtime && fi.ctime == fs.ctime) {
LOG("mtime/ctime hit for {}", path);
continue;
-// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#pragma once
+#include <util/BitSet.hpp>
+
#include <cstdint>
#include <string>
random_seed = 1U << 12,
};
-class Sloppiness
-{
-public:
- Sloppiness(Sloppy value = Sloppy::none);
- explicit Sloppiness(uint32_t value);
-
- void enable(Sloppy value);
- bool is_enabled(Sloppy value) const;
- uint32_t to_bitmask() const;
-
-private:
- Sloppy m_sloppiness = Sloppy::none;
-};
-
-// --- Inline implementations ---
-
-inline Sloppiness::Sloppiness(Sloppy value) : m_sloppiness(value)
-{
-}
-
-inline Sloppiness::Sloppiness(uint32_t value)
- : m_sloppiness(static_cast<Sloppy>(value))
-{
-}
-
-inline void
-Sloppiness::enable(Sloppy value)
-{
- m_sloppiness = static_cast<Sloppy>(static_cast<uint32_t>(m_sloppiness)
- | static_cast<uint32_t>(value));
-}
-
-inline bool
-Sloppiness::is_enabled(Sloppy value) const
-{
- return static_cast<uint32_t>(m_sloppiness) & static_cast<uint32_t>(value);
-}
-
-inline uint32_t
-Sloppiness::to_bitmask() const
-{
- return static_cast<uint32_t>(m_sloppiness);
-}
+using Sloppiness = util::BitSet<Sloppy>;
} // namespace core
-// Copyright (C) 2009-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2009-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
size_t size_hint)
{
const bool check_temporal_macros =
- !ctx.config.sloppiness().is_enabled(core::Sloppy::time_macros);
- int result =
+ !ctx.config.sloppiness().contains(core::Sloppy::time_macros);
+ auto result =
do_hash_file(ctx, digest, path, size_hint, check_temporal_macros);
if (!check_temporal_macros || result == HASH_SOURCE_CODE_OK