@@ -678,10 +678,13 @@ struct SourceMgrDiagnosticVerifierHandlerImpl {
678678 // / A list of expected diagnostics for each buffer of the source manager.
679679 llvm::StringMap<SmallVector<ExpectedDiag, 2 >> expectedDiagsPerFile;
680680
681+ // / A list of expected diagnostics with unknown locations.
682+ SmallVector<ExpectedDiag, 2 > expectedUnknownLocDiags;
683+
681684 // / Regex to match the expected diagnostics format.
682685 llvm::Regex expected =
683686 llvm::Regex (" expected-(error|note|remark|warning)(-re)? "
684- " *(@([+-][0-9]+|above|below))? *{{(.*)}}$" );
687+ " *(@([+-][0-9]+|above|below|unknown ))? *{{(.*)}}$" );
685688};
686689} // namespace detail
687690} // namespace mlir
@@ -774,6 +777,11 @@ SourceMgrDiagnosticVerifierHandlerImpl::computeExpectedDiags(
774777 record.lineNo += offset;
775778 else
776779 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 ;
777785 } else if (offsetMatch.consume_front (" above" )) {
778786 // If the designator applies 'above' we add it to the last non
779787 // designator line.
@@ -828,53 +836,57 @@ SourceMgrDiagnosticVerifierHandler::~SourceMgrDiagnosticVerifierHandler() {
828836// / verified correctly, failure otherwise.
829837LogicalResult SourceMgrDiagnosticVerifierHandler::verify () {
830838 // 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 )
835841 impl->status =
836842 err.emitError (os, mgr,
837843 " expected " + getDiagKindStr (err.kind ) + " \" " +
838844 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);
841851 impl->expectedDiagsPerFile .clear ();
842852 return impl->status ;
843853}
844854
845855// / Process a single diagnostic.
846856void 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 ());
857858}
858859
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,
861862 StringRef msg,
862863 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 ;
868878 }
869879
870880 // Search for a matching expected diagnostic.
871881 // If we find something that is close then emit a more specific error.
872882 ExpectedDiag *nearMiss = nullptr ;
873883
874884 // 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)) {
878890 if (e.kind == kind) {
879891 e.matched = true ;
880892 return ;
0 commit comments