Endill updated this revision to Diff 526013. Endill edited the summary of this revision. Endill added a comment.
Address feedback Docs contributed by @aaron.ballman Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151320/new/ https://reviews.llvm.org/D151320 Files: clang/include/clang/Frontend/VerifyDiagnosticConsumer.h clang/lib/Frontend/VerifyDiagnosticConsumer.cpp clang/test/Frontend/verify-maybe-no-diagnostics.c
Index: clang/test/Frontend/verify-maybe-no-diagnostics.c =================================================================== --- clang/test/Frontend/verify-maybe-no-diagnostics.c +++ clang/test/Frontend/verify-maybe-no-diagnostics.c @@ -2,7 +2,9 @@ // 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_C2 -verify %s 2>&1 | FileCheck --check-prefix=C2-CHECK %s +// RUN: %clang_cc1 -DTEST_C3 -verify %s +// RUN: not %clang_cc1 -DTEST_C4 -verify %s 2>&1 | FileCheck --check-prefix=C4-CHECK %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 @@ -31,11 +33,29 @@ #endif #ifdef TEST_C2 +// expected-maybe-no-diagnostics #error test_c2 -// expected-error@-1 {{test_c2}} + +// C2-CHECK: error: 'error' diagnostics seen but not expected: +// C2-CHECK-NEXT: {{test_c2}} +// C2-CHECK-NEXT: 1 error generated. +#endif + +#ifdef TEST_C3 +#error test_c3 +// expected-error@-1 {{test_c3}} // expected-maybe-no-diagnostics #endif +#ifdef TEST_C4 +#error test_c4 +// expected-maybe-no-diagnostics + +// C4-CHECK: error: 'error' diagnostics seen but not expected: +// C4-CHECK-NEXT: {{test_c4}} +// C4-CHECK-NEXT: 1 error generated. +#endif + #ifdef TEST_D1 // expected-maybe-no-diagnostics #error test_d1 Index: clang/lib/Frontend/VerifyDiagnosticConsumer.cpp =================================================================== --- clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -453,6 +453,7 @@ // Type in initial directive token: -{error|warning|note|no-diagnostics} bool NoDiag = false; + bool MaybeNoDiag = false; StringRef DType; if (DToken.endswith(DType="-error")) D.DL = ED ? &ED->Errors : nullptr; @@ -462,11 +463,9 @@ D.DL = ED ? &ED->Remarks : nullptr; else if (DToken.endswith(DType="-note")) D.DL = ED ? &ED->Notes : nullptr; - else if (DToken.endswith(DType="-maybe-no-diagnostics")) { - if (Status == VerifyDiagnosticConsumer::HasNoDirectives) - Status = VerifyDiagnosticConsumer::HasExpectedMaybeNoDiagnostics; - continue; - } else if (DToken.endswith(DType="-no-diagnostics")) { + else if (DToken.endswith(DType="-maybe-no-diagnostics")) + MaybeNoDiag = true; + else if (DToken.endswith(DType="-no-diagnostics")) { NoDiag = true; if (D.RegexKind) continue; @@ -481,6 +480,12 @@ if (!std::binary_search(Prefixes.begin(), Prefixes.end(), DToken)) continue; + if (MaybeNoDiag) { + if (Status == VerifyDiagnosticConsumer::HasNoDirectives) + Status = VerifyDiagnosticConsumer::HasExpectedMaybeNoDiagnostics; + continue; + } + if (NoDiag) { if (Status == VerifyDiagnosticConsumer::HasOtherExpectedDirectives) Diags.Report(Pos, diag::err_verify_invalid_no_diags) Index: clang/include/clang/Frontend/VerifyDiagnosticConsumer.h =================================================================== --- clang/include/clang/Frontend/VerifyDiagnosticConsumer.h +++ clang/include/clang/Frontend/VerifyDiagnosticConsumer.h @@ -183,6 +183,23 @@ /// // expected-no-diagnostics /// \endcode /// +/// Additionally, you can use: +/// +/// \code +/// // expected-maybe-no-diagnostics +/// \endcode +/// +/// to specify that a file with no "expected-*" comments should pass when no +/// diagnostics are generated, but doesn't conflict with "expected-*" directives +/// when they are present. This situation mostly comes up for DR conformance tests +/// where dozens of distinct test cases are within the same physical file but use +/// the 'split-file' utility to split individual test cases into logical files +/// at runtime. In that case, a header file containing "expected-maybe-no-diagnostics" +/// can be force included into each RUN line in the physical file. The tests that +/// expect diagostics continue to pass or fail depending on whether the correct +/// diagnostics are emitted, but they do not fail automatically due to a +/// combination of "expected-no-diagnostics" and "expected-*" within the same +/// test. The "expected-no-diagnostics" comment is almost always preferred. class VerifyDiagnosticConsumer: public DiagnosticConsumer, public CommentHandler { public:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits