diff --git a/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h b/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h --- a/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h +++ b/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h @@ -251,7 +251,8 @@ HasNoDirectives, HasNoDirectivesReported, HasExpectedNoDiagnostics, - HasOtherExpectedDirectives + HasOtherExpectedDirectives, + HasExpectedMaybeNoDiagnostics }; class MarkerTracker; diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -462,7 +462,11 @@ D.DL = ED ? &ED->Remarks : nullptr; else if (DToken.endswith(DType="-note")) D.DL = ED ? &ED->Notes : nullptr; - else if (DToken.endswith(DType="-no-diagnostics")) { + else if (DToken.endswith(DType="-maybe-no-diagnostics")) { + if (Status == VerifyDiagnosticConsumer::HasNoDirectives) + Status = VerifyDiagnosticConsumer::HasExpectedMaybeNoDiagnostics; + continue; + } else if (DToken.endswith(DType="-no-diagnostics")) { NoDiag = true; if (D.RegexKind) continue; diff --git a/clang/test/Frontend/verify-maybe-no-diagnostics.c b/clang/test/Frontend/verify-maybe-no-diagnostics.c new file mode 100644 --- /dev/null +++ b/clang/test/Frontend/verify-maybe-no-diagnostics.c @@ -0,0 +1,106 @@ +// RUN: %clang_cc1 -DTEST_A1 -verify %s +// RUN: %clang_cc1 -DTEST_B1 -verify %s +// RUN: %clang_cc1 -DTEST_B2 -verify %s +// RUN: %clang_cc1 -DTEST_C1 -verify %s +// RUN: %clang_cc1 -DTEST_C2 -verify %s +// RUN: not %clang_cc1 -DTEST_D1 -verify %s 2>&1 | FileCheck --check-prefix=D1-CHECK %s +// RUN: not %clang_cc1 -DTEST_D2 -verify %s 2>&1 | FileCheck --check-prefix=D2-CHECK %s +// RUN: not %clang_cc1 -DTEST_D3 -verify %s 2>&1 | FileCheck --check-prefix=D3-CHECK %s +// RUN: not %clang_cc1 -DTEST_D4 -verify %s 2>&1 | FileCheck --check-prefix=D4-CHECK %s +// RUN: not %clang_cc1 -DTEST_D5 -verify %s 2>&1 | FileCheck --check-prefix=D5-CHECK %s +// RUN: not %clang_cc1 -DTEST_D6 -verify %s 2>&1 | FileCheck --check-prefix=D6-CHECK %s + +#ifdef TEST_A1 +// expected-maybe-no-diagnostics +#endif + +#ifdef TEST_B1 +// expected-maybe-no-diagnostics +// expected-no-diagnostics +#endif + +#ifdef TEST_B2 +// expected-no-diagnostics +// expected-maybe-no-diagnostics +#endif + +#ifdef TEST_C1 +// expected-maybe-no-diagnostics +#error test_c1 +// expected-error@-1 {{test_c1}} +#endif + +#ifdef TEST_C2 +#error test_c2 +// expected-error@-1 {{test_c2}} +// expected-maybe-no-diagnostics +#endif + +#ifdef TEST_D1 +// expected-maybe-no-diagnostics +#error test_d1 +// expected-error@-1 {{test_d1}} +// expected-no-diagnostics + +// D1-CHECK: error: 'error' diagnostics seen but not expected: +// D1-CHECK-NEXT: {{.*}} 'expected-no-diagnostics' directive cannot follow other expected directives +// D1-CHECK-NEXT: 1 error generated. +#endif + +#ifdef TEST_D2 +// expected-maybe-no-diagnostics +// expected-no-diagnostics +#error test_d2 +// expected-error@-1 {{test_d2}} + +// D2-CHECK: error: 'error' diagnostics seen but not expected: +// D2-CHECK-NEXT: {{test_d2}} +// D2-CHECK-NEXT: {{.*}} expected directive cannot follow 'expected-no-diagnostics' directive +// D2-CHECK-NEXT: 2 errors generated. +#endif + +#ifdef TEST_D3 +// expected-no-diagnostics +// expected-maybe-no-diagnostics +#error test_d3 +// expected-error@-1 {{test_d3}} + +// D3-CHECK: error: 'error' diagnostics seen but not expected: +// D3-CHECK-NEXT: {{test_d3}} +// D3-CHECK-NEXT: {{.*}} expected directive cannot follow 'expected-no-diagnostics' directive +// D3-CHECK-NEXT: 2 errors generated. +#endif + +#ifdef TEST_D4 +// expected-no-diagnostics +#error test_d4 +// expected-error@-1 {{test_d4}} +// expected-maybe-no-diagnostics + +// D4-CHECK: error: 'error' diagnostics seen but not expected: +// D4-CHECK-NEXT: {{test_d4}} +// D4-CHECK-NEXT: {{.*}} expected directive cannot follow 'expected-no-diagnostics' directive +// D4-CHECK-NEXT: 2 errors generated. +#endif + +#ifdef TEST_D5 +#error test_d5 +// expected-error@-1 {{test_d5}} +// expected-no-diagnostics +// expected-maybe-no-diagnostics + +// D5-CHECK: error: 'error' diagnostics seen but not expected: +// D5-CHECK-NEXT: {{.*}} 'expected-no-diagnostics' directive cannot follow other expected directives +// D5-CHECK-NEXT: 1 error generated. +#endif + +#ifdef TEST_D6 +#error test_d6 +// expected-error@-1 {{test_d6}} +// expected-maybe-no-diagnostics +// expected-no-diagnostics + +// D6-CHECK: error: 'error' diagnostics seen but not expected: +// D6-CHECK-NEXT: {{.*}} 'expected-no-diagnostics' directive cannot follow other expected directives +// D6-CHECK-NEXT: 1 error generated. +#endif