@@ -678,10 +678,13 @@ struct SourceMgrDiagnosticVerifierHandlerImpl {
678
678
// / A list of expected diagnostics for each buffer of the source manager.
679
679
llvm::StringMap<SmallVector<ExpectedDiag, 2 >> expectedDiagsPerFile;
680
680
681
+ // / A list of expected diagnostics with unknown locations.
682
+ SmallVector<ExpectedDiag, 2 > expectedUnknownLocDiags;
683
+
681
684
// / Regex to match the expected diagnostics format.
682
685
llvm::Regex expected =
683
686
llvm::Regex (" expected-(error|note|remark|warning)(-re)? "
684
- " *(@([+-][0-9]+|above|below))? *{{(.*)}}$" );
687
+ " *(@([+-][0-9]+|above|below|unknown ))? *{{(.*)}}$" );
685
688
};
686
689
} // namespace detail
687
690
} // namespace mlir
@@ -774,6 +777,11 @@ SourceMgrDiagnosticVerifierHandlerImpl::computeExpectedDiags(
774
777
record.lineNo += offset;
775
778
else
776
779
record.lineNo -= offset;
780
+ } else if (offsetMatch.consume_front (" unknown" )) {
781
+ // This is matching unknown locations.
782
+ record.fileLoc = SMLoc ();
783
+ expectedUnknownLocDiags.emplace_back (std::move (record));
784
+ continue ;
777
785
} else if (offsetMatch.consume_front (" above" )) {
778
786
// If the designator applies 'above' we add it to the last non
779
787
// designator line.
@@ -828,53 +836,57 @@ SourceMgrDiagnosticVerifierHandler::~SourceMgrDiagnosticVerifierHandler() {
828
836
// / verified correctly, failure otherwise.
829
837
LogicalResult SourceMgrDiagnosticVerifierHandler::verify () {
830
838
// Verify that all expected errors were seen.
831
- for (auto &expectedDiagsPair : impl->expectedDiagsPerFile ) {
832
- for (auto &err : expectedDiagsPair.second ) {
833
- if (err.matched )
834
- continue ;
839
+ auto checkExpectedDiags = [&](ExpectedDiag &err) {
840
+ if (!err.matched )
835
841
impl->status =
836
842
err.emitError (os, mgr,
837
843
" expected " + getDiagKindStr (err.kind ) + " \" " +
838
844
err.substring + " \" was not produced" );
839
- }
840
- }
845
+ };
846
+ for (auto &expectedDiagsPair : impl->expectedDiagsPerFile )
847
+ for (auto &err : expectedDiagsPair.second )
848
+ checkExpectedDiags (err);
849
+ for (auto &err : impl->expectedUnknownLocDiags )
850
+ checkExpectedDiags (err);
841
851
impl->expectedDiagsPerFile .clear ();
842
852
return impl->status ;
843
853
}
844
854
845
855
// / Process a single diagnostic.
846
856
void SourceMgrDiagnosticVerifierHandler::process (Diagnostic &diag) {
847
- auto kind = diag.getSeverity ();
848
-
849
- // Process a FileLineColLoc.
850
- if (auto fileLoc = diag.getLocation ()->findInstanceOf <FileLineColLoc>())
851
- return process (fileLoc, diag.str (), kind);
852
-
853
- emitDiagnostic (diag.getLocation (),
854
- " unexpected " + getDiagKindStr (kind) + " : " + diag.str (),
855
- DiagnosticSeverity::Error);
856
- impl->status = failure ();
857
+ return process (diag.getLocation (), diag.str (), diag.getSeverity ());
857
858
}
858
859
859
- // / Process a FileLineColLoc diagnostic.
860
- void SourceMgrDiagnosticVerifierHandler::process (FileLineColLoc loc,
860
+ // / Process a diagnostic at a certain location .
861
+ void SourceMgrDiagnosticVerifierHandler::process (LocationAttr loc,
861
862
StringRef msg,
862
863
DiagnosticSeverity kind) {
863
- // Get the expected diagnostics for this file.
864
- auto diags = impl->getExpectedDiags (loc.getFilename ());
865
- if (!diags) {
866
- diags = impl->computeExpectedDiags (os, mgr,
867
- getBufferForFile (loc.getFilename ()));
864
+ FileLineColLoc fileLoc = loc.findInstanceOf <FileLineColLoc>();
865
+ MutableArrayRef<ExpectedDiag> diags;
866
+
867
+ if (fileLoc) {
868
+ // Get the expected diagnostics for this file.
869
+ if (auto maybeDiags = impl->getExpectedDiags (fileLoc.getFilename ())) {
870
+ diags = *maybeDiags;
871
+ } else {
872
+ diags = impl->computeExpectedDiags (
873
+ os, mgr, getBufferForFile (fileLoc.getFilename ()));
874
+ }
875
+ } else {
876
+ // Get all expected diagnostics at unknown locations.
877
+ diags = impl->expectedUnknownLocDiags ;
868
878
}
869
879
870
880
// Search for a matching expected diagnostic.
871
881
// If we find something that is close then emit a more specific error.
872
882
ExpectedDiag *nearMiss = nullptr ;
873
883
874
884
// If this was an expected error, remember that we saw it and return.
875
- unsigned line = loc.getLine ();
876
- for (auto &e : *diags) {
877
- if (line == e.lineNo && e.match (msg)) {
885
+ for (auto &e : diags) {
886
+ // File line must match (unless it's an unknown location).
887
+ if (fileLoc && fileLoc.getLine () != e.lineNo )
888
+ continue ;
889
+ if (e.match (msg)) {
878
890
if (e.kind == kind) {
879
891
e.matched = true ;
880
892
return ;
0 commit comments