Skip to content

Commit 5278f1b

Browse files
committed
[clang][DepScan] Allow ModuleDep to be const (llvm#132968)
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 (cherry picked from commit 9aecbdf)
1 parent e347255 commit 5278f1b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct ModuleDeps {
168168

169169
/// Get (or compute) the compiler invocation that can be used to build this
170170
/// module. Does not include argv[0].
171-
const std::vector<std::string> &getBuildArguments();
171+
const std::vector<std::string> &getBuildArguments() const;
172172

173173
private:
174174
friend class ModuleDepCollector;
@@ -181,7 +181,8 @@ struct ModuleDeps {
181181
/// including transitive dependencies.
182182
std::vector<std::string> FileDeps;
183183

184-
std::variant<std::monostate, CowCompilerInvocation, std::vector<std::string>>
184+
mutable std::variant<std::monostate, CowCompilerInvocation,
185+
std::vector<std::string>>
185186
BuildInfo;
186187
};
187188

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ void ModuleDeps::forEachFileDep(llvm::function_ref<void(StringRef)> Cb) const {
3636
}
3737
}
3838

39-
const std::vector<std::string> &ModuleDeps::getBuildArguments() {
39+
const std::vector<std::string> &ModuleDeps::getBuildArguments() const {
40+
// FIXME: this operation is not thread safe and is expected to be called
41+
// on a single thread. Otherwise it should be protected with a lock.
4042
assert(!std::holds_alternative<std::monostate>(BuildInfo) &&
4143
"Using uninitialized ModuleDeps");
4244
if (const auto *CI = std::get_if<CowCompilerInvocation>(&BuildInfo))

0 commit comments

Comments
 (0)