Skip to content

Commit b63abd8

Browse files
committed
[DiagnosticVerifier] emit placeholder when filename is empty
This makes it more explicit and consistent, which are good properties for test output. It makes it easier both for humans and update-verify-tests to see what exactly is going on. This does not affect how diagnostics are displayed to users normally.
1 parent 703fc1c commit b63abd8

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

lib/Frontend/DiagnosticVerifier.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,14 @@ void DiagnosticVerifier::printDiagnostic(const llvm::SMDiagnostic &Diag) const {
485485
ColoredStream coloredStream{stream};
486486
raw_ostream &out = UseColor ? coloredStream : stream;
487487
llvm::SourceMgr &Underlying = SM.getLLVMSourceMgr();
488-
Underlying.PrintMessage(out, Diag);
488+
if (Diag.getFilename().empty()) {
489+
llvm::SMDiagnostic SubstDiag(
490+
*Diag.getSourceMgr(), Diag.getLoc(), "<empty-filename>",
491+
Diag.getLineNo(), Diag.getColumnNo(), Diag.getKind(), Diag.getMessage(),
492+
Diag.getLineContents(), Diag.getRanges(), Diag.getFixIts());
493+
Underlying.PrintMessage(out, SubstDiag);
494+
} else
495+
Underlying.PrintMessage(out, Diag);
489496

490497
SourceLoc Loc = SourceLoc::getFromPointer(Diag.getLoc().getPointer());
491498
if (Loc.isInvalid())

test/Frontend/DiagnosticVerifier/clang-attribute.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,64 +24,64 @@ module TestClang {
2424
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: error: unexpected remark produced: macro content: |/// This is an auto-generated wrapper for safer interop|
2525
// CHECK: TEST_H:1:25: note: in expansion from here
2626
// CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
27-
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
28-
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
29-
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
30-
// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
27+
// CHECK: <empty-filename>:1:1: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
28+
// // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
29+
// CHECK: TEST_H:1:6: note: in expansion from here
30+
// CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
3131

3232
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: error: unexpected remark produced: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer<Int32>) {|
3333
// CHECK: TEST_H:1:25: note: in expansion from here
3434
// CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
35-
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
35+
// CHECK: <empty-filename>:1:1: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
3636
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
37-
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
38-
// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
37+
// CHECK: TEST_H:1:6: note: in expansion from here
38+
// CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
3939

4040
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: error: unexpected remark produced: macro content: | let len = Int32(exactly: p.count)!|
4141
// CHECK: TEST_H:1:25: note: in expansion from here
4242
// CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
43-
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
43+
// CHECK: <empty-filename>:1:1: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
4444
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
45-
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
46-
// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
45+
// CHECK: TEST_H:1:6: note: in expansion from here
46+
// CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
4747

4848
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: error: unexpected remark produced: macro content: | return unsafe foo(len, p.baseAddress!)|
4949
// CHECK: TEST_H:1:25: note: in expansion from here
5050
// CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
51-
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
51+
// CHECK: <empty-filename>:1:1: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
5252
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
53-
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
54-
// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
53+
// CHECK: TEST_H:1:6: note: in expansion from here
54+
// CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
5555

5656
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: error: unexpected remark produced: macro content: |}|
5757
// CHECK: TEST_H:1:25: note: in expansion from here
5858
// CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
59-
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
59+
// CHECK: <empty-filename>:1:1: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
6060
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
61-
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
62-
// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
61+
// CHECK: TEST_H:1:6: note: in expansion from here
62+
// CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
6363

6464
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: remark: diagnostic produced elsewhere: macro content: |/// This is an auto-generated wrapper for safer interop|
6565
// CHECK: TEST_H:1:25: note: in expansion from here
66-
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
67-
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
66+
// CHECK: <empty-filename>:1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
67+
// CHECK: TEST_H:1:6: note: in expansion from here
6868

6969
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: remark: diagnostic produced elsewhere: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer<Int32>) {|
7070
// CHECK: TEST_H:1:25: note: in expansion from here
71-
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
72-
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
71+
// CHECK: <empty-filename>:1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
72+
// CHECK: TEST_H:1:6: note: in expansion from here
7373

7474
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: remark: diagnostic produced elsewhere: macro content: | let len = Int32(exactly: p.count)!|
7575
// CHECK: TEST_H:1:25: note: in expansion from here
76-
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
77-
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
76+
// CHECK: <empty-filename>:1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
77+
// CHECK: TEST_H:1:6: note: in expansion from here
7878

7979
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: remark: diagnostic produced elsewhere: macro content: | return unsafe foo(len, p.baseAddress!)|
8080
// CHECK: TEST_H:1:25: note: in expansion from here
81-
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
82-
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
81+
// CHECK: <empty-filename>:1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
82+
// CHECK: TEST_H:1:6: note: in expansion from here
8383

8484
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: remark: diagnostic produced elsewhere: macro content: |}|
8585
// CHECK: TEST_H:1:25: note: in expansion from here
86-
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
87-
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
86+
// CHECK: <empty-filename>:1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
87+
// CHECK: TEST_H:1:6: note: in expansion from here

0 commit comments

Comments
 (0)