Skip to content

Commit 530588f

Browse files
committed
[DiagnosticVerifier] suggest outermost buffername for...
...-verify-additional-file It's not expected that users add macro expansion buffer names to -verify-additional-file. The recommended approach is to add the actual source file that the macro was expanded in, and use expected-expansion.
1 parent bbcba6a commit 530588f

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lib/Frontend/DiagnosticVerifier.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,16 @@ bool DiagnosticVerifier::verifyUnrelated(
430430
auto diag = SM.GetMessage(Loc, llvm::SourceMgr::DK_Error, Message, {}, {});
431431
printDiagnostic(diag);
432432

433-
auto FileName = SM.getIdentifierForBuffer(SM.findBufferContainingLoc(Loc));
433+
unsigned TopmostBufferID = SM.findBufferContainingLoc(Loc);
434+
while (const GeneratedSourceInfo *GSI =
435+
SM.getGeneratedSourceInfo(TopmostBufferID)) {
436+
SourceLoc ParentLoc = GSI->originalSourceRange.getStart();
437+
if (ParentLoc.isInvalid())
438+
break;
439+
TopmostBufferID = SM.findBufferContainingLoc(ParentLoc);
440+
Loc = ParentLoc;
441+
}
442+
auto FileName = SM.getIdentifierForBuffer(TopmostBufferID);
434443
auto noteDiag =
435444
SM.GetMessage(Loc, llvm::SourceMgr::DK_Note,
436445
("file '" + FileName +

test/Frontend/DiagnosticVerifier/clang-attribute.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,35 @@ module TestClang {
2323

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
26-
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
27-
// CHECK: TEST_H:1:25: note: in expansion from here
26+
// 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
2827
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
2928
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
3029
// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
3130

3231
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: error: unexpected remark produced: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer<Int32>) {|
3332
// CHECK: TEST_H:1:25: note: in expansion from here
34-
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
35-
// CHECK: TEST_H:1:25: note: in expansion from here
33+
// 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
3634
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
3735
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
3836
// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
3937

4038
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: error: unexpected remark produced: macro content: | let len = Int32(exactly: p.count)!|
4139
// CHECK: TEST_H:1:25: note: in expansion from here
42-
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
43-
// CHECK: TEST_H:1:25: note: in expansion from here
40+
// 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
4441
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
4542
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
4643
// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
4744

4845
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: error: unexpected remark produced: macro content: | return unsafe foo(len, p.baseAddress!)|
4946
// CHECK: TEST_H:1:25: note: in expansion from here
50-
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
51-
// CHECK: TEST_H:1:25: note: in expansion from here
47+
// 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
5248
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
5349
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
5450
// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
5551

5652
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: error: unexpected remark produced: macro content: |}|
5753
// CHECK: TEST_H:1:25: note: in expansion from here
58-
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
59-
// CHECK: TEST_H:1:25: note: in expansion from here
54+
// 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
6055
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
6156
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
6257
// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file

0 commit comments

Comments
 (0)