@@ -181,7 +181,10 @@ canonicalizeForCaching(llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
181181 //
182182 // TODO: Extract CASOptions.Path first if we need it later since it'll
183183 // disappear here.
184- Invocation.getCASOpts ().freezeConfig (Diags);
184+ Invocation.getCASOpts () = {};
185+ // Set the CASPath to the hash schema to match CASOptions::freezeConfig.
186+ Invocation.getCASOpts ().CASPath =
187+ CAS.getContext ().getHashSchemaIdentifier ().str ();
185188
186189 // TODO: Canonicalize DiagnosticOptions here to be "serialized" only. Pass in
187190 // a hook to mirror diagnostics to stderr (when writing there), and handle
@@ -194,8 +197,20 @@ canonicalizeForCaching(llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
194197std::optional<llvm::cas::CASID> clang::canonicalizeAndCreateCacheKey (
195198 llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
196199 CompilerInvocation &Invocation, CompileJobCachingOptions &Opts) {
200+ // Preserve and freeze CASOptions so that we do not modify behaviour of
201+ // Invocation.getCASOpts().getOrCreateDatabases().
202+ CASOptions CASOpts (Invocation.getCASOpts ());
203+ CASOpts.freezeConfig (Diags);
204+
197205 Opts = canonicalizeForCaching (CAS, Diags, Invocation);
198- return createCompileJobCacheKeyImpl (CAS, Diags, Invocation);
206+ auto CacheKey = createCompileJobCacheKeyImpl (CAS, Diags, Invocation);
207+ if (!CacheKey)
208+ return std::nullopt ;
209+
210+ assert (Invocation.getCASOpts ().CASPath == CASOpts.CASPath &&
211+ " cas instance has incompatible hash with cas options" );
212+ Invocation.getCASOpts () = std::move (CASOpts);
213+ return CacheKey;
199214}
200215
201216std::optional<llvm::cas::CASID>
0 commit comments