@@ -181,7 +181,10 @@ canonicalizeForCaching(llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
181
181
//
182
182
// TODO: Extract CASOptions.Path first if we need it later since it'll
183
183
// 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 ();
185
188
186
189
// TODO: Canonicalize DiagnosticOptions here to be "serialized" only. Pass in
187
190
// a hook to mirror diagnostics to stderr (when writing there), and handle
@@ -194,8 +197,20 @@ canonicalizeForCaching(llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
194
197
std::optional<llvm::cas::CASID> clang::canonicalizeAndCreateCacheKey (
195
198
llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
196
199
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
+
197
205
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;
199
214
}
200
215
201
216
std::optional<llvm::cas::CASID>
0 commit comments