Skip to content

Commit 62ba94e

Browse files
committed
[DiagnosticVerifier] don't repeat diagnostics in other files
`verifyUnknown()` and `verifyUnrelated()` would not remove the diagnostics after reporting their errors, leading to the same diagnostics then being emitted a second time. This removes them from the list after emitting them, just like `verifyFile()` does.
1 parent b63abd8 commit 62ba94e

File tree

6 files changed

+19
-41
lines changed

6 files changed

+19
-41
lines changed

lib/Frontend/DiagnosticVerifier.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,19 +386,23 @@ static void autoApplyFixes(SourceManager &SM, unsigned BufferID,
386386
bool DiagnosticVerifier::verifyUnknown(
387387
std::vector<CapturedDiagnosticInfo> &CapturedDiagnostics) const {
388388
bool HadError = false;
389-
for (unsigned i = 0, e = CapturedDiagnostics.size(); i != e; ++i) {
390-
if (CapturedDiagnostics[i].Loc.isValid())
389+
auto CapturedDiagIter = CapturedDiagnostics.begin();
390+
while (CapturedDiagIter != CapturedDiagnostics.end()) {
391+
if (CapturedDiagIter->Loc.isValid()) {
392+
++CapturedDiagIter;
391393
continue;
394+
}
392395

393396
HadError = true;
394397
std::string Message =
395398
("unexpected " +
396-
getDiagKindString(CapturedDiagnostics[i].Classification) +
397-
" produced: " + CapturedDiagnostics[i].Message)
399+
getDiagKindString(CapturedDiagIter->Classification) +
400+
" produced: " + CapturedDiagIter->Message)
398401
.str();
399402

400403
auto diag = SM.GetMessage({}, llvm::SourceMgr::DK_Error, Message, {}, {});
401404
printDiagnostic(diag);
405+
CapturedDiagIter = CapturedDiagnostics.erase(CapturedDiagIter);
402406
}
403407

404408
if (HadError) {
@@ -414,17 +418,20 @@ bool DiagnosticVerifier::verifyUnknown(
414418
bool DiagnosticVerifier::verifyUnrelated(
415419
std::vector<CapturedDiagnosticInfo> &CapturedDiagnostics) const {
416420
bool HadError = false;
417-
for (unsigned i = 0, e = CapturedDiagnostics.size(); i != e; ++i) {
418-
SourceLoc Loc = CapturedDiagnostics[i].Loc;
419-
if (!Loc.isValid())
421+
auto CapturedDiagIter = CapturedDiagnostics.begin();
422+
while (CapturedDiagIter != CapturedDiagnostics.end()) {
423+
SourceLoc Loc = CapturedDiagIter->Loc;
424+
if (!Loc.isValid()) {
425+
++CapturedDiagIter;
420426
// checked by verifyUnknown
421427
continue;
428+
}
422429

423430
HadError = true;
424431
std::string Message =
425432
("unexpected " +
426-
getDiagKindString(CapturedDiagnostics[i].Classification) +
427-
" produced: " + CapturedDiagnostics[i].Message)
433+
getDiagKindString(CapturedDiagIter->Classification) +
434+
" produced: " + CapturedDiagIter->Message)
428435
.str();
429436

430437
auto diag = SM.GetMessage(Loc, llvm::SourceMgr::DK_Error, Message, {}, {});
@@ -450,6 +457,7 @@ bool DiagnosticVerifier::verifyUnrelated(
450457
"ignore diagnostics in this file"),
451458
{}, {});
452459
printDiagnostic(noteDiag);
460+
CapturedDiagIter = CapturedDiagnostics.erase(CapturedDiagIter);
453461
}
454462

455463
return HadError;

test/Frontend/DiagnosticVerifier/broken-c-module.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
// RUN: not %target-typecheck-verify-swift -I %S/Inputs/broken-c-module 2>&1 | %FileCheck %s --implicit-check-not error: --implicit-check-not note: --implicit-check-not warning:
77

88
// CHECK: <unknown>:0: error: fatal error encountered while in -verify mode
9-
// CHECK: [[@LINE+7]]:8: error: unexpected error produced: could not build
9+
// CHECK: [[@LINE+5]]:8: error: unexpected error produced: could not build
1010
// CHECK: error: unexpected note produced: in file included from <module-includes>:1:
1111
// CHECK: note: file '<module-includes>' is not parsed for 'expected' statements. Use '-verify-additional-file <module-includes>' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
1212
// CHECK: error: unexpected error produced: expected function body after function declarator
1313
// CHECK: note: file '{{.*}}broken_c.h' is not parsed for 'expected' statements. Use '-verify-additional-file {{.*}}broken_c.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
14-
// CHECK: note: diagnostic produced elsewhere: in file included from <module-includes>
15-
// CHECK: broken_c.h:2:11: error: diagnostic produced elsewhere: expected function body after function declarator
1614
import BrokenCModule

test/Frontend/DiagnosticVerifier/clang-attribute.swift

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,3 @@ module TestClang {
6060
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
6161
// CHECK: TEST_H:1:6: note: in expansion from here
6262
// 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
63-
64-
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: remark: diagnostic produced elsewhere: macro content: |/// This is an auto-generated wrapper for safer interop|
65-
// CHECK: TEST_H:1:25: 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
68-
69-
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: remark: diagnostic produced elsewhere: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer<Int32>) {|
70-
// CHECK: TEST_H:1:25: 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
73-
74-
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: remark: diagnostic produced elsewhere: macro content: | let len = Int32(exactly: p.count)!|
75-
// CHECK: TEST_H:1:25: 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
78-
79-
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: remark: diagnostic produced elsewhere: macro content: | return unsafe foo(len, p.baseAddress!)|
80-
// CHECK: TEST_H:1:25: 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
83-
84-
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: remark: diagnostic produced elsewhere: macro content: |}|
85-
// CHECK: TEST_H:1:25: 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

test/Frontend/DiagnosticVerifier/verify.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ fn(()) // expected-error {{argument passed to call that takes no arguments}}
3434
let x: Array<Int, Int>
3535
// CHECK: error: unexpected note produced: generic struct 'Array' declared here
3636
// CHECK: note: file 'Swift.Array' is not parsed for 'expected' statements. Use '-verify-additional-file Swift.Array' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
37-
// CHECK: note: diagnostic produced elsewhere: generic struct 'Array' declared here

test/Frontend/DiagnosticVerifier/verify2.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ extension Crap {} // expected-error {{non-nominal type 'Crap' (aka '() -> ()') c
4444

4545
// CHECK: error: unexpected note produced: 'Bool' declared here
4646
// CHECK: note: file 'Swift.Bool' is not parsed for 'expected' statements. Use '-verify-additional-file Swift.Bool' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
47-
// CHECK: note: diagnostic produced elsewhere: 'Bool' declared here
4847

4948
// Verify the serialized diags have the right magic at the top.
5049
// CHECK-SERIALIZED: DIA

test/Interop/Cxx/templates/function-template-typechecker-errors.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: not %target-typecheck-verify-swift -verify-ignore-unrelated -I %S/Inputs -enable-experimental-cxx-interop 2>&1 | %FileCheck %s
2-
1+
// RUN: not %target-typecheck-verify-swift -verify-ignore-unrelated -verify-ignore-unknown -I %S/Inputs -enable-experimental-cxx-interop 2>&1 | %FileCheck %s
32
// README: If you just added support for protocol composition to the
43
// ClangTypeConverter, please update this test to use a different type that we
54
// don't support so the error messages here are still tested.

0 commit comments

Comments
 (0)