[clang] [clang] Specialize invocation path visitation to the cow (PR #205686)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 26 09:11:28 PDT 2026
================
@@ -445,13 +424,30 @@ class CowCompilerInvocation : public CompilerInvocationBase {
ssaf::SSAFOptions &getMutSSAFOpts();
/// @}
+ /// The result of mutable visitation.
+ struct VisitMutResult {
+ /// Whether to replace the given StringRef with the modified std::string &.
+ bool Replace = false;
+ /// Whether to short-circuit the visitation.
+ bool Terminate = false;
+ };
+
/// Visits paths stored in the invocation, allowing the callback to mutate
- /// them. To preserve the copy-on-write invariant for groups whose paths the
- /// caller might modify, this ensures unique ownership of every option group
- /// up front; if the callback only inspects (and does not mutate) the paths,
- /// the const \c visitPaths overload should be used instead to avoid those
- /// per-group copies.
- void visitMutPaths(llvm::function_ref<bool(std::string &)> Callback);
+ /// them via the out-param. This upholds the same copy-on-write semantics as
+ /// the mutable getters.
+ void visitMutPaths(
+ llvm::function_ref<VisitMutResult(StringRef, std::string &)> Cb);
----------------
jansvoboda11 wrote:
I considered this, but I didn't like that this prevents you from erasing a path, which is IMO important in an API as general as this.
https://github.com/llvm/llvm-project/pull/205686
More information about the cfe-commits
mailing list