[cfe-commits] r67462 - in /cfe/trunk: Driver/clang.cpp include/clang/Lex/PTHManager.h lib/Lex/PTHLexer.cpp

Ted Kremenek kremenek at apple.com
Sat Mar 21 23:42:40 PDT 2009


Author: kremenek
Date: Sun Mar 22 01:42:39 2009
New Revision: 67462

URL: http://llvm.org/viewvc/llvm-project?rev=67462&view=rev
Log:
PTHManager::Create():
- Make the Diagnostic::Level for PTH errors to be specified by the caller

clang (driver):
- Set the PTHManager diagnostic level to "Diagnostic::Error" for -include-pth
  (a hard error) and Diagnostic::Warning for -token-cache (we can still
  proceed).

Modified:
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/include/clang/Lex/PTHManager.h
    cfe/trunk/lib/Lex/PTHLexer.cpp

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=67462&r1=67461&r2=67462&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Sun Mar 22 01:42:39 2009
@@ -1156,15 +1156,20 @@
     if (!TokenCache.empty() && !ImplicitIncludePTH.empty()) {
       fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
                       "options\n");
-      exit (1);
+      exit(1);
     }
     
     // Use PTH?
     if (!TokenCache.empty() || !ImplicitIncludePTH.empty()) {
       const std::string& x = TokenCache.empty() ? ImplicitIncludePTH:TokenCache;
-      PTHMgr.reset(PTHManager::Create(x, &Diags));
+      PTHMgr.reset(PTHManager::Create(x, &Diags, 
+                                      TokenCache.empty() ? Diagnostic::Error
+                                                        : Diagnostic::Warning));
     }
     
+    if (Diags.hasErrorOccurred())
+      exit(1);
+    
     // Create the Preprocessor.
     llvm::OwningPtr<Preprocessor> PP(new Preprocessor(Diags, LangInfo, Target,
                                                       SourceMgr, HeaderInfo,

Modified: cfe/trunk/include/clang/Lex/PTHManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PTHManager.h?rev=67462&r1=67461&r2=67462&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/PTHManager.h (original)
+++ cfe/trunk/include/clang/Lex/PTHManager.h Sun Mar 22 01:42:39 2009
@@ -17,6 +17,7 @@
 #include "clang/Lex/PTHLexer.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/Diagnostic.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/Allocator.h"
 #include <string>
@@ -118,7 +119,8 @@
   
   /// Create - This method creates PTHManager objects.  The 'file' argument
   ///  is the name of the PTH file.  This method returns NULL upon failure.
-  static PTHManager *Create(const std::string& file, Diagnostic* Diags = 0);
+  static PTHManager *Create(const std::string& file, Diagnostic* Diags = 0,
+                            Diagnostic::Level failureLevel=Diagnostic::Warning);
 
   void setPreprocessor(Preprocessor *pp) { PP = pp; }    
   

Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=67462&r1=67461&r2=67462&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Sun Mar 22 01:42:39 2009
@@ -583,21 +583,23 @@
   free(PerIDCache);
 }
 
-static void InvalidPTH(Diagnostic *Diags, const char* Msg = 0) {
+static void InvalidPTH(Diagnostic *Diags, Diagnostic::Level level,
+                       const char* Msg = 0) {
   if (!Diags) return;  
   if (!Msg) Msg = "Invalid or corrupted PTH file";
-  unsigned DiagID = Diags->getCustomDiagID(Diagnostic::Warning, Msg);
+  unsigned DiagID = Diags->getCustomDiagID(level, Msg);
   Diags->Report(FullSourceLoc(), DiagID);
 }
 
-PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags) {
+PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
+                               Diagnostic::Level level) {
   // Memory map the PTH file.
   llvm::OwningPtr<llvm::MemoryBuffer>
   File(llvm::MemoryBuffer::getFile(file.c_str()));
   
   if (!File) {
     if (Diags) {
-      unsigned DiagID = Diags->getCustomDiagID(Diagnostic::Warning,
+      unsigned DiagID = Diags->getCustomDiagID(level,
                                                "PTH file %0 could not be read");
       Diags->Report(FullSourceLoc(), DiagID) << file;
     }
@@ -613,7 +615,7 @@
   // Check the prologue of the file.
   if ((BufEnd - BufBeg) < (signed) (sizeof("cfe-pth") + 3 + 4) ||
       memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth") - 1) != 0) {
-    InvalidPTH(Diags);
+    InvalidPTH(Diags, level);
     return 0;
   }
   
@@ -622,7 +624,7 @@
   unsigned Version = ReadLE32(p);
   
   if (Version != PTHManager::Version) {
-    InvalidPTH(Diags,
+    InvalidPTH(Diags, level,
         Version < PTHManager::Version 
         ? "PTH file uses an older PTH format that is no longer supported"
         : "PTH file uses a newer PTH format that cannot be read");
@@ -633,7 +635,7 @@
   const unsigned char *PrologueOffset = p;
   
   if (PrologueOffset >= BufEnd) {
-    InvalidPTH(Diags);
+    InvalidPTH(Diags, level);
     return 0;
   }
   
@@ -643,7 +645,7 @@
   const unsigned char* FileTable = BufBeg + ReadLE32(FileTableOffset);
   
   if (!(FileTable > BufBeg && FileTable < BufEnd)) {
-    InvalidPTH(Diags);
+    InvalidPTH(Diags, level);
     return 0; // FIXME: Proper error diagnostic?
   }
   
@@ -652,7 +654,7 @@
   // Warn if the PTH file is empty.  We still want to create a PTHManager
   // as the PTH could be used with -include-pth.
   if (FL->isEmpty())
-    InvalidPTH(Diags, "PTH file contains no cached source data");
+    InvalidPTH(Diags, level, "PTH file contains no cached source data");
   
   // Get the location of the table mapping from persistent ids to the
   // data needed to reconstruct identifiers.
@@ -660,7 +662,7 @@
   const unsigned char* IData = BufBeg + ReadLE32(IDTableOffset);
   
   if (!(IData >= BufBeg && IData < BufEnd)) {
-    InvalidPTH(Diags);
+    InvalidPTH(Diags, level);
     return 0;
   }
   
@@ -669,23 +671,18 @@
   const unsigned char* StringIdTableOffset = PrologueOffset + sizeof(uint32_t)*1;
   const unsigned char* StringIdTable = BufBeg + ReadLE32(StringIdTableOffset);
   if (!(StringIdTable >= BufBeg && StringIdTable < BufEnd)) {
-    InvalidPTH(Diags);
+    InvalidPTH(Diags, level);
     return 0;
   }
 
   llvm::OwningPtr<PTHStringIdLookup> SL(PTHStringIdLookup::Create(StringIdTable,
                                                                   BufBeg));
   
-  // Issue a warning about the PTH file containing no identifiers.                                                                
-  if (!FL->isEmpty() && SL->isEmpty()) {
-    InvalidPTH(Diags, "PTH file contains no identifiers.");
-  }
-
   // Get the location of the spelling cache.
   const unsigned char* spellingBaseOffset = PrologueOffset + sizeof(uint32_t)*3;
   const unsigned char* spellingBase = BufBeg + ReadLE32(spellingBaseOffset);
   if (!(spellingBase >= BufBeg && spellingBase < BufEnd)) {
-    InvalidPTH(Diags);
+    InvalidPTH(Diags, level);
     return 0;
   }
   
@@ -700,7 +697,8 @@
   if (NumIds) {
     PerIDCache = (IdentifierInfo**)calloc(NumIds, sizeof(*PerIDCache));  
     if (!PerIDCache) {
-      InvalidPTH(Diags, "Could not allocate memory for processing PTH file");
+      InvalidPTH(Diags, level, 
+                 "Could not allocate memory for processing PTH file");
       return 0;
     }
   }





More information about the cfe-commits mailing list