Skip to content

Commit ca87615

Browse files
[CAS] Allow empty filename for diagnostics location
Fix a bug that an empty filename for diagnostics can trigger an error in the cached diagnostics. The empty filename can be a virtual file synthesized, for example, to hold an implicit attribute from clang importer. The cached diagnostics can correctly handle such filename now and cached/replay those diagnostics. rdar://141961161
1 parent eb6933b commit ca87615

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

lib/Frontend/CachedDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ unsigned DiagnosticSerializer::getFileIDFromBufferID(SourceManager &SM,
330330

331331
auto &Buf = SM.getLLVMSourceMgr().getBufferInfo(Idx);
332332
auto Filename = Buf.Buffer->getBufferIdentifier();
333-
bool IsFileBacked = SM.getFileSystem()->exists(Filename);
333+
bool IsFileBacked = !Filename.empty() && SM.getFileSystem()->exists(Filename);
334334

335335
// Construct and add to files. If there is an IncludeLoc, the file from
336336
// IncludeLoc is added before current file.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// REQUIRES: swift_feature_RegionBasedIsolation
2+
// REQUIRES: objc_interop
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: split-file %s %t
6+
7+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -O -I %t \
8+
// RUN: -disable-implicit-string-processing-module-import \
9+
// RUN: %t/test.swift -o %t/deps.json -cache-compile-job -cas-path %t/cas -module-load-mode prefer-serialized
10+
11+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/shim.cmd
12+
// RUN: %swift_frontend_plain @%t/shim.cmd
13+
14+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:_SwiftConcurrencyShims > %t/cshim.cmd
15+
// RUN: %swift_frontend_plain @%t/cshim.cmd
16+
17+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:A > %t/A.cmd
18+
// RUN: %swift_frontend_plain @%t/A.cmd -Rcache-compile-job 2>&1 | %FileCheck %s --check-prefix=CHECK --check-prefix=CACHE-MISS
19+
20+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:A > %t/A.cmd
21+
// RUN: %swift_frontend_plain @%t/A.cmd -Rcache-compile-job 2>&1 | %FileCheck %s --check-prefix=CHECK --check-prefix=CACHE-HIT
22+
23+
// CACHE-MISS: remark: cache miss for input
24+
// CHECK: <module-includes>:1
25+
// CHECK-SAME: note: in file included from <module-includes>:1:
26+
// CHECK: warning: warning a.h
27+
// CACHE-HIT: remark: replay output file
28+
29+
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
30+
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
31+
32+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd
33+
// RUN: echo "\"-disable-implicit-string-processing-module-import\"" >> %t/MyApp.cmd
34+
// RUN: echo "\"-disable-implicit-swift-modules\"" >> %t/MyApp.cmd
35+
// RUN: echo "\"-explicit-swift-module-map-file\"" >> %t/MyApp.cmd
36+
// RUN: echo "\"@%t/map.casid\"" >> %t/MyApp.cmd
37+
38+
// RUN: %target-swift-frontend -cache-compile-job -module-name Test -O -cas-path %t/cas @%t/MyApp.cmd %t/test.swift \
39+
// RUN: -emit-module -o %t/test.swiftmodule -require-explicit-sendable -strict-concurrency=complete -enable-upcoming-feature RegionBasedIsolation
40+
41+
//--- module.modulemap
42+
module A {
43+
header "a.h"
44+
export *
45+
}
46+
47+
//--- a.h
48+
#warning warning a.h
49+
50+
#pragma clang attribute push(__attribute__((swift_attr("@_nonSendable(_assumed)"))), apply_to = any(objc_interface, record, enum))
51+
@protocol P
52+
@end
53+
54+
@interface C
55+
@end
56+
#pragma clang attribute pop
57+
58+
//--- test.swift
59+
import A
60+
import _Concurrency
61+
62+
func acceptSendable<T: Sendable>(_: T) {
63+
}
64+
65+
func testMe(c: C) {
66+
acceptSendable(c)
67+
}
68+

0 commit comments

Comments
 (0)