[cfe-commits] r166281 - in /cfe/trunk: docs/InternalsManual.html include/clang/Basic/DiagnosticFrontendKinds.td include/clang/Frontend/VerifyDiagnosticConsumer.h lib/Frontend/VerifyDiagnosticConsumer.cpp test/ARCMT/verify.m test/Frontend/verify.c test/Frontend/verify2.c test/Frontend/verify3.c

Andy Gibbs andyg1001 at hotmail.co.uk
Fri Oct 19 05:49:32 PDT 2012


Author: andyg
Date: Fri Oct 19 07:49:32 2012
New Revision: 166281

URL: http://llvm.org/viewvc/llvm-project?rev=166281&view=rev
Log:
Change VerifyDiagnosticConsumer so that it *must* contain at least one "expected-*" directive.  As a result, for test-cases that are not expected to generate any diagnostics, an additional directive "expected-no-diagnostics" has been implemented which can then be included in such test-cases.  This new directive may not be used in conjunction with any other "expected-*" directive.

This change was initially proposed as a solution to the problem highlighted by check-in r164677, i.e. that -verify will not cause a test-case failure where the compile command does not actually reference the file.

Patch reviewed by David Blaikie.

Added:
    cfe/trunk/test/Frontend/verify3.c
Modified:
    cfe/trunk/docs/InternalsManual.html
    cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
    cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h
    cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp
    cfe/trunk/test/ARCMT/verify.m
    cfe/trunk/test/Frontend/verify.c
    cfe/trunk/test/Frontend/verify2.c

Modified: cfe/trunk/docs/InternalsManual.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/InternalsManual.html?rev=166281&r1=166280&r2=166281&view=diff
==============================================================================
--- cfe/trunk/docs/InternalsManual.html (original)
+++ cfe/trunk/docs/InternalsManual.html Fri Oct 19 07:49:32 2012
@@ -502,7 +502,9 @@
 Instead of formatting and printing out the diagnostics, this implementation just
 captures and remembers the diagnostics as they fly by.  Then -verify compares
 the list of produced diagnostics to the list of expected ones.  If they disagree,
-it prints out its own output.
+it prints out its own output.  Full documentation for the -verify mode can be
+found in the Clang API documentation for VerifyDiagnosticConsumer, <a
+href="/doxygen/classclang_1_1VerifyDiagnosticConsumer.html#details">here</a>.
 </p>
 
 <p>There are many other possible implementations of this interface, and this is

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=166281&r1=166280&r2=166281&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Fri Oct 19 07:49:32 2012
@@ -76,6 +76,11 @@
 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">;
+def err_verify_no_directives : Error<
+    "no expected directives found: consider use of 'expected-no-diagnostics'">;
 
 def note_fixit_applied : Note<"FIX-IT applied suggested code changes">;
 def note_fixit_in_macro : Note<

Modified: cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h?rev=166281&r1=166280&r2=166281&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h (original)
+++ cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h Fri Oct 19 07:49:32 2012
@@ -33,7 +33,9 @@
 /// Indicating that a line expects an error or a warning is simple. Put a
 /// comment on the line that has the diagnostic, use:
 ///
-///     expected-{error,warning,note}
+/// \code
+///   expected-{error,warning,note}
+/// \endcode
 ///
 /// to tag if it's an expected error or warning, and place the expected text
 /// between {{ and }} markers. The full text doesn't have to be included, only
@@ -94,12 +96,15 @@
 ///
 /// In this example, the diagnostic may appear only once, if at all.
 ///
-/// Regex matching mode may be selected by appending '-re' to type. Example:
+/// Regex matching mode may be selected by appending '-re' to type, such as:
 ///
+/// \code
 ///   expected-error-re
+/// \endcode
 ///
 /// Examples matching error: "variable has incomplete type 'struct s'"
 ///
+/// \code
 ///   // expected-error {{variable has incomplete type 'struct s'}}
 ///   // expected-error {{variable has incomplete type}}
 ///
@@ -107,6 +112,15 @@
 ///   // expected-error-re {{variable has has type 'struct .*'}}
 ///   // expected-error-re {{variable has has type 'struct (.*)'}}
 ///   // expected-error-re {{variable has has type 'struct[[:space:]](.*)'}}
+/// \endcode
+///
+/// VerifyDiagnosticConsumer expects at least one expected-* directive to
+/// be found inside the source code.  If no diagnostics are expected the
+/// following directive can be used to indicate this:
+///
+/// \code
+///   // expected-no-diagnostics
+/// \endcode
 ///
 class VerifyDiagnosticConsumer: public DiagnosticConsumer,
                                 public CommentHandler {
@@ -166,6 +180,13 @@
     }
   };
 
+  enum DirectiveStatus {
+    HasNoDirectives,
+    HasNoDirectivesReported,
+    HasExpectedNoDiagnostics,
+    HasOtherExpectedDirectives
+  };
+
 private:
   DiagnosticsEngine &Diags;
   DiagnosticConsumer *PrimaryClient;
@@ -175,6 +196,7 @@
   const LangOptions *LangOpts;
   SourceManager *SrcManager;
   unsigned ActiveSourceFiles;
+  DirectiveStatus Status;
   ExpectedData ED;
 
   void CheckDiagnostics();

Modified: cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp?rev=166281&r1=166280&r2=166281&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp Fri Oct 19 07:49:32 2012
@@ -31,7 +31,7 @@
   : Diags(_Diags),
     PrimaryClient(Diags.getClient()), OwnsPrimaryClient(Diags.ownsClient()),
     Buffer(new TextDiagnosticBuffer()), CurrentPreprocessor(0),
-    LangOpts(0), SrcManager(0), ActiveSourceFiles(0)
+    LangOpts(0), SrcManager(0), ActiveSourceFiles(0), Status(HasNoDirectives)
 {
   Diags.takeClient();
   if (Diags.hasSourceManager())
@@ -278,7 +278,8 @@
 ///
 /// Returns true if any valid directives were found.
 static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
-                           SourceLocation Pos, DiagnosticsEngine &Diags) {
+                           SourceLocation Pos, DiagnosticsEngine &Diags,
+                           VerifyDiagnosticConsumer::DirectiveStatus &Status) {
   // A single comment may contain multiple directives.
   bool FoundDirective = false;
   for (ParseHelper PH(S); !PH.Done();) {
@@ -300,10 +301,24 @@
       DL = ED ? &ED->Warnings : NULL;
     else if (PH.Next("note"))
       DL = ED ? &ED->Notes : NULL;
-    else
+    else if (PH.Next("no-diagnostics")) {
+      if (Status == VerifyDiagnosticConsumer::HasOtherExpectedDirectives)
+        Diags.Report(Pos, diag::err_verify_invalid_no_diags)
+          << /*IsExpectedNoDiagnostics=*/true;
+      else
+        Status = VerifyDiagnosticConsumer::HasExpectedNoDiagnostics;
+      continue;
+    } else
       continue;
     PH.Advance();
 
+    if (Status == VerifyDiagnosticConsumer::HasExpectedNoDiagnostics) {
+      Diags.Report(Pos, diag::err_verify_invalid_no_diags)
+        << /*IsExpectedNoDiagnostics=*/false;
+      continue;
+    }
+    Status = VerifyDiagnosticConsumer::HasOtherExpectedDirectives;
+
     // If a directive has been found but we're not interested
     // in storing the directive information, return now.
     if (!DL)
@@ -450,7 +465,7 @@
   // Fold any "\<EOL>" sequences
   size_t loc = C.find('\\');
   if (loc == StringRef::npos) {
-    ParseDirective(C, &ED, SM, CommentBegin, PP.getDiagnostics());
+    ParseDirective(C, &ED, SM, CommentBegin, PP.getDiagnostics(), Status);
     return false;
   }
 
@@ -480,7 +495,7 @@
   }
 
   if (!C2.empty())
-    ParseDirective(C2, &ED, SM, CommentBegin, PP.getDiagnostics());
+    ParseDirective(C2, &ED, SM, CommentBegin, PP.getDiagnostics(), Status);
   return false;
 }
 
@@ -505,6 +520,8 @@
 
   Token Tok;
   Tok.setKind(tok::comment);
+  VerifyDiagnosticConsumer::DirectiveStatus Status =
+    VerifyDiagnosticConsumer::HasNoDirectives;
   while (Tok.isNot(tok::eof)) {
     RawLex.Lex(Tok);
     if (!Tok.is(tok::comment)) continue;
@@ -514,7 +531,7 @@
 
     // Find first directive.
     if (ParseDirective(Comment, 0, SM, Tok.getLocation(),
-                       SM.getDiagnostics()))
+                       SM.getDiagnostics(), Status))
       return true;
   }
   return false;
@@ -718,6 +735,14 @@
 #endif // !NDEBUG
 
   if (SrcManager) {
+    // 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();
+      ++NumErrors;
+      Status = HasNoDirectivesReported;
+    }
+
     // Check that the expected diagnostics occurred.
     NumErrors += CheckResults(Diags, *SrcManager, *Buffer, ED);
   } else {

Modified: cfe/trunk/test/ARCMT/verify.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/verify.m?rev=166281&r1=166280&r2=166281&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/verify.m (original)
+++ cfe/trunk/test/ARCMT/verify.m Fri Oct 19 07:49:32 2012
@@ -8,6 +8,7 @@
 #error should not be ignored
 // expected-error at -1 {{should not be ignored}}
 
-//      CHECK: error: 'error' diagnostics seen but not expected:
+//      CHECK: error: no expected directives found: consider use of 'expected-no-diagnostics'
+// CHECK-NEXT: error: 'error' diagnostics seen but not expected:
 // CHECK-NEXT:   (frontend): error reading '{{.*}}verify.m.tmp.invalid'
-// CHECK-NEXT: 1 error generated.
+// CHECK-NEXT: 2 errors generated.

Modified: cfe/trunk/test/Frontend/verify.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/verify.c?rev=166281&r1=166280&r2=166281&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/verify.c (original)
+++ cfe/trunk/test/Frontend/verify.c Fri Oct 19 07:49:32 2012
@@ -111,9 +111,10 @@
 #if 0
 // RUN: %clang_cc1 -verify %t.invalid 2>&1 | FileCheck -check-prefix=CHECK6 %s
 
-//      CHECK6: error: 'error' diagnostics seen but not expected:
+//      CHECK6: error: no expected directives found: consider use of 'expected-no-diagnostics'
+// CHECK6-NEXT: error: 'error' diagnostics seen but not expected:
 // CHECK6-NEXT:   (frontend): error reading '{{.*}}verify.c.tmp.invalid'
-// CHECK6-NEXT: 1 error generated.
+// CHECK6-NEXT: 2 errors generated.
 
 // RUN: echo -e '//expected-error at 2{{1}}\n#error 2' | %clang_cc1 -verify 2>&1 | FileCheck -check-prefix=CHECK7 %s
 

Modified: cfe/trunk/test/Frontend/verify2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/verify2.c?rev=166281&r1=166280&r2=166281&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/verify2.c (original)
+++ cfe/trunk/test/Frontend/verify2.c Fri Oct 19 07:49:32 2012
@@ -3,7 +3,7 @@
 
 // Please note that all comments are inside "#if 0" blocks so that
 // VerifyDiagnosticConsumer sees no comments while processing this
-// test-case.
+// test-case (and hence no expected-* directives).
 #endif
 
 #include "verify2.h"
@@ -12,8 +12,9 @@
 #if 0
 // expected-error {{should be ignored}}
 
-//      CHECK: error: 'error' diagnostics seen but not expected:
+//      CHECK: error: no expected directives found: consider use of 'expected-no-diagnostics'
+// CHECK-NEXT: error: 'error' diagnostics seen but not expected:
 // CHECK-NEXT:   Line 1: header
 // CHECK-NEXT:   Line 10: source
-// CHECK-NEXT: 2 errors generated.
+// CHECK-NEXT: 3 errors generated.
 #endif

Added: cfe/trunk/test/Frontend/verify3.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/verify3.c?rev=166281&view=auto
==============================================================================
--- cfe/trunk/test/Frontend/verify3.c (added)
+++ cfe/trunk/test/Frontend/verify3.c Fri Oct 19 07:49:32 2012
@@ -0,0 +1,41 @@
+// This test-case runs several sub-tests on -verify to ensure that correct
+// diagnostics are generated in relation to the mis-use and non-use of the
+// 'expected-no-diagnostics' directive.
+
+// RUN: %clang_cc1 -DTEST1 -verify %s 2>&1 | FileCheck -check-prefix=CHECK1 %s
+#ifdef TEST1
+// expected-no-diagnostics
+// expected-note {{}}
+
+//      CHECK1: error: 'error' diagnostics seen but not expected:
+// CHECK1-NEXT:   Line 8: expected directive cannot follow 'expected-no-diagnostics' directive
+// CHECK1-NEXT: 1 error generated.
+#endif
+
+// RUN: %clang_cc1 -DTEST2 -verify %s 2>&1 | FileCheck -check-prefix=CHECK2 %s
+#ifdef TEST2
+#warning X
+// expected-warning at -1 {{X}}
+// expected-no-diagnostics
+
+//      CHECK2: error: 'error' diagnostics seen but not expected:
+// CHECK2-NEXT:   Line 19: 'expected-no-diagnostics' directive cannot follow other expected directives
+// CHECK2-NEXT: 1 error generated.
+#endif
+
+// RUN: %clang_cc1 -DTEST3 -verify %s 2>&1 | FileCheck -check-prefix=CHECK3 %s
+// RUN: %clang_cc1 -verify 2>&1 | FileCheck -check-prefix=CHECK3 %s
+#ifdef TEST3
+// no directives
+
+//      CHECK3: error: no expected directives found: consider use of 'expected-no-diagnostics'
+// CHECK3-NEXT: 1 error generated.
+#endif
+
+// RUN: %clang_cc1 -E -DTEST4 -verify %s 2>&1 | FileCheck -check-prefix=CHECK4 %s
+#ifdef TEST4
+#warning X
+// expected-warning at -1 {{X}}
+
+// CHECK4-NOT: error: no expected directives found: consider use of 'expected-no-diagnostics'
+#endif





More information about the cfe-commits mailing list