diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 85ecfdf9de62d..b1a282f5164a2 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -176,10 +176,10 @@ def err_verify_inconsistent_diags : Error< "'%0' diagnostics %select{expected|seen}1 but not %select{seen|expected}1: " "%2">; def err_verify_invalid_no_diags : Error< - "%select{expected|'expected-no-diagnostics'}0 directive cannot follow " - "%select{'expected-no-diagnostics' directive|other expected directives}0">; + "%select{expected|'%0-no-diagnostics'}1 directive cannot follow " + "%select{'%0-no-diagnostics' directive|other expected directives}1">; def err_verify_no_directives : Error< - "no expected directives found: consider use of 'expected-no-diagnostics'">; + "no expected directives found: consider use of '%0-no-diagnostics'">; def err_verify_nonconst_addrspace : Error< "qualifier 'const' is needed for variables in address space '%0'">; diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index 304935a0a90b8..48330e9361718 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -396,6 +396,12 @@ class VerifyDiagnosticConsumer::MarkerTracker { } }; +static std::string DetailedErrorString(const DiagnosticsEngine &Diags) { + if (Diags.getDiagnosticOptions().VerifyPrefixes.empty()) + return "expected"; + return *Diags.getDiagnosticOptions().VerifyPrefixes.begin(); +} + /// ParseDirective - Go through the comment and see if it indicates expected /// diagnostics. If so, then put them in the appropriate directive list. /// @@ -478,14 +484,14 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, if (NoDiag) { if (Status == VerifyDiagnosticConsumer::HasOtherExpectedDirectives) Diags.Report(Pos, diag::err_verify_invalid_no_diags) - << /*IsExpectedNoDiagnostics=*/true; + << DetailedErrorString(Diags) << /*IsExpectedNoDiagnostics=*/true; else Status = VerifyDiagnosticConsumer::HasExpectedNoDiagnostics; continue; } if (Status == VerifyDiagnosticConsumer::HasExpectedNoDiagnostics) { Diags.Report(Pos, diag::err_verify_invalid_no_diags) - << /*IsExpectedNoDiagnostics=*/false; + << DetailedErrorString(Diags) << /*IsExpectedNoDiagnostics=*/false; continue; } Status = VerifyDiagnosticConsumer::HasOtherExpectedDirectives; @@ -1104,7 +1110,8 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() { // Produce an error if no expected-* directives could be found in the // source file(s) processed. if (Status == HasNoDirectives) { - Diags.Report(diag::err_verify_no_directives).setForceEmit(); + Diags.Report(diag::err_verify_no_directives).setForceEmit() + << DetailedErrorString(Diags); ++NumErrors; Status = HasNoDirectivesReported; } diff --git a/clang/test/Frontend/verify.c b/clang/test/Frontend/verify.c index c549011d7b7a9..afd1c7d6907e2 100644 --- a/clang/test/Frontend/verify.c +++ b/clang/test/Frontend/verify.c @@ -187,3 +187,32 @@ unexpected b; // expected-error@33 1-1 {{unknown type}} #endif #endif + +#ifdef TEST10 +// RUN: not %clang_cc1 -DTEST10 -verify=foo %s 2>&1 | FileCheck -check-prefix=CHECK10 %s + +// CHECK10: error: no expected directives found: consider use of 'foo-no-diagnostics' +#endif + +#ifdef TEST11 +// RUN: not %clang_cc1 -DTEST11 -verify=foo %s 2>&1 | FileCheck -check-prefix=CHECK11 %s + +// foo-no-diagnostics +// foo-note {{}} + +// CHECK11: error: 'foo-error' diagnostics seen but not expected: +// CHECK11-NEXT: Line 201: expected directive cannot follow 'foo-no-diagnostics' directive +// CHECK11-NEXT: 1 error generated. +#endif + +#ifdef TEST12 +// RUN: not %clang_cc1 -DTEST12 -verify=foo %s 2>&1 | FileCheck -check-prefix=CHECK12 %s + +#warning X +// foo-warning@-1 {{X}} +// foo-no-diagnostics + +// CHECK12: error: 'foo-error' diagnostics seen but not expected: +// CHECK12-NEXT: Line 213: 'foo-no-diagnostics' directive cannot follow other expected directives +// CHECK12-NEXT: 1 error generated. +#endif