[llvm-branch-commits] [cfe-tag] r98891 - in /cfe/tags/cremebrulee/cremebrulee-46.1: include/clang/Frontend/PCHReader.h lib/Frontend/PCHReader.cpp

Ted Kremenek kremenek at apple.com
Thu Mar 18 15:52:33 PDT 2010


Author: kremenek
Date: Thu Mar 18 17:52:33 2010
New Revision: 98891

URL: http://llvm.org/viewvc/llvm-project?rev=98891&view=rev
Log:
Revert 98886.

Modified:
    cfe/tags/cremebrulee/cremebrulee-46.1/include/clang/Frontend/PCHReader.h
    cfe/tags/cremebrulee/cremebrulee-46.1/lib/Frontend/PCHReader.cpp

Modified: cfe/tags/cremebrulee/cremebrulee-46.1/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/tags/cremebrulee/cremebrulee-46.1/include/clang/Frontend/PCHReader.h?rev=98891&r1=98890&r2=98891&view=diff
==============================================================================
--- cfe/tags/cremebrulee/cremebrulee-46.1/include/clang/Frontend/PCHReader.h (original)
+++ cfe/tags/cremebrulee/cremebrulee-46.1/include/clang/Frontend/PCHReader.h Thu Mar 18 17:52:33 2010
@@ -132,9 +132,6 @@
                                     std::string &SuggestedPredefines);
   virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID);
   virtual void ReadCounter(unsigned Value);
-
-private:
-  void Error(const char *Msg);
 };
 
 /// \brief Reads a precompiled head containing the contents of a
@@ -157,7 +154,7 @@
     public ExternalSLocEntrySource {
 public:
   enum PCHReadResult { Success, Failure, IgnorePCH };
-  friend class PCHValidator;
+
 private:
   /// \ brief The receiver of some callbacks invoked by PCHReader.
   llvm::OwningPtr<PCHReaderListener> Listener;
@@ -475,7 +472,7 @@
   ///
   /// This routine should only be used for fatal errors that have to
   /// do with non-routine failures (e.g., corrupted PCH file).
-  void Error(const char *Msg);
+  bool Error(const char *Msg);
 
   PCHReader(const PCHReader&); // do not implement
   PCHReader &operator=(const PCHReader &); // do not implement
@@ -793,10 +790,6 @@
   uint64_t Offset;
 };
 
-inline void PCHValidator::Error(const char *Msg) {
-  Reader.Error(Msg);
-}
-
 } // end namespace clang
 
 #endif

Modified: cfe/tags/cremebrulee/cremebrulee-46.1/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/tags/cremebrulee/cremebrulee-46.1/lib/Frontend/PCHReader.cpp?rev=98891&r1=98890&r2=98891&view=diff
==============================================================================
--- cfe/tags/cremebrulee/cremebrulee-46.1/lib/Frontend/PCHReader.cpp (original)
+++ cfe/tags/cremebrulee/cremebrulee-46.1/lib/Frontend/PCHReader.cpp Thu Mar 18 17:52:33 2010
@@ -150,10 +150,7 @@
   std::pair<llvm::StringRef,llvm::StringRef> Split =
     llvm::StringRef(PP.getPredefines()).split(PCHInclude.str());
   llvm::StringRef Left =  Split.first, Right = Split.second;
-  if (Left == PP.getPredefines()) {
-    Error("Missing PCH include entry!");
-    return true;
-  }
+  assert(Left != PP.getPredefines() && "Missing PCH include entry!");
 
   // If the predefines is equal to the joined left and right halves, we're done!
   if (Left.size() + Right.size() == PCHPredef.size() &&
@@ -606,8 +603,10 @@
 typedef OnDiskChainedHashTable<PCHIdentifierLookupTrait>
   PCHIdentifierLookupTable;
 
-void PCHReader::Error(const char *Msg) {
-  Diag(diag::err_fe_pch_malformed) << Msg;
+bool PCHReader::Error(const char *Msg) {
+  unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Fatal, Msg);
+  Diag(DiagID);
+  return true;
 }
 
 /// \brief Check the contents of the predefines buffer against the
@@ -902,11 +901,6 @@
       return Failure;
     }
 
-    if (Record.size() < 8) {
-      Error("source location entry is incorrect");
-      return Failure;
-    }
-
     FileID FID = SourceMgr.createFileID(File,
                                 SourceLocation::getFromRawEncoding(Record[1]),
                                        (SrcMgr::CharacteristicKind)Record[2],
@@ -933,12 +927,8 @@
     Record.clear();
     unsigned RecCode
       = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen);
-
-    if (RecCode != pch::SM_SLOC_BUFFER_BLOB) {
-      Error("PCH record has invalid code");
-      return Failure;
-    }
-
+    assert(RecCode == pch::SM_SLOC_BUFFER_BLOB && "Ill-formed PCH file");
+    (void)RecCode;
     llvm::MemoryBuffer *Buffer
       = llvm::MemoryBuffer::getMemBuffer(BlobStart,
                                          BlobStart + BlobLen - 1,
@@ -1593,44 +1583,29 @@
     Context->setObjCFastEnumerationStateType(GetType(FastEnum));
   if (unsigned File = SpecialTypes[pch::SPECIAL_TYPE_FILE]) {
     QualType FileType = GetType(File);
-    if (FileType.isNull()) {
-      Error("FILE type is NULL");
-      return;
-    }
+    assert(!FileType.isNull() && "FILE type is NULL");
     if (const TypedefType *Typedef = FileType->getAs<TypedefType>())
       Context->setFILEDecl(Typedef->getDecl());
     else {
       const TagType *Tag = FileType->getAs<TagType>();
-      if (!Tag) {
-        Error("Invalid FILE type in PCH file");
-        return;
-      }
+      assert(Tag && "Invalid FILE type in PCH file");
       Context->setFILEDecl(Tag->getDecl());
     }
   }
   if (unsigned Jmp_buf = SpecialTypes[pch::SPECIAL_TYPE_jmp_buf]) {
     QualType Jmp_bufType = GetType(Jmp_buf);
-    if (Jmp_bufType.isNull()) {
-      Error("jmp_bug type is NULL");
-      return;
-    }
+    assert(!Jmp_bufType.isNull() && "jmp_bug type is NULL");
     if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>())
       Context->setjmp_bufDecl(Typedef->getDecl());
     else {
       const TagType *Tag = Jmp_bufType->getAs<TagType>();
-      if (!Tag) {
-        Error("Invalid jmp_bug type in PCH file");
-        return;
-      }
+      assert(Tag && "Invalid jmp_bug type in PCH file");
       Context->setjmp_bufDecl(Tag->getDecl());
     }
   }
   if (unsigned Sigjmp_buf = SpecialTypes[pch::SPECIAL_TYPE_sigjmp_buf]) {
     QualType Sigjmp_bufType = GetType(Sigjmp_buf);
-    if (Sigjmp_bufType.isNull()) {
-      Error("sigjmp_buf type is NULL");
-      return;
-    }
+    assert(!Sigjmp_bufType.isNull() && "sigjmp_buf type is NULL");
     if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>())
       Context->setsigjmp_bufDecl(Typedef->getDecl());
     else {
@@ -1847,65 +1822,45 @@
   unsigned Code = DeclsCursor.ReadCode();
   switch ((pch::TypeCode)DeclsCursor.ReadRecord(Code, Record)) {
   case pch::TYPE_EXT_QUAL: {
-    if (Record.size() != 2) {
-      Error("Incorrect encoding of extended qualifier type");
-      return QualType();
-    }
+    assert(Record.size() == 2 &&
+           "Incorrect encoding of extended qualifier type");
     QualType Base = GetType(Record[0]);
     Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]);
     return Context->getQualifiedType(Base, Quals);
   }
 
   case pch::TYPE_COMPLEX: {
-    if (Record.size() != 1) {
-      Error("Incorrect encoding of complex type");
-      return QualType();
-    }
+    assert(Record.size() == 1 && "Incorrect encoding of complex type");
     QualType ElemType = GetType(Record[0]);
     return Context->getComplexType(ElemType);
   }
 
   case pch::TYPE_POINTER: {
-    if (Record.size() != 1) {
-      Error("Incorrect encoding of pointer type");
-      return QualType();
-    }
+    assert(Record.size() == 1 && "Incorrect encoding of pointer type");
     QualType PointeeType = GetType(Record[0]);
     return Context->getPointerType(PointeeType);
   }
 
   case pch::TYPE_BLOCK_POINTER: {
-    if (Record.size() != 1) {
-      Error("Incorrect encoding of block pointer type");
-      return QualType();
-    }
+    assert(Record.size() == 1 && "Incorrect encoding of block pointer type");
     QualType PointeeType = GetType(Record[0]);
     return Context->getBlockPointerType(PointeeType);
   }
 
   case pch::TYPE_LVALUE_REFERENCE: {
-    if (Record.size() != 1) {
-      Error("Incorrect encoding of lvalue reference type");
-      return QualType();
-    }
+    assert(Record.size() == 1 && "Incorrect encoding of lvalue reference type");
     QualType PointeeType = GetType(Record[0]);
     return Context->getLValueReferenceType(PointeeType);
   }
 
   case pch::TYPE_RVALUE_REFERENCE: {
-    if (Record.size() != 1) {
-      Error("Incorrect encoding of rvalue reference type");
-      return QualType();
-    }
+    assert(Record.size() == 1 && "Incorrect encoding of rvalue reference type");
     QualType PointeeType = GetType(Record[0]);
     return Context->getRValueReferenceType(PointeeType);
   }
 
   case pch::TYPE_MEMBER_POINTER: {
-    if (Record.size() != 1) {
-      Error("Incorrect encoding of member pointer type");
-      return QualType();
-    }
+    assert(Record.size() == 1 && "Incorrect encoding of member pointer type");
     QualType PointeeType = GetType(Record[0]);
     QualType ClassType = GetType(Record[1]);
     return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr());
@@ -2001,10 +1956,7 @@
              cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0])));
 
   case pch::TYPE_TYPEDEF:
-    if (Record.size() != 1) {
-      Error("incorrect encoding of typedef type");
-      return QualType();
-    }
+    assert(Record.size() == 1 && "incorrect encoding of typedef type");
     return Context->getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0])));
 
   case pch::TYPE_TYPEOF_EXPR:
@@ -2023,24 +1975,15 @@
     return Context->getDecltypeType(ReadTypeExpr());
 
   case pch::TYPE_RECORD:
-    if (Record.size() != 1) {
-      Error("incorrect encoding of record type");
-      return QualType();
-    }
+    assert(Record.size() == 1 && "incorrect encoding of record type");
     return Context->getTypeDeclType(cast<RecordDecl>(GetDecl(Record[0])));
 
   case pch::TYPE_ENUM:
-    if (Record.size() != 1) {
-      Error("incorrect encoding of enum type");
-      return QualType();
-    }
+    assert(Record.size() == 1 && "incorrect encoding of enum type");
     return Context->getTypeDeclType(cast<EnumDecl>(GetDecl(Record[0])));
 
   case pch::TYPE_ELABORATED: {
-    if (Record.size() != 2) {
-      Error("incorrect encoding of elaborated type");
-      return QualType();
-    }
+    assert(Record.size() == 2 && "incorrect encoding of elaborated type");
     unsigned Tag = Record[1];
     return Context->getElaboratedType(GetType(Record[0]),
                                       (ElaboratedType::TagKind) Tag);
@@ -2385,12 +2328,8 @@
                                   llvm::SmallVectorImpl<pch::DeclID> &Decls) {
   assert(DC->hasExternalLexicalStorage() &&
          "DeclContext has no lexical decls in storage");
-
   uint64_t Offset = DeclContextOffsets[DC].first;
-  if (Offset == 0) {
-    Error("DeclContext has no lexical decls in storage");
-    return true;
-  }
+  assert(Offset && "DeclContext has no lexical decls in storage");
 
   // Keep track of where we are in the stream, then jump back there
   // after reading this context.
@@ -2402,10 +2341,8 @@
   RecordData Record;
   unsigned Code = DeclsCursor.ReadCode();
   unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
-  if (RecCode != pch::DECL_CONTEXT_LEXICAL) {
-    Error("Expected lexical block");
-    return true;
-  }
+  (void)RecCode;
+  assert(RecCode == pch::DECL_CONTEXT_LEXICAL && "Expected lexical block");
 
   // Load all of the declaration IDs
   Decls.clear();
@@ -2419,10 +2356,7 @@
   assert(DC->hasExternalVisibleStorage() &&
          "DeclContext has no visible decls in storage");
   uint64_t Offset = DeclContextOffsets[DC].second;
-  if (Offset == 0) {
-    Error("DeclContext has no visible decls in storage");
-    return true;
-  }
+  assert(Offset && "DeclContext has no visible decls in storage");
 
   // Keep track of where we are in the stream, then jump back there
   // after reading this context.
@@ -2434,11 +2368,8 @@
   RecordData Record;
   unsigned Code = DeclsCursor.ReadCode();
   unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
-  if (RecCode != pch::DECL_CONTEXT_VISIBLE) {
-    Error("Expected visible block");
-    return true;
-  }
-
+  (void)RecCode;
+  assert(RecCode == pch::DECL_CONTEXT_VISIBLE && "Expected visible block");
   if (Record.size() == 0)
     return false;
 





More information about the llvm-branch-commits mailing list