[clang] [clang][DepScan] Allow ModuleDep to be const (PR #132968)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 25 11:07:33 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Cyndy Ishida (cyndyishida)
<details>
<summary>Changes</summary>
This type can be exposed from C APIs, where instantiations of this type are not expected to mutate after creation. To support this, mark the lazy computation of build arguments mutable, as that is not intended to otherwise mutate the state of these objects.
This was reviewed separately by @<!-- -->jansvoboda11
---
Full diff: https://github.com/llvm/llvm-project/pull/132968.diff
2 Files Affected:
- (modified) clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h (+3-2)
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+3-1)
``````````diff
diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index 422202caddfd4..ed150b467e3a1 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -153,7 +153,7 @@ struct ModuleDeps {
/// Get (or compute) the compiler invocation that can be used to build this
/// module. Does not include argv[0].
- const std::vector<std::string> &getBuildArguments();
+ const std::vector<std::string> &getBuildArguments() const;
private:
friend class ModuleDepCollector;
@@ -166,7 +166,8 @@ struct ModuleDeps {
/// including transitive dependencies.
std::vector<std::string> FileDeps;
- std::variant<std::monostate, CowCompilerInvocation, std::vector<std::string>>
+ mutable std::variant<std::monostate, CowCompilerInvocation,
+ std::vector<std::string>>
BuildInfo;
};
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index d715ef874e002..364f156566855 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -31,7 +31,9 @@ void ModuleDeps::forEachFileDep(llvm::function_ref<void(StringRef)> Cb) const {
}
}
-const std::vector<std::string> &ModuleDeps::getBuildArguments() {
+const std::vector<std::string> &ModuleDeps::getBuildArguments() const {
+ // FIXME: this operation is not thread safe and is expected to be called
+ // on a single thread. Otherwise it should be protected with a lock.
assert(!std::holds_alternative<std::monostate>(BuildInfo) &&
"Using uninitialized ModuleDeps");
if (const auto *CI = std::get_if<CowCompilerInvocation>(&BuildInfo))
``````````
</details>
https://github.com/llvm/llvm-project/pull/132968
More information about the cfe-commits
mailing list