Skip to content

Commit 9aecbdf

Browse files
authored
[clang][DepScan] Allow ModuleDep to be const (#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
1 parent 535b284 commit 9aecbdf

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
@@ -153,7 +153,7 @@ struct ModuleDeps {
153153

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

158158
private:
159159
friend class ModuleDepCollector;
@@ -166,7 +166,8 @@ struct ModuleDeps {
166166
/// including transitive dependencies.
167167
std::vector<std::string> FileDeps;
168168

169-
std::variant<std::monostate, CowCompilerInvocation, std::vector<std::string>>
169+
mutable std::variant<std::monostate, CowCompilerInvocation,
170+
std::vector<std::string>>
170171
BuildInfo;
171172
};
172173

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

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

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

0 commit comments

Comments
 (0)