[cfe-commits] r59924 - in /cfe/trunk: Driver/DiagChecker.cpp test/Sema/vla.c

Chris Lattner sabre at nondot.org
Sun Nov 23 15:38:26 PST 2008


Author: lattner
Date: Sun Nov 23 17:38:26 2008
New Revision: 59924

URL: http://llvm.org/viewvc/llvm-project?rev=59924&view=rev
Log:
clean up -verify mode output.  If the expected-error string is 
mangled, report it using the diagnostics machinery instead of printf.

Modified:
    cfe/trunk/Driver/DiagChecker.cpp
    cfe/trunk/test/Sema/vla.c

Modified: cfe/trunk/Driver/DiagChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/DiagChecker.cpp?rev=59924&r1=59923&r2=59924&view=diff

==============================================================================
--- cfe/trunk/Driver/DiagChecker.cpp (original)
+++ cfe/trunk/Driver/DiagChecker.cpp Sun Nov 23 17:38:26 2008
@@ -23,6 +23,12 @@
 typedef TextDiagnosticBuffer::DiagList DiagList;
 typedef TextDiagnosticBuffer::const_iterator const_diag_iterator;
 
+static void EmitError(Preprocessor &PP, SourceLocation Pos, const char *String){
+  unsigned ID = PP.getDiagnostics().getCustomDiagID(Diagnostic::Error, String);
+  PP.Diag(Pos, ID);
+}
+
+
 // USING THE DIAGNOSTIC CHECKER:
 //
 // Indicating that a line expects an error or a warning is simple. Put a comment
@@ -38,19 +44,17 @@
 // You can place as many diagnostics on one line as you wish. To make the code
 // more readable, you can use slash-newline to separate out the diagnostics.
 
-static const char * const ExpectedErrStr = "expected-error";
-static const char * const ExpectedWarnStr = "expected-warning";
-static const char * const ExpectedNoteStr = "expected-note";
-
 /// FindDiagnostics - Go through the comment and see if it indicates expected
 /// diagnostics. If so, then put them in a diagnostic list.
 /// 
 static void FindDiagnostics(const std::string &Comment,
                             DiagList &ExpectedDiags,
-                            SourceManager &SourceMgr,
+                            Preprocessor &PP,
                             SourceLocation Pos,
                             const char * const ExpectedStr) {
-  // Find all expected diagnostics
+  SourceManager &SourceMgr = PP.getSourceManager();
+  
+  // Find all expected diagnostics.
   typedef std::string::size_type size_type;
   size_type ColNo = 0;
 
@@ -61,27 +65,23 @@
     size_type OpenDiag = Comment.find("{{", ColNo);
 
     if (OpenDiag == std::string::npos) {
-      fprintf(stderr,
-              "oops:%d: Cannot find beginning of expected error string\n",
-              SourceMgr.getLogicalLineNumber(Pos));
-      break;
+      EmitError(PP, Pos,
+                "cannot find start ('{{') of expected diagnostic string");
+      return;
     }
 
     OpenDiag += 2;
     size_type CloseDiag = Comment.find("}}", OpenDiag);
 
     if (CloseDiag == std::string::npos) {
-      fprintf(stderr,
-              "oops:%d: Cannot find end of expected error string\n",
-              SourceMgr.getLogicalLineNumber(Pos));
-      break;
+      EmitError(PP, Pos,"cannot find end ('}}') of expected diagnostic string");
+      return;
     }
 
     std::string Msg(Comment.substr(OpenDiag, CloseDiag - OpenDiag));
     size_type FindPos;
-    while((FindPos = Msg.find("\\n")) != std::string::npos) {
+    while ((FindPos = Msg.find("\\n")) != std::string::npos)
       Msg.replace(FindPos, 2, "\n");
-    }
     ExpectedDiags.push_back(std::make_pair(Pos, Msg));
     ColNo = CloseDiag + 2;
   }
@@ -95,7 +95,6 @@
                               DiagList &ExpectedNotes) {
   // Create a raw lexer to pull all the comments out of the main file.  We don't
   // want to look in #include'd headers for expected-error strings.
-  
   unsigned FileID = PP.getSourceManager().getMainFileID();
   std::pair<const char*,const char*> File =
     PP.getSourceManager().getBufferData(FileID);
@@ -108,25 +107,25 @@
   RawLex.SetCommentRetentionState(true);
 
   Token Tok;
-  do {
+  Tok.setKind(tok::comment);
+  while (Tok.isNot(tok::eof)) {
     RawLex.Lex(Tok);
-
-    if (Tok.is(tok::comment)) {
-      std::string Comment = PP.getSpelling(Tok);
-
-      // Find all expected errors
-      FindDiagnostics(Comment, ExpectedErrors, PP.getSourceManager(),
-                      Tok.getLocation(), ExpectedErrStr);
-
-      // Find all expected warnings
-      FindDiagnostics(Comment, ExpectedWarnings, PP.getSourceManager(),
-                      Tok.getLocation(), ExpectedWarnStr);
-
-      // Find all expected notes
-      FindDiagnostics(Comment, ExpectedNotes, PP.getSourceManager(),
-                      Tok.getLocation(), ExpectedNoteStr);
-    }
-  } while (Tok.isNot(tok::eof));
+    if (!Tok.is(tok::comment)) continue;
+    
+    std::string Comment = PP.getSpelling(Tok);
+
+    // Find all expected errors.
+    FindDiagnostics(Comment, ExpectedErrors, PP,
+                    Tok.getLocation(), "expected-error");
+
+    // Find all expected warnings.
+    FindDiagnostics(Comment, ExpectedWarnings, PP,
+                    Tok.getLocation(), "expected-warning");
+
+    // Find all expected notes.
+    FindDiagnostics(Comment, ExpectedNotes, PP,
+                    Tok.getLocation(), "expected-note");
+  };
 }
 
 /// PrintProblem - This takes a diagnostic map of the delta between expected and

Modified: cfe/trunk/test/Sema/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vla.c?rev=59924&r1=59923&r2=59924&view=diff

==============================================================================
--- cfe/trunk/test/Sema/vla.c (original)
+++ cfe/trunk/test/Sema/vla.c Sun Nov 23 17:38:26 2008
@@ -14,5 +14,5 @@
 }
 
 // PR3048
-int x = sizeof(struct{char qq[x];}); // expected-error {{fields must have a constant size}}
+int x = sizeof(struct{char qq[x];}); // expected-error {{fields must have a constant size}
 





More information about the cfe-commits mailing list