@@ -207,7 +207,10 @@ canonicalizeForCaching(llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
207
207
//
208
208
// TODO: Extract CASOptions.Path first if we need it later since it'll
209
209
// disappear here.
210
- Invocation.getCASOpts ().freezeConfig (Diags);
210
+ Invocation.getCASOpts () = {};
211
+ // Set the CASPath to the hash schema to match CASOptions::freezeConfig.
212
+ Invocation.getCASOpts ().CASPath =
213
+ CAS.getContext ().getHashSchemaIdentifier ().str ();
211
214
212
215
// TODO: Canonicalize DiagnosticOptions here to be "serialized" only. Pass in
213
216
// a hook to mirror diagnostics to stderr (when writing there), and handle
@@ -223,47 +226,51 @@ clang::canonicalizeAndCreateCacheKeys(ObjectStore &CAS,
223
226
DiagnosticsEngine &Diags,
224
227
CompilerInvocation &CI,
225
228
CompileJobCachingOptions &Opts) {
226
- if (!CI.getFrontendOpts ().CASInputFileCacheKey .empty ()) {
227
- Opts = canonicalizeForCaching (CAS, Diags, CI);
228
- auto CacheKey = createCompileJobCacheKeyImpl (CAS, Diags, CI);
229
- if (!CacheKey)
230
- return std::nullopt;
231
-
232
- auto ID = CAS.parseID (CI.getFrontendOpts ().CASInputFileCacheKey );
233
- if (!ID) {
234
- Diags.Report (diag::err_cas_cannot_parse_input_cache_key)
235
- << CI.getFrontendOpts ().CASInputFileCacheKey ;
236
- return std::nullopt;
237
- }
238
- auto Value = Cache.get (*ID);
239
- if (!Value) {
240
- Diags.Report (diag::err_cas_cannot_lookup_input_cache_key)
241
- << Value.takeError ();
242
- return std::nullopt;
243
- }
244
- if (!*Value) {
245
- Diags.Report (diag::err_cas_missing_input_cache_entry)
246
- << llvm::cas::ObjectStore::createUnknownObjectError (*ID);
247
- return std::nullopt;
248
- }
229
+ // Preserve and freeze CASOptions so that we do not modify behaviour of
230
+ // Invocation.getCASOpts().getOrCreateDatabases().
231
+ CASOptions CASOpts (CI.getCASOpts ());
232
+ CASOpts.freezeConfig (Diags);
249
233
250
- CI.getFrontendOpts ().CASInputFileCASID = Value.get ()->toString ();
251
- CI.getFrontendOpts ().CASInputFileCacheKey .clear ();
234
+ Opts = canonicalizeForCaching (CAS, Diags, CI);
235
+ auto CacheKey = createCompileJobCacheKeyImpl (CAS, Diags, CI);
236
+ if (!CacheKey)
237
+ return std::nullopt;
252
238
253
- CompilerInvocation CICopy = CI;
254
- (void )canonicalizeForCaching (CAS, Diags, CICopy);
255
- auto CanonicalCacheKey = createCompileJobCacheKeyImpl (CAS, Diags, CICopy);
256
- if (!CanonicalCacheKey)
257
- return std::nullopt;
239
+ assert (CI.getCASOpts ().CASPath == CASOpts.CASPath &&
240
+ " cas instance has incompatible hash with cas options" );
241
+ CI.getCASOpts () = std::move (CASOpts);
258
242
259
- return std::make_pair (*CacheKey, *CanonicalCacheKey);
243
+ if (CI.getFrontendOpts ().CASInputFileCacheKey .empty ())
244
+ return std::make_pair (*CacheKey, *CacheKey);
245
+
246
+ auto ID = CAS.parseID (CI.getFrontendOpts ().CASInputFileCacheKey );
247
+ if (!ID) {
248
+ Diags.Report (diag::err_cas_cannot_parse_input_cache_key)
249
+ << CI.getFrontendOpts ().CASInputFileCacheKey ;
250
+ return std::nullopt;
251
+ }
252
+ auto Value = Cache.get (*ID);
253
+ if (!Value) {
254
+ Diags.Report (diag::err_cas_cannot_lookup_input_cache_key)
255
+ << Value.takeError ();
256
+ return std::nullopt;
257
+ }
258
+ if (!*Value) {
259
+ Diags.Report (diag::err_cas_missing_input_cache_entry)
260
+ << llvm::cas::ObjectStore::createUnknownObjectError (*ID);
261
+ return std::nullopt;
260
262
}
261
263
262
- Opts = canonicalizeForCaching (CAS, Diags, CI);
263
- auto CacheKey = createCompileJobCacheKeyImpl (CAS, Diags, CI);
264
- if (!CacheKey)
264
+ CI.getFrontendOpts ().CASInputFileCASID = Value.get ()->toString ();
265
+ CI.getFrontendOpts ().CASInputFileCacheKey .clear ();
266
+
267
+ CompilerInvocation CICopy = CI;
268
+ (void )canonicalizeForCaching (CAS, Diags, CICopy);
269
+ auto CanonicalCacheKey = createCompileJobCacheKeyImpl (CAS, Diags, CICopy);
270
+ if (!CanonicalCacheKey)
265
271
return std::nullopt;
266
- return std::make_pair (*CacheKey, *CacheKey);
272
+
273
+ return std::make_pair (*CacheKey, *CanonicalCacheKey);
267
274
}
268
275
269
276
std::optional<llvm::cas::CASID>
0 commit comments