Skip to content

Commit 4e58f03

Browse files
authoredFeb 7, 2024
[Clang] Fix : More Detailed "No expected directives found" (#78338)
Updated the error message to use the proper prefix when no expected directives are found by changing the hard coded expected in the message to a dynamic value in two error messages. Fixes #58290
1 parent 50d38cf commit 4e58f03

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed
 

‎clang/include/clang/Basic/DiagnosticFrontendKinds.td

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ def err_verify_inconsistent_diags : Error<
176176
"'%0' diagnostics %select{expected|seen}1 but not %select{seen|expected}1: "
177177
"%2">;
178178
def err_verify_invalid_no_diags : Error<
179-
"%select{expected|'expected-no-diagnostics'}0 directive cannot follow "
180-
"%select{'expected-no-diagnostics' directive|other expected directives}0">;
179+
"%select{expected|'%0-no-diagnostics'}1 directive cannot follow "
180+
"%select{'%0-no-diagnostics' directive|other expected directives}1">;
181181
def err_verify_no_directives : Error<
182-
"no expected directives found: consider use of 'expected-no-diagnostics'">;
182+
"no expected directives found: consider use of '%0-no-diagnostics'">;
183183
def err_verify_nonconst_addrspace : Error<
184184
"qualifier 'const' is needed for variables in address space '%0'">;
185185

‎clang/lib/Frontend/VerifyDiagnosticConsumer.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ class VerifyDiagnosticConsumer::MarkerTracker {
396396
}
397397
};
398398

399+
static std::string DetailedErrorString(const DiagnosticsEngine &Diags) {
400+
if (Diags.getDiagnosticOptions().VerifyPrefixes.empty())
401+
return "expected";
402+
return *Diags.getDiagnosticOptions().VerifyPrefixes.begin();
403+
}
404+
399405
/// ParseDirective - Go through the comment and see if it indicates expected
400406
/// diagnostics. If so, then put them in the appropriate directive list.
401407
///
@@ -478,14 +484,14 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
478484
if (NoDiag) {
479485
if (Status == VerifyDiagnosticConsumer::HasOtherExpectedDirectives)
480486
Diags.Report(Pos, diag::err_verify_invalid_no_diags)
481-
<< /*IsExpectedNoDiagnostics=*/true;
487+
<< DetailedErrorString(Diags) << /*IsExpectedNoDiagnostics=*/true;
482488
else
483489
Status = VerifyDiagnosticConsumer::HasExpectedNoDiagnostics;
484490
continue;
485491
}
486492
if (Status == VerifyDiagnosticConsumer::HasExpectedNoDiagnostics) {
487493
Diags.Report(Pos, diag::err_verify_invalid_no_diags)
488-
<< /*IsExpectedNoDiagnostics=*/false;
494+
<< DetailedErrorString(Diags) << /*IsExpectedNoDiagnostics=*/false;
489495
continue;
490496
}
491497
Status = VerifyDiagnosticConsumer::HasOtherExpectedDirectives;
@@ -1104,7 +1110,8 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
11041110
// Produce an error if no expected-* directives could be found in the
11051111
// source file(s) processed.
11061112
if (Status == HasNoDirectives) {
1107-
Diags.Report(diag::err_verify_no_directives).setForceEmit();
1113+
Diags.Report(diag::err_verify_no_directives).setForceEmit()
1114+
<< DetailedErrorString(Diags);
11081115
++NumErrors;
11091116
Status = HasNoDirectivesReported;
11101117
}

‎clang/test/Frontend/verify.c

+29
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,32 @@ unexpected b; // expected-error@33 1-1 {{unknown type}}
187187
#endif
188188

189189
#endif
190+
191+
#ifdef TEST10
192+
// RUN: not %clang_cc1 -DTEST10 -verify=foo %s 2>&1 | FileCheck -check-prefix=CHECK10 %s
193+
194+
// CHECK10: error: no expected directives found: consider use of 'foo-no-diagnostics'
195+
#endif
196+
197+
#ifdef TEST11
198+
// RUN: not %clang_cc1 -DTEST11 -verify=foo %s 2>&1 | FileCheck -check-prefix=CHECK11 %s
199+
200+
// foo-no-diagnostics
201+
// foo-note {{}}
202+
203+
// CHECK11: error: 'foo-error' diagnostics seen but not expected:
204+
// CHECK11-NEXT: Line 201: expected directive cannot follow 'foo-no-diagnostics' directive
205+
// CHECK11-NEXT: 1 error generated.
206+
#endif
207+
208+
#ifdef TEST12
209+
// RUN: not %clang_cc1 -DTEST12 -verify=foo %s 2>&1 | FileCheck -check-prefix=CHECK12 %s
210+
211+
#warning X
212+
// foo-warning@-1 {{X}}
213+
// foo-no-diagnostics
214+
215+
// CHECK12: error: 'foo-error' diagnostics seen but not expected:
216+
// CHECK12-NEXT: Line 213: 'foo-no-diagnostics' directive cannot follow other expected directives
217+
// CHECK12-NEXT: 1 error generated.
218+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.