[cfe-commits] r135936 - in /cfe/trunk: include/clang/Frontend/VerifyDiagnosticsClient.h lib/Frontend/VerifyDiagnosticsClient.cpp

Axel Naumann Axel.Naumann at cern.ch
Mon Jul 25 12:18:12 PDT 2011


Author: axel
Date: Mon Jul 25 14:18:12 2011
New Revision: 135936

URL: http://llvm.org/viewvc/llvm-project?rev=135936&view=rev
Log:
Pick up expected diagnostics not only in the main file but also in the file where the first diagnostic occurred.
Useful if the main file is not relevant (like with cling).
By Vassil Vassilev.

Modified:
    cfe/trunk/include/clang/Frontend/VerifyDiagnosticsClient.h
    cfe/trunk/lib/Frontend/VerifyDiagnosticsClient.cpp

Modified: cfe/trunk/include/clang/Frontend/VerifyDiagnosticsClient.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/VerifyDiagnosticsClient.h?rev=135936&r1=135935&r2=135936&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/VerifyDiagnosticsClient.h (original)
+++ cfe/trunk/include/clang/Frontend/VerifyDiagnosticsClient.h Mon Jul 25 14:18:12 2011
@@ -70,6 +70,7 @@
   Preprocessor *CurrentPreprocessor;
 
 private:
+  FileID FirstErrorFID; // FileID of first diagnostic
   void CheckDiagnostics();
 
 public:

Modified: cfe/trunk/lib/Frontend/VerifyDiagnosticsClient.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/VerifyDiagnosticsClient.cpp?rev=135936&r1=135935&r2=135936&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/VerifyDiagnosticsClient.cpp (original)
+++ cfe/trunk/lib/Frontend/VerifyDiagnosticsClient.cpp Mon Jul 25 14:18:12 2011
@@ -52,6 +52,10 @@
 
 void VerifyDiagnosticsClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
                                               const DiagnosticInfo &Info) {
+  if (FirstErrorFID.isInvalid() && Info.hasSourceManager()) {
+    const SourceManager &SM = Info.getSourceManager();
+    FirstErrorFID = SM.getFileID(Info.getLocation());
+  }
   // Send the diagnostic to the buffer, we will check it once we reach the end
   // of the source file (or are destructed).
   Buffer->HandleDiagnostic(DiagLevel, Info);
@@ -323,14 +327,12 @@
 
 /// FindExpectedDiags - Lex the main source file to find all of the
 //   expected errors and warnings.
-static void FindExpectedDiags(Preprocessor &PP, ExpectedData &ED) {
-  // 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.
-  SourceManager &SM = PP.getSourceManager();
-  FileID FID = SM.getMainFileID();
-  if (SM.getMainFileID().isInvalid())
+static void FindExpectedDiags(Preprocessor &PP, ExpectedData &ED, FileID FID) {
+  // Create a raw lexer to pull all the comments out of FID.
+  if (FID.isInvalid())
     return;
 
+  SourceManager& SM = PP.getSourceManager();
   // Create a lexer to lex all the tokens of the main file in raw mode.
   const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID);
   Lexer RawLex(FID, FromFile, SM, PP.getLangOptions());
@@ -481,11 +483,21 @@
   // If we have a preprocessor, scan the source for expected diagnostic
   // markers. If not then any diagnostics are unexpected.
   if (CurrentPreprocessor) {
-    FindExpectedDiags(*CurrentPreprocessor, ED);
+    SourceManager &SM = CurrentPreprocessor->getSourceManager();
+    // Extract expected-error strings from main file.
+    FindExpectedDiags(*CurrentPreprocessor, ED, SM.getMainFileID());
+    // Only check for expectations in other diagnostic locations
+    // if they are not the main file (via ID or FileEntry) - the main
+    // file has already been looked at, and its expectations must not
+    // be added twice.
+    if (!FirstErrorFID.isInvalid() && FirstErrorFID != SM.getMainFileID()
+        && (!SM.getFileEntryForID(FirstErrorFID)
+            || (SM.getFileEntryForID(FirstErrorFID) !=
+                SM.getFileEntryForID(SM.getMainFileID()))))
+      FindExpectedDiags(*CurrentPreprocessor, ED, FirstErrorFID);
 
     // Check that the expected diagnostics occurred.
-    NumErrors += CheckResults(Diags, CurrentPreprocessor->getSourceManager(),
-                              *Buffer, ED);
+    NumErrors += CheckResults(Diags, SM, *Buffer, ED);
   } else {
     NumErrors += (PrintProblem(Diags, 0,
                                Buffer->err_begin(), Buffer->err_end(),





More information about the cfe-commits mailing list