Skip to content

Commit 010408f

Browse files
authored
Merge pull request #19022 from jrose-apple/diagonal
Honor #sourceLocation filenames in serialized diagnostics
2 parents 9e2ebd0 + 115a664 commit 010408f

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

lib/Frontend/SerializedDiagnosticConsumer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ emitDiagnosticMessage(SourceManager &SM,
497497

498498
StringRef filename = "";
499499
if (Loc.isValid())
500-
filename = SM.getIdentifierForBuffer(SM.findBufferContainingLoc(Loc));
500+
filename = SM.getDisplayNameForLoc(Loc);
501501

502502
// Emit the RECORD_DIAG record.
503503
Record.clear();

test/Frontend/vfs.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfs/secondary-vfsoverlay.yaml > %t/secondary-overlay.yaml
44
// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfs/tertiary-vfsoverlay.yaml > %t/tertiary-overlay.yaml
55

6-
// RUN: not %target-swift-frontend -vfsoverlay %t/overlay.yaml -typecheck %s %t/mapped-file.swift 2>&1 | %FileCheck -check-prefix=BASIC_MAPPING_ERROR %s
6+
// RUN: not %target-swift-frontend -vfsoverlay %t/overlay.yaml -typecheck %s %t/mapped-file.swift -serialize-diagnostics-path %t/basic.dia 2>&1 | %FileCheck -check-prefix=BASIC_MAPPING_ERROR %s
7+
// RUN: c-index-test -read-diagnostics %t/basic.dia 2>&1 | %FileCheck -check-prefix=BASIC_MAPPING_ERROR %s
78

89
// BASIC_MAPPING_ERROR: {{.*}}/mapped-file.swift:2:17: error:
910

10-
// RUN: not %target-swift-frontend -vfsoverlay %t/overlay.yaml -vfsoverlay %t/secondary-overlay.yaml -vfsoverlay %t/tertiary-overlay.yaml -typecheck %s %t/triple-mapped-swift-file.swift 2>&1 | %FileCheck -check-prefix=COMPLEX_MAPPING_ERROR %s
11+
// RUN: not %target-swift-frontend -vfsoverlay %t/overlay.yaml -vfsoverlay %t/secondary-overlay.yaml -vfsoverlay %t/tertiary-overlay.yaml -typecheck %s %t/triple-mapped-swift-file.swift -serialize-diagnostics-path %t/complex.dia 2>&1 | %FileCheck -check-prefix=COMPLEX_MAPPING_ERROR %s
12+
// RUN: c-index-test -read-diagnostics %t/complex.dia 2>&1 | %FileCheck -check-prefix=COMPLEX_MAPPING_ERROR %s
1113

1214
// COMPLEX_MAPPING_ERROR: {{.*}}/triple-mapped-swift-file.swift:2:17: error:
1315

test/Misc/serialized-diagnostics.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@
55
// RUN: c-index-test -read-diagnostics %t.dia > %t.deserialized_diagnostics.txt 2>&1
66
// RUN: %FileCheck --input-file=%t.deserialized_diagnostics.txt %s
77

8-
// Test swift_driver integrated frontend
9-
// RUN: %target-swift-frontend -typecheck -serialize-diagnostics-path %t.integrated_frontend.dia %s -verify
10-
// RUN: c-index-test -read-diagnostics %t.integrated_frontend.dia > %t.integrated_frontend.deserialized_diagnostics.txt 2>&1
11-
// RUN: %FileCheck --input-file=%t.integrated_frontend.deserialized_diagnostics.txt %s
12-
138
var x = 1 x = 2 // expected-error {{consecutive statements on a line must be separated by ';'}} {{10-10=;}}
14-
var z : Int // expected-note {{previously declared here}}
9+
// CHECK: {{.*[/\\]}}serialized-diagnostics.swift:[[@LINE-1]]:10: error: consecutive statements on a line must be separated by ';' [] []
10+
// CHECK-NEXT: Number FIXITs = 1
11+
// CHECK-NEXT: FIXIT: ({{.*[/\\]}}serialized-diagnostics.swift:[[@LINE-3]]:10 - {{.*[/\\]}}serialized-diagnostics.swift:[[@LINE-3]]:10): ";"
12+
13+
var z : Int // expected-note 2 {{previously declared here}}
1514
var z : Int // expected-error {{invalid redeclaration}}
15+
// CHECK-NEXT: {{.*[/\\]}}serialized-diagnostics.swift:[[@LINE-1]]:5: error: invalid redeclaration of 'z' [] []
16+
// CHECK-NEXT: Number FIXITs = 0
17+
// CHECK-NEXT: +-{{.*[/\\]}}serialized-diagnostics.swift:[[@LINE-4]]:5: note: 'z' previously declared here [] []
18+
// CHECK-NEXT: Number FIXITs = 0
1619

17-
// CHECK: 13:10: error: consecutive statements on a line must be separated by ';' [] []
18-
// CHECK-NEXT: Number FIXITs = 1
19-
// CHECK-NEXT: FIXIT: ({{.*[/\\]}}serialized-diagnostics.swift:13:10 - {{.*[/\\]}}serialized-diagnostics.swift:13:10): ";"
20-
// CHECK-NEXT: 15:5: error: invalid redeclaration of 'z' [] []
20+
#sourceLocation(file: "fake-file.swuft", line: 4)
21+
var z : Int // Note: no expected-* here because it's "not in this file".
22+
// CHECK-NEXT: {{^}}fake-file.swuft:4:5: error: invalid redeclaration of 'z' [] []
2123
// CHECK-NEXT: Number FIXITs = 0
22-
// CHECK-NEXT: +-{{.*[/\\]}}serialized-diagnostics.swift:14:5: note: 'z' previously declared here [] []
24+
// CHECK-NEXT: +-{{.*[/\\]}}serialized-diagnostics.swift:{{[0-9]+}}:5: note: 'z' previously declared here [] []
2325
// CHECK-NEXT: Number FIXITs = 0
24-
// CHECK-NEXT: Number of diagnostics: 2
26+
27+
// CHECK-NEXT: Number of diagnostics: 3

0 commit comments

Comments
 (0)