[cfe-commits] r107087 - in /cfe/trunk: include/clang/Frontend/PCHReader.h include/clang/Frontend/PCHWriter.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHReaderStmt.cpp lib/Frontend/PCHWriter.cpp lib/Frontend/PCHWriterStmt.cpp test/PCH/exprs.c test/PCH/exprs.h

Douglas Gregor dgregor at apple.com
Tue Jun 29 07:52:18 PDT 2010


Very nice!

On Jun 28, 2010, at 3:28 PM, Argyrios Kyrtzidis wrote:

> Author: akirtzidis
> Date: Mon Jun 28 17:28:35 2010
> New Revision: 107087
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=107087&view=rev
> Log:
> Modify the way sub-statements are stored and retrieved from PCH.
> 
> Before this commit, sub-stmts were stored as encountered and when they were placed in the Stmts stack we had to know what index
> each stmt operand has. This complicated supporting variable sub-stmts and sub-stmts that were contained in TypeSourceInfos, e.g.
> 
> x = sizeof(int[1]);
> 
> would crash PCH.
> 
> Now, sub-stmts are stored in reverse order, from last to first, so that when reading them, in order to get the next sub-stmt we just
> need to pop the last stmt from the stack. This greatly simplified the way stmts are written and read (just use PCHWriter::AddStmt and
> PCHReader::ReadStmt accordingly) and allowed variable stmt operands and TypeSourceInfo exprs.
> 
> Modified:
>    cfe/trunk/include/clang/Frontend/PCHReader.h
>    cfe/trunk/include/clang/Frontend/PCHWriter.h
>    cfe/trunk/lib/Frontend/PCHReader.cpp
>    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
>    cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
>    cfe/trunk/lib/Frontend/PCHWriter.cpp
>    cfe/trunk/lib/Frontend/PCHWriterStmt.cpp
>    cfe/trunk/test/PCH/exprs.c
>    cfe/trunk/test/PCH/exprs.h
> 
> Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=107087&r1=107086&r2=107087&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
> +++ cfe/trunk/include/clang/Frontend/PCHReader.h Mon Jun 28 17:28:35 2010
> @@ -449,6 +449,34 @@
>   /// Objective-C protocols.
>   llvm::SmallVector<Decl *, 16> InterestingDecls;
> 
> +  /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
> +  llvm::SmallVector<Stmt *, 16> StmtStack;
> +
> +  /// \brief What kind of records we are reading.
> +  enum ReadingKind {
> +    Read_Decl, Read_Type, Read_Stmt
> +  };
> +
> +  /// \brief What kind of records we are reading. 
> +  ReadingKind ReadingKind;
> +
> +  /// \brief RAII object to change the reading kind.
> +  class ReadingKindTracker {
> +    PCHReader &Reader;
> +    enum ReadingKind PrevKind;
> +
> +    ReadingKindTracker(const ReadingKindTracker&); // do not implement
> +    ReadingKindTracker &operator=(const ReadingKindTracker&);// do not implement
> +
> +  public:
> +    ReadingKindTracker(enum ReadingKind newKind, PCHReader &reader)
> +      : Reader(reader), PrevKind(Reader.ReadingKind) {
> +      Reader.ReadingKind = newKind;
> +    }
> +
> +    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
> +  };
> +
>   /// \brief The file ID for the predefines buffer in the PCH file.
>   FileID PCHPredefinesBufferID;
> 
> @@ -469,6 +497,9 @@
>   /// predefines buffer may contain additional definitions.
>   std::string SuggestedPredefines;
> 
> +  /// \brief Reads a statement from the specified cursor.
> +  Stmt *ReadStmtFromStream(llvm::BitstreamCursor &Cursor);
> +
>   void MaybeAddSystemRootToFilename(std::string &Filename);
> 
>   PCHReadResult ReadPCHBlock();
> @@ -563,19 +594,6 @@
>   /// \brief Read preprocessed entities into the 
>   virtual void ReadPreprocessedEntities();
> 
> -  /// \brief Abstract interface for reading expressions.
> -  class ExprReader {
> -  public:
> -    virtual Expr *Read();
> -  };
> -
> -  /// \brief Reads a TemplateArgumentLocInfo appropriate for the
> -  /// given TemplateArgument kind.
> -  TemplateArgumentLocInfo
> -  GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,
> -                             const RecordData &Record, unsigned &Idx,
> -                             ExprReader &ExprRdr);
> -
>   /// \brief Reads a TemplateArgumentLocInfo appropriate for the
>   /// given TemplateArgument kind.
>   TemplateArgumentLocInfo
> @@ -584,11 +602,6 @@
> 
>   /// \brief Reads a TemplateArgumentLoc.
>   TemplateArgumentLoc ReadTemplateArgumentLoc(const RecordData &Record,
> -                                              unsigned &Idx,
> -                                              ExprReader &ExprRdr);
> -
> -  /// \brief Reads a TemplateArgumentLoc.
> -  TemplateArgumentLoc ReadTemplateArgumentLoc(const RecordData &Record,
>                                               unsigned &Idx);
> 
>   /// \brief Reads a declarator info from the given record.
> @@ -719,10 +732,6 @@
>   TemplateName ReadTemplateName(const RecordData &Record, unsigned &Idx);
> 
>   /// \brief Read a template argument.
> -  TemplateArgument ReadTemplateArgument(const RecordData &Record,unsigned &Idx,
> -                                        ExprReader &ExprRdr);
> -
> -  /// \brief Read a template argument.
>   TemplateArgument ReadTemplateArgument(const RecordData &Record,unsigned &Idx);
> 
>   /// \brief Read a template parameter list.
> @@ -759,19 +768,11 @@
>   /// \brief Reads attributes from the current stream position.
>   Attr *ReadAttributes();
> 
> -  /// \brief ReadDeclExpr - Reads an expression from the current decl cursor.
> -  Expr *ReadDeclExpr();
> -
> -  /// \brief ReadTypeExpr - Reads an expression from the current type cursor.
> -  Expr *ReadTypeExpr();
> +  /// \brief Reads a statement.
> +  Stmt *ReadStmt();
> 
> -  /// \brief Reads a statement from the specified cursor.
> -  Stmt *ReadStmt(llvm::BitstreamCursor &Cursor);
> -
> -  /// \brief Read a statement from the current DeclCursor.
> -  Stmt *ReadDeclStmt() {
> -    return ReadStmt(DeclsCursor);
> -  }
> +  /// \brief Reads an expression.
> +  Expr *ReadExpr();
> 
>   /// \brief Reads the macro record located at the given offset.
>   void ReadMacroRecord(uint64_t Offset);
> 
> Modified: cfe/trunk/include/clang/Frontend/PCHWriter.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHWriter.h?rev=107087&r1=107086&r2=107087&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Frontend/PCHWriter.h (original)
> +++ cfe/trunk/include/clang/Frontend/PCHWriter.h Mon Jun 28 17:28:35 2010
> @@ -189,7 +189,11 @@
> 
>   /// \brief Statements that we've encountered while serializing a
>   /// declaration or type.
> -  llvm::SmallVector<Stmt *, 8> StmtsToEmit;
> +  llvm::SmallVector<Stmt *, 16> StmtsToEmit;
> +  
> +  /// \brief Statements collection to use for PCHWriter::AddStmt().
> +  /// It will point to StmtsToEmit unless it is overriden. 
> +  llvm::SmallVector<Stmt *, 16> *CollectedStmts;
> 
>   /// \brief Mapping from SwitchCase statements to IDs.
>   std::map<SwitchCase *, unsigned> SwitchCaseIDs;
> @@ -211,8 +215,8 @@
>   /// file.
>   unsigned NumVisibleDeclContexts;
> 
> -  /// \brief True when we are in Stmts emitting mode.
> -  bool EmittingStmts;
> +  /// \brief Write the given subexpression to the bitstream.
> +  void WriteSubStmt(Stmt *S);
> 
>   void WriteBlockInfoBlock();
>   void WriteMetadata(ASTContext &Context, const char *isysroot);
> @@ -359,15 +363,9 @@
>   /// the corresponding statements just after the type or
>   /// declaration.
>   void AddStmt(Stmt *S) {
> -    if (EmittingStmts)
> -      WriteSubStmt(S);
> -    else
> -      StmtsToEmit.push_back(S);
> +      CollectedStmts->push_back(S);
>   }
> 
> -  /// \brief Write the given subexpression to the bitstream.
> -  void WriteSubStmt(Stmt *S);
> -
>   /// \brief Flush all of the statements and expressions that have
>   /// been added to the queue via AddStmt().
>   void FlushStmts();
> 
> Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=107087&r1=107086&r2=107087&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
> +++ cfe/trunk/lib/Frontend/PCHReader.cpp Mon Jun 28 17:28:35 2010
> @@ -321,18 +321,6 @@
> // PCH reader implementation
> //===----------------------------------------------------------------------===//
> 
> -// Give ExprReader's VTable a home.
> -Expr *PCHReader::ExprReader::Read() { return 0; }
> -
> -namespace {
> -  class DeclExprReader : public PCHReader::ExprReader {
> -    PCHReader &Reader;
> -  public:
> -    DeclExprReader(PCHReader &reader) : Reader(reader) { }
> -    virtual Expr *Read() { return Reader.ReadDeclExpr(); }
> -  };
> -} // anonymous namespace
> -
> PCHReader::PCHReader(Preprocessor &PP, ASTContext *Context,
>                      const char *isysroot)
>   : Listener(new PCHValidator(PP, *this)), SourceMgr(PP.getSourceManager()),
> @@ -372,14 +360,6 @@
> 
> PCHReader::~PCHReader() {}
> 
> -Expr *PCHReader::ReadDeclExpr() {
> -  return dyn_cast_or_null<Expr>(ReadStmt(DeclsCursor));
> -}
> -
> -Expr *PCHReader::ReadTypeExpr() {
> -  return dyn_cast_or_null<Expr>(ReadStmt(DeclsCursor));
> -}
> -
> 
> namespace {
> class PCHMethodPoolLookupTrait {
> @@ -1969,6 +1949,8 @@
>   // after reading this type.
>   SavedStreamPosition SavedPosition(DeclsCursor);
> 
> +  ReadingKindTracker ReadingKind(Read_Type, *this);
> +  
>   // Note that we are loading a type record.
>   LoadingTypeOrDecl Loading(*this);
> 
> @@ -2064,7 +2046,7 @@
>     unsigned IndexTypeQuals = Record[2];
>     SourceLocation LBLoc = SourceLocation::getFromRawEncoding(Record[3]);
>     SourceLocation RBLoc = SourceLocation::getFromRawEncoding(Record[4]);
> -    return Context->getVariableArrayType(ElementType, ReadTypeExpr(),
> +    return Context->getVariableArrayType(ElementType, ReadExpr(),
>                                          ASM, IndexTypeQuals,
>                                          SourceRange(LBLoc, RBLoc));
>   }
> @@ -2141,7 +2123,7 @@
>     return Context->getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0])));
> 
>   case pch::TYPE_TYPEOF_EXPR:
> -    return Context->getTypeOfExprType(ReadTypeExpr());
> +    return Context->getTypeOfExprType(ReadExpr());
> 
>   case pch::TYPE_TYPEOF: {
>     if (Record.size() != 1) {
> @@ -2153,7 +2135,7 @@
>   }
> 
>   case pch::TYPE_DECLTYPE:
> -    return Context->getDecltypeType(ReadTypeExpr());
> +    return Context->getDecltypeType(ReadExpr());
> 
>   case pch::TYPE_RECORD:
>     if (Record.size() != 1) {
> @@ -2319,7 +2301,7 @@
>   TL.setLBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   TL.setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   if (Record[Idx++])
> -    TL.setSizeExpr(Reader.ReadDeclExpr());
> +    TL.setSizeExpr(Reader.ReadExpr());
>   else
>     TL.setSizeExpr(0);
> }
> @@ -2511,10 +2493,10 @@
> TemplateArgumentLocInfo
> PCHReader::GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,
>                                       const RecordData &Record,
> -                                      unsigned &Index, ExprReader &ExprRdr) {
> +                                      unsigned &Index) {
>   switch (Kind) {
>   case TemplateArgument::Expression:
> -    return ExprRdr.Read();
> +    return ReadExpr();
>   case TemplateArgument::Type:
>     return GetTypeSourceInfo(Record, Index);
>   case TemplateArgument::Template: {
> @@ -2532,32 +2514,16 @@
>   return TemplateArgumentLocInfo();
> }
> 
> -TemplateArgumentLocInfo
> -PCHReader::GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,
> -                                      const RecordData &Record,
> -                                      unsigned &Index) {
> -  DeclExprReader DeclExprReader(*this);
> -  return GetTemplateArgumentLocInfo(Kind, Record, Index, DeclExprReader);
> -}
> -
> TemplateArgumentLoc
> -PCHReader::ReadTemplateArgumentLoc(const RecordData &Record, unsigned &Index,
> -                                   ExprReader &ExprRdr) {
> -  TemplateArgument Arg = ReadTemplateArgument(Record, Index, ExprRdr);
> +PCHReader::ReadTemplateArgumentLoc(const RecordData &Record, unsigned &Index) {
> +  TemplateArgument Arg = ReadTemplateArgument(Record, Index);
> 
>   if (Arg.getKind() == TemplateArgument::Expression) {
>     if (Record[Index++]) // bool InfoHasSameExpr.
>       return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr()));
>   }
>   return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(Arg.getKind(),
> -                                                             Record, Index,
> -                                                             ExprRdr));
> -}
> -
> -TemplateArgumentLoc
> -PCHReader::ReadTemplateArgumentLoc(const RecordData &Record, unsigned &Index) {
> -  DeclExprReader DeclExprReader(*this);
> -  return ReadTemplateArgumentLoc(Record, Index, DeclExprReader);
> +                                                             Record, Index));
> }
> 
> Decl *PCHReader::GetExternalDecl(uint32_t ID) {
> @@ -2589,7 +2555,7 @@
>   // Since we know tha this statement is part of a decl, make sure to use the
>   // decl cursor to read it.
>   DeclsCursor.JumpToBit(Offset);
> -  return ReadStmt(DeclsCursor);
> +  return ReadStmtFromStream(DeclsCursor);
> }
> 
> bool PCHReader::FindExternalLexicalDecls(const DeclContext *DC,
> @@ -3034,8 +3000,7 @@
> }
> 
> TemplateArgument
> -PCHReader::ReadTemplateArgument(const RecordData &Record, unsigned &Idx,
> -                                ExprReader &ExprRdr) {
> +PCHReader::ReadTemplateArgument(const RecordData &Record, unsigned &Idx) {
>   switch ((TemplateArgument::ArgKind)Record[Idx++]) {
>   case TemplateArgument::Null:
>     return TemplateArgument();
> @@ -3051,13 +3016,13 @@
>   case TemplateArgument::Template:
>     return TemplateArgument(ReadTemplateName(Record, Idx));
>   case TemplateArgument::Expression:
> -    return TemplateArgument(ExprRdr.Read());
> +    return TemplateArgument(ReadExpr());
>   case TemplateArgument::Pack: {
>     unsigned NumArgs = Record[Idx++];
>     llvm::SmallVector<TemplateArgument, 8> Args;
>     Args.reserve(NumArgs);
>     while (NumArgs--)
> -      Args.push_back(ReadTemplateArgument(Record, Idx, ExprRdr));
> +      Args.push_back(ReadTemplateArgument(Record, Idx));
>     TemplateArgument TemplArg;
>     TemplArg.setArgumentPack(Args.data(), Args.size(), /*CopyArgs=*/true);
>     return TemplArg;
> @@ -3068,12 +3033,6 @@
>   return TemplateArgument();
> }
> 
> -TemplateArgument
> -PCHReader::ReadTemplateArgument(const RecordData &Record, unsigned &Idx) {
> -  DeclExprReader DeclExprReader(*this);
> -  return ReadTemplateArgument(Record, Idx, DeclExprReader);
> -}
> -
> TemplateParameterList *
> PCHReader::ReadTemplateParameterList(const RecordData &Record, unsigned &Idx) {
>   SourceLocation TemplateLoc = ReadSourceLocation(Record, Idx);
> 
> Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=107087&r1=107086&r2=107087&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
> +++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Mon Jun 28 17:28:35 2010
> @@ -184,7 +184,7 @@
> void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
>   VisitValueDecl(ECD);
>   if (Record[Idx++])
> -    ECD->setInitExpr(Reader.ReadDeclExpr());
> +    ECD->setInitExpr(Reader.ReadExpr());
>   ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
> }
> 
> @@ -299,7 +299,7 @@
>   if (Record[Idx++]) {
>     // In practice, this won't be executed (since method definitions
>     // don't occur in header files).
> -    MD->setBody(Reader.ReadDeclStmt());
> +    MD->setBody(Reader.ReadStmt());
>     MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
>     MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
>   }
> @@ -493,7 +493,7 @@
>   VisitDeclaratorDecl(FD);
>   FD->setMutable(Record[Idx++]);
>   if (Record[Idx++])
> -    FD->setBitWidth(Reader.ReadDeclExpr());
> +    FD->setBitWidth(Reader.ReadExpr());
> }
> 
> void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
> @@ -508,7 +508,7 @@
>   VD->setPreviousDeclaration(
>                          cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
>   if (Record[Idx++])
> -    VD->setInit(Reader.ReadDeclExpr());
> +    VD->setInit(Reader.ReadExpr());
> }
> 
> void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
> @@ -523,12 +523,12 @@
> 
> void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
>   VisitDecl(AD);
> -  AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
> +  AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr()));
> }
> 
> void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
>   VisitDecl(BD);
> -  BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
> +  BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt()));
>   BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
>   unsigned NumParams = Record[Idx++];
>   llvm::SmallVector<ParmVarDecl *, 16> Params;
> @@ -861,7 +861,7 @@
>   D->setPosition(Record[Idx++]);
>   // Rest of NonTypeTemplateParmDecl.
>   if (Record[Idx++]) {
> -    Expr *DefArg = Reader.ReadDeclExpr();
> +    Expr *DefArg = Reader.ReadExpr();
>     bool Inherited = Record[Idx++];
>     D->setDefaultArgument(DefArg, Inherited);
>  }
> @@ -1106,6 +1106,8 @@
>   // after reading this declaration.
>   SavedStreamPosition SavedPosition(DeclsCursor);
> 
> +  ReadingKindTracker ReadingKind(Read_Decl, *this);
> +
>   // Note that we are loading a declaration record.
>   LoadingTypeOrDecl Loading(*this);
> 
> 
> Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=107087&r1=107086&r2=107087&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
> +++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Mon Jun 28 17:28:35 2010
> @@ -19,16 +19,15 @@
> 
> namespace {
> 
> -  class PCHStmtReader : public StmtVisitor<PCHStmtReader, unsigned> {
> +  class PCHStmtReader : public StmtVisitor<PCHStmtReader> {
>     PCHReader &Reader;
>     const PCHReader::RecordData &Record;
>     unsigned &Idx;
> -    llvm::SmallVectorImpl<Stmt *> &StmtStack;
> 
>   public:
>     PCHStmtReader(PCHReader &Reader, const PCHReader::RecordData &Record,
> -                  unsigned &Idx, llvm::SmallVectorImpl<Stmt *> &StmtStack)
> -      : Reader(Reader), Record(Record), Idx(Idx), StmtStack(StmtStack) { }
> +                  unsigned &Idx)
> +      : Reader(Reader), Record(Record), Idx(Idx) { }
> 
>     /// \brief The number of record fields required for the Stmt class
>     /// itself.
> @@ -39,225 +38,194 @@
>     static const unsigned NumExprFields = NumStmtFields + 3;
> 
>     /// \brief Read and initialize a ExplicitTemplateArgumentList structure.
> -    /// \return the number of Exprs that were read.
> -    unsigned
> -    ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
> -                                     unsigned NumTemplateArgs,
> -                            llvm::SmallVectorImpl<Stmt *>::iterator EndOfExprs);
> -
> -    // Each of the Visit* functions reads in part of the expression
> -    // from the given record and the current expression stack, then
> -    // return the total number of operands that it read from the
> -    // expression stack.
> -
> -    unsigned VisitStmt(Stmt *S);
> -    unsigned VisitNullStmt(NullStmt *S);
> -    unsigned VisitCompoundStmt(CompoundStmt *S);
> -    unsigned VisitSwitchCase(SwitchCase *S);
> -    unsigned VisitCaseStmt(CaseStmt *S);
> -    unsigned VisitDefaultStmt(DefaultStmt *S);
> -    unsigned VisitLabelStmt(LabelStmt *S);
> -    unsigned VisitIfStmt(IfStmt *S);
> -    unsigned VisitSwitchStmt(SwitchStmt *S);
> -    unsigned VisitWhileStmt(WhileStmt *S);
> -    unsigned VisitDoStmt(DoStmt *S);
> -    unsigned VisitForStmt(ForStmt *S);
> -    unsigned VisitGotoStmt(GotoStmt *S);
> -    unsigned VisitIndirectGotoStmt(IndirectGotoStmt *S);
> -    unsigned VisitContinueStmt(ContinueStmt *S);
> -    unsigned VisitBreakStmt(BreakStmt *S);
> -    unsigned VisitReturnStmt(ReturnStmt *S);
> -    unsigned VisitDeclStmt(DeclStmt *S);
> -    unsigned VisitAsmStmt(AsmStmt *S);
> -    unsigned VisitExpr(Expr *E);
> -    unsigned VisitPredefinedExpr(PredefinedExpr *E);
> -    unsigned VisitDeclRefExpr(DeclRefExpr *E);
> -    unsigned VisitIntegerLiteral(IntegerLiteral *E);
> -    unsigned VisitFloatingLiteral(FloatingLiteral *E);
> -    unsigned VisitImaginaryLiteral(ImaginaryLiteral *E);
> -    unsigned VisitStringLiteral(StringLiteral *E);
> -    unsigned VisitCharacterLiteral(CharacterLiteral *E);
> -    unsigned VisitParenExpr(ParenExpr *E);
> -    unsigned VisitUnaryOperator(UnaryOperator *E);
> -    unsigned VisitOffsetOfExpr(OffsetOfExpr *E);
> -    unsigned VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
> -    unsigned VisitArraySubscriptExpr(ArraySubscriptExpr *E);
> -    unsigned VisitCallExpr(CallExpr *E);
> -    unsigned VisitMemberExpr(MemberExpr *E);
> -    unsigned VisitCastExpr(CastExpr *E);
> -    unsigned VisitBinaryOperator(BinaryOperator *E);
> -    unsigned VisitCompoundAssignOperator(CompoundAssignOperator *E);
> -    unsigned VisitConditionalOperator(ConditionalOperator *E);
> -    unsigned VisitImplicitCastExpr(ImplicitCastExpr *E);
> -    unsigned VisitExplicitCastExpr(ExplicitCastExpr *E);
> -    unsigned VisitCStyleCastExpr(CStyleCastExpr *E);
> -    unsigned VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
> -    unsigned VisitExtVectorElementExpr(ExtVectorElementExpr *E);
> -    unsigned VisitInitListExpr(InitListExpr *E);
> -    unsigned VisitDesignatedInitExpr(DesignatedInitExpr *E);
> -    unsigned VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
> -    unsigned VisitVAArgExpr(VAArgExpr *E);
> -    unsigned VisitAddrLabelExpr(AddrLabelExpr *E);
> -    unsigned VisitStmtExpr(StmtExpr *E);
> -    unsigned VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
> -    unsigned VisitChooseExpr(ChooseExpr *E);
> -    unsigned VisitGNUNullExpr(GNUNullExpr *E);
> -    unsigned VisitShuffleVectorExpr(ShuffleVectorExpr *E);
> -    unsigned VisitBlockExpr(BlockExpr *E);
> -    unsigned VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
> -    unsigned VisitObjCStringLiteral(ObjCStringLiteral *E);
> -    unsigned VisitObjCEncodeExpr(ObjCEncodeExpr *E);
> -    unsigned VisitObjCSelectorExpr(ObjCSelectorExpr *E);
> -    unsigned VisitObjCProtocolExpr(ObjCProtocolExpr *E);
> -    unsigned VisitObjCIvarRefExpr(ObjCIvarRefExpr *E);
> -    unsigned VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E);
> -    unsigned VisitObjCImplicitSetterGetterRefExpr(
> +    void ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
> +                                          unsigned NumTemplateArgs);
> +
> +    void VisitStmt(Stmt *S);
> +    void VisitNullStmt(NullStmt *S);
> +    void VisitCompoundStmt(CompoundStmt *S);
> +    void VisitSwitchCase(SwitchCase *S);
> +    void VisitCaseStmt(CaseStmt *S);
> +    void VisitDefaultStmt(DefaultStmt *S);
> +    void VisitLabelStmt(LabelStmt *S);
> +    void VisitIfStmt(IfStmt *S);
> +    void VisitSwitchStmt(SwitchStmt *S);
> +    void VisitWhileStmt(WhileStmt *S);
> +    void VisitDoStmt(DoStmt *S);
> +    void VisitForStmt(ForStmt *S);
> +    void VisitGotoStmt(GotoStmt *S);
> +    void VisitIndirectGotoStmt(IndirectGotoStmt *S);
> +    void VisitContinueStmt(ContinueStmt *S);
> +    void VisitBreakStmt(BreakStmt *S);
> +    void VisitReturnStmt(ReturnStmt *S);
> +    void VisitDeclStmt(DeclStmt *S);
> +    void VisitAsmStmt(AsmStmt *S);
> +    void VisitExpr(Expr *E);
> +    void VisitPredefinedExpr(PredefinedExpr *E);
> +    void VisitDeclRefExpr(DeclRefExpr *E);
> +    void VisitIntegerLiteral(IntegerLiteral *E);
> +    void VisitFloatingLiteral(FloatingLiteral *E);
> +    void VisitImaginaryLiteral(ImaginaryLiteral *E);
> +    void VisitStringLiteral(StringLiteral *E);
> +    void VisitCharacterLiteral(CharacterLiteral *E);
> +    void VisitParenExpr(ParenExpr *E);
> +    void VisitUnaryOperator(UnaryOperator *E);
> +    void VisitOffsetOfExpr(OffsetOfExpr *E);
> +    void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
> +    void VisitArraySubscriptExpr(ArraySubscriptExpr *E);
> +    void VisitCallExpr(CallExpr *E);
> +    void VisitMemberExpr(MemberExpr *E);
> +    void VisitCastExpr(CastExpr *E);
> +    void VisitBinaryOperator(BinaryOperator *E);
> +    void VisitCompoundAssignOperator(CompoundAssignOperator *E);
> +    void VisitConditionalOperator(ConditionalOperator *E);
> +    void VisitImplicitCastExpr(ImplicitCastExpr *E);
> +    void VisitExplicitCastExpr(ExplicitCastExpr *E);
> +    void VisitCStyleCastExpr(CStyleCastExpr *E);
> +    void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
> +    void VisitExtVectorElementExpr(ExtVectorElementExpr *E);
> +    void VisitInitListExpr(InitListExpr *E);
> +    void VisitDesignatedInitExpr(DesignatedInitExpr *E);
> +    void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
> +    void VisitVAArgExpr(VAArgExpr *E);
> +    void VisitAddrLabelExpr(AddrLabelExpr *E);
> +    void VisitStmtExpr(StmtExpr *E);
> +    void VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
> +    void VisitChooseExpr(ChooseExpr *E);
> +    void VisitGNUNullExpr(GNUNullExpr *E);
> +    void VisitShuffleVectorExpr(ShuffleVectorExpr *E);
> +    void VisitBlockExpr(BlockExpr *E);
> +    void VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
> +    void VisitObjCStringLiteral(ObjCStringLiteral *E);
> +    void VisitObjCEncodeExpr(ObjCEncodeExpr *E);
> +    void VisitObjCSelectorExpr(ObjCSelectorExpr *E);
> +    void VisitObjCProtocolExpr(ObjCProtocolExpr *E);
> +    void VisitObjCIvarRefExpr(ObjCIvarRefExpr *E);
> +    void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E);
> +    void VisitObjCImplicitSetterGetterRefExpr(
>                             ObjCImplicitSetterGetterRefExpr *E);
> -    unsigned VisitObjCMessageExpr(ObjCMessageExpr *E);
> -    unsigned VisitObjCSuperExpr(ObjCSuperExpr *E);
> -    unsigned VisitObjCIsaExpr(ObjCIsaExpr *E);
> -
> -    unsigned VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
> -    unsigned VisitObjCAtCatchStmt(ObjCAtCatchStmt *);
> -    unsigned VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *);
> -    unsigned VisitObjCAtTryStmt(ObjCAtTryStmt *);
> -    unsigned VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *);
> -    unsigned VisitObjCAtThrowStmt(ObjCAtThrowStmt *);
> -
> -    unsigned VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
> -    unsigned VisitCXXConstructExpr(CXXConstructExpr *E);
> -    unsigned VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
> -    unsigned VisitCXXStaticCastExpr(CXXStaticCastExpr *E);
> -    unsigned VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E);
> -    unsigned VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E);
> -    unsigned VisitCXXConstCastExpr(CXXConstCastExpr *E);
> -    unsigned VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
> -    unsigned VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
> -    unsigned VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
> -    unsigned VisitCXXTypeidExpr(CXXTypeidExpr *E);
> -    unsigned VisitCXXThisExpr(CXXThisExpr *E);
> -    unsigned VisitCXXThrowExpr(CXXThrowExpr *E);
> -    unsigned VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
> -    unsigned VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
> +    void VisitObjCMessageExpr(ObjCMessageExpr *E);
> +    void VisitObjCSuperExpr(ObjCSuperExpr *E);
> +    void VisitObjCIsaExpr(ObjCIsaExpr *E);
> +
> +    void VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
> +    void VisitObjCAtCatchStmt(ObjCAtCatchStmt *);
> +    void VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *);
> +    void VisitObjCAtTryStmt(ObjCAtTryStmt *);
> +    void VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *);
> +    void VisitObjCAtThrowStmt(ObjCAtThrowStmt *);
> +
> +    void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
> +    void VisitCXXConstructExpr(CXXConstructExpr *E);
> +    void VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
> +    void VisitCXXStaticCastExpr(CXXStaticCastExpr *E);
> +    void VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E);
> +    void VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E);
> +    void VisitCXXConstCastExpr(CXXConstCastExpr *E);
> +    void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
> +    void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
> +    void VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
> +    void VisitCXXTypeidExpr(CXXTypeidExpr *E);
> +    void VisitCXXThisExpr(CXXThisExpr *E);
> +    void VisitCXXThrowExpr(CXXThrowExpr *E);
> +    void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
> +    void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
> 
> -    unsigned VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
> -    unsigned VisitCXXNewExpr(CXXNewExpr *E);
> -    unsigned VisitCXXDeleteExpr(CXXDeleteExpr *E);
> -    unsigned VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
> +    void VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
> +    void VisitCXXNewExpr(CXXNewExpr *E);
> +    void VisitCXXDeleteExpr(CXXDeleteExpr *E);
> +    void VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
> 
> -    unsigned VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
> +    void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
> 
> -    unsigned VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
> -    unsigned VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
> -    unsigned VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
> -
> -    unsigned VisitOverloadExpr(OverloadExpr *E);
> -    unsigned VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
> -    unsigned VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
> +    void VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
> +    void VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
> +    void VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
> +
> +    void VisitOverloadExpr(OverloadExpr *E);
> +    void VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
> +    void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
>   };
> }
> 
> -unsigned PCHStmtReader::
> +void PCHStmtReader::
> ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList,
> -                                 unsigned NumTemplateArgs,
> -                           llvm::SmallVectorImpl<Stmt *>::iterator EndOfExprs) {
> -
> -  class StmtStackExprReader : public PCHReader::ExprReader {
> -    llvm::SmallVectorImpl<Stmt *>::iterator StmtI;
> -  public:
> -    StmtStackExprReader(const llvm::SmallVectorImpl<Stmt *>::iterator &stmtI)
> -      : StmtI(stmtI) { }
> -    virtual Expr *Read() { return cast_or_null<Expr>(*StmtI++); }
> -  };
> -
> -  unsigned NumExprs = Record[Idx++];
> -  
> +                                 unsigned NumTemplateArgs) {
>   TemplateArgumentListInfo ArgInfo;
>   ArgInfo.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
>   ArgInfo.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
> -  
> -  StmtStackExprReader ExprReader(EndOfExprs - NumExprs);
>   for (unsigned i = 0; i != NumTemplateArgs; ++i)
> -    ArgInfo.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx,
> -                                                       ExprReader));
> +    ArgInfo.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
>   ArgList.initializeFrom(ArgInfo);
> -
> -  return NumExprs;
> }
> 
> -unsigned PCHStmtReader::VisitStmt(Stmt *S) {
> +void PCHStmtReader::VisitStmt(Stmt *S) {
>   assert(Idx == NumStmtFields && "Incorrect statement field count");
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitNullStmt(NullStmt *S) {
> +void PCHStmtReader::VisitNullStmt(NullStmt *S) {
>   VisitStmt(S);
>   S->setSemiLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitCompoundStmt(CompoundStmt *S) {
> +void PCHStmtReader::VisitCompoundStmt(CompoundStmt *S) {
>   VisitStmt(S);
> +  llvm::SmallVector<Stmt *, 16> Stmts;
>   unsigned NumStmts = Record[Idx++];
> -  S->setStmts(*Reader.getContext(),
> -              StmtStack.data() + StmtStack.size() - NumStmts, NumStmts);
> +  while (NumStmts--)
> +    Stmts.push_back(Reader.ReadStmt());
> +  S->setStmts(*Reader.getContext(), Stmts.data(), Stmts.size());
>   S->setLBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setRBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return NumStmts;
> }
> 
> -unsigned PCHStmtReader::VisitSwitchCase(SwitchCase *S) {
> +void PCHStmtReader::VisitSwitchCase(SwitchCase *S) {
>   VisitStmt(S);
>   Reader.RecordSwitchCaseID(S, Record[Idx++]);
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitCaseStmt(CaseStmt *S) {
> +void PCHStmtReader::VisitCaseStmt(CaseStmt *S) {
>   VisitSwitchCase(S);
> -  S->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 3]));
> -  S->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
> -  S->setSubStmt(StmtStack.back());
> +  S->setLHS(Reader.ReadExpr());
> +  S->setRHS(Reader.ReadExpr());
> +  S->setSubStmt(Reader.ReadStmt());
>   S->setCaseLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setEllipsisLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 3;
> }
> 
> -unsigned PCHStmtReader::VisitDefaultStmt(DefaultStmt *S) {
> +void PCHStmtReader::VisitDefaultStmt(DefaultStmt *S) {
>   VisitSwitchCase(S);
> -  S->setSubStmt(StmtStack.back());
> +  S->setSubStmt(Reader.ReadStmt());
>   S->setDefaultLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitLabelStmt(LabelStmt *S) {
> +void PCHStmtReader::VisitLabelStmt(LabelStmt *S) {
>   VisitStmt(S);
>   S->setID(Reader.GetIdentifierInfo(Record, Idx));
> -  S->setSubStmt(StmtStack.back());
> +  S->setSubStmt(Reader.ReadStmt());
>   S->setIdentLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   Reader.RecordLabelStmt(S, Record[Idx++]);
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitIfStmt(IfStmt *S) {
> +void PCHStmtReader::VisitIfStmt(IfStmt *S) {
>   VisitStmt(S);
>   S->setConditionVariable(*Reader.getContext(),
>                           cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
> -  S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3]));
> -  S->setThen(StmtStack[StmtStack.size() - 2]);
> -  S->setElse(StmtStack[StmtStack.size() - 1]);
> +  S->setCond(Reader.ReadExpr());
> +  S->setThen(Reader.ReadStmt());
> +  S->setElse(Reader.ReadStmt());
>   S->setIfLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setElseLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 3;
> }
> 
> -unsigned PCHStmtReader::VisitSwitchStmt(SwitchStmt *S) {
> +void PCHStmtReader::VisitSwitchStmt(SwitchStmt *S) {
>   VisitStmt(S);
>   S->setConditionVariable(*Reader.getContext(),
>                           cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
> -  S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 2]));
> -  S->setBody(StmtStack.back());
> +  S->setCond(Reader.ReadExpr());
> +  S->setBody(Reader.ReadStmt());
>   S->setSwitchLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   SwitchCase *PrevSC = 0;
>   for (unsigned N = Record.size(); Idx != N; ++Idx) {
> @@ -272,80 +240,71 @@
>     SC->Retain();
>     PrevSC = SC;
>   }
> -  return 2;
> }
> 
> -unsigned PCHStmtReader::VisitWhileStmt(WhileStmt *S) {
> +void PCHStmtReader::VisitWhileStmt(WhileStmt *S) {
>   VisitStmt(S);
>   S->setConditionVariable(*Reader.getContext(),
>                           cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
> -  S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
> -  S->setBody(StmtStack.back());
> +  S->setCond(Reader.ReadExpr());
> +  S->setBody(Reader.ReadStmt());
>   S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 2;
> }
> 
> -unsigned PCHStmtReader::VisitDoStmt(DoStmt *S) {
> +void PCHStmtReader::VisitDoStmt(DoStmt *S) {
>   VisitStmt(S);
> -  S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
> -  S->setBody(StmtStack.back());
> +  S->setCond(Reader.ReadExpr());
> +  S->setBody(Reader.ReadStmt());
>   S->setDoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 2;
> }
> 
> -unsigned PCHStmtReader::VisitForStmt(ForStmt *S) {
> +void PCHStmtReader::VisitForStmt(ForStmt *S) {
>   VisitStmt(S);
> -  S->setInit(StmtStack[StmtStack.size() - 4]);
> -  S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 3]));
> +  S->setInit(Reader.ReadStmt());
> +  S->setCond(Reader.ReadExpr());
>   S->setConditionVariable(*Reader.getContext(),
>                           cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
> -  S->setInc(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
> -  S->setBody(StmtStack.back());
> +  S->setInc(Reader.ReadExpr());
> +  S->setBody(Reader.ReadStmt());
>   S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 4;
> }
> 
> -unsigned PCHStmtReader::VisitGotoStmt(GotoStmt *S) {
> +void PCHStmtReader::VisitGotoStmt(GotoStmt *S) {
>   VisitStmt(S);
>   Reader.SetLabelOf(S, Record[Idx++]);
>   S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
> +void PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
>   VisitStmt(S);
>   S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  S->setTarget(cast_or_null<Expr>(StmtStack.back()));
> -  return 1;
> +  S->setTarget(Reader.ReadExpr());
> }
> 
> -unsigned PCHStmtReader::VisitContinueStmt(ContinueStmt *S) {
> +void PCHStmtReader::VisitContinueStmt(ContinueStmt *S) {
>   VisitStmt(S);
>   S->setContinueLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitBreakStmt(BreakStmt *S) {
> +void PCHStmtReader::VisitBreakStmt(BreakStmt *S) {
>   VisitStmt(S);
>   S->setBreakLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitReturnStmt(ReturnStmt *S) {
> +void PCHStmtReader::VisitReturnStmt(ReturnStmt *S) {
>   VisitStmt(S);
> -  S->setRetValue(cast_or_null<Expr>(StmtStack.back()));
> +  S->setRetValue(Reader.ReadExpr());
>   S->setReturnLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setNRVOCandidate(cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitDeclStmt(DeclStmt *S) {
> +void PCHStmtReader::VisitDeclStmt(DeclStmt *S) {
>   VisitStmt(S);
>   S->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> @@ -362,10 +321,9 @@
>                                                    Decls.data(),
>                                                    Decls.size())));
>   }
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitAsmStmt(AsmStmt *S) {
> +void PCHStmtReader::VisitAsmStmt(AsmStmt *S) {
>   VisitStmt(S);
>   unsigned NumOutputs = Record[Idx++];
>   unsigned NumInputs = Record[Idx++];
> @@ -376,9 +334,7 @@
>   S->setSimple(Record[Idx++]);
>   S->setMSAsm(Record[Idx++]);
> 
> -  unsigned StackIdx
> -    = StmtStack.size() - (NumOutputs*2 + NumInputs*2 + NumClobbers + 1);
> -  S->setAsmString(cast_or_null<StringLiteral>(StmtStack[StackIdx++]));
> +  S->setAsmString(cast_or_null<StringLiteral>(Reader.ReadStmt()));
> 
>   // Outputs and inputs
>   llvm::SmallVector<IdentifierInfo *, 16> Names;
> @@ -386,71 +342,62 @@
>   llvm::SmallVector<Stmt*, 16> Exprs;
>   for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) {
>     Names.push_back(Reader.GetIdentifierInfo(Record, Idx));
> -    Constraints.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++]));
> -    Exprs.push_back(StmtStack[StackIdx++]);
> +    Constraints.push_back(cast_or_null<StringLiteral>(Reader.ReadStmt()));
> +    Exprs.push_back(Reader.ReadStmt());
>   }
> 
>   // Constraints
>   llvm::SmallVector<StringLiteral*, 16> Clobbers;
>   for (unsigned I = 0; I != NumClobbers; ++I)
> -    Clobbers.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++]));
> +    Clobbers.push_back(cast_or_null<StringLiteral>(Reader.ReadStmt()));
> 
>   S->setOutputsAndInputsAndClobbers(*Reader.getContext(),
>                                     Names.data(), Constraints.data(), 
>                                     Exprs.data(), NumOutputs, NumInputs, 
>                                     Clobbers.data(), NumClobbers);
> -
> -  assert(StackIdx == StmtStack.size() && "Error deserializing AsmStmt");
> -  return NumOutputs*2 + NumInputs*2 + NumClobbers + 1;
> }
> 
> -unsigned PCHStmtReader::VisitExpr(Expr *E) {
> +void PCHStmtReader::VisitExpr(Expr *E) {
>   VisitStmt(E);
>   E->setType(Reader.GetType(Record[Idx++]));
>   E->setTypeDependent(Record[Idx++]);
>   E->setValueDependent(Record[Idx++]);
>   assert(Idx == NumExprFields && "Incorrect expression field count");
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
> +void PCHStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
>   VisitExpr(E);
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]);
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
> +void PCHStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
>   VisitExpr(E);
>   E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   // FIXME: read qualifier
>   // FIXME: read explicit template arguments
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
> +void PCHStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
>   VisitExpr(E);
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setValue(Reader.ReadAPInt(Record, Idx));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
> +void PCHStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
>   VisitExpr(E);
>   E->setValue(Reader.ReadAPFloat(Record, Idx));
>   E->setExact(Record[Idx++]);
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
> +void PCHStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
>   VisitExpr(E);
> -  E->setSubExpr(cast<Expr>(StmtStack.back()));
> -  return 1;
> +  E->setSubExpr(Reader.ReadExpr());
> }
> 
> -unsigned PCHStmtReader::VisitStringLiteral(StringLiteral *E) {
> +void PCHStmtReader::VisitStringLiteral(StringLiteral *E) {
>   VisitExpr(E);
>   unsigned Len = Record[Idx++];
>   assert(Record[Idx] == E->getNumConcatenated() &&
> @@ -466,35 +413,30 @@
>   // Read source locations
>   for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
>     E->setStrTokenLoc(I, SourceLocation::getFromRawEncoding(Record[Idx++]));
> -
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
> +void PCHStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
>   VisitExpr(E);
>   E->setValue(Record[Idx++]);
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setWide(Record[Idx++]);
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitParenExpr(ParenExpr *E) {
> +void PCHStmtReader::VisitParenExpr(ParenExpr *E) {
>   VisitExpr(E);
>   E->setLParen(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParen(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  E->setSubExpr(cast<Expr>(StmtStack.back()));
> -  return 1;
> +  E->setSubExpr(Reader.ReadExpr());
> }
> 
> -unsigned PCHStmtReader::VisitUnaryOperator(UnaryOperator *E) {
> +void PCHStmtReader::VisitUnaryOperator(UnaryOperator *E) {
>   VisitExpr(E);
> -  E->setSubExpr(cast<Expr>(StmtStack.back()));
> +  E->setSubExpr(Reader.ReadExpr());
>   E->setOpcode((UnaryOperator::Opcode)Record[Idx++]);
>   E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
> +void PCHStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
>   typedef OffsetOfExpr::OffsetOfNode Node;
>   VisitExpr(E);
>   assert(E->getNumComponents() == Record[Idx]);
> @@ -532,153 +474,135 @@
>   }
> 
>   for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
> -    E->setIndexExpr(I, cast_or_null<Expr>(StmtStack[StmtStack.size() - N + I]));
> -  
> -  return E->getNumExpressions();
> +    E->setIndexExpr(I, Reader.ReadExpr());
> }
> 
> -unsigned PCHStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
> +void PCHStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
>   VisitExpr(E);
>   E->setSizeof(Record[Idx++]);
>   if (Record[Idx] == 0) {
> -    E->setArgument(cast<Expr>(StmtStack.back()));
> +    E->setArgument(Reader.ReadExpr());
>     ++Idx;
>   } else {
>     E->setArgument(Reader.GetTypeSourceInfo(Record, Idx));
>   }
>   E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return E->isArgumentType()? 0 : 1;
> }
> 
> -unsigned PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
> +void PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
>   VisitExpr(E);
> -  E->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 2]));
> -  E->setRHS(cast<Expr>(StmtStack[StmtStack.size() - 1]));
> +  E->setLHS(Reader.ReadExpr());
> +  E->setRHS(Reader.ReadExpr());
>   E->setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 2;
> }
> 
> -unsigned PCHStmtReader::VisitCallExpr(CallExpr *E) {
> +void PCHStmtReader::VisitCallExpr(CallExpr *E) {
>   VisitExpr(E);
>   E->setNumArgs(*Reader.getContext(), Record[Idx++]);
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  E->setCallee(cast<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1]));
> +  E->setCallee(Reader.ReadExpr());
>   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
> -    E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I]));
> -  return E->getNumArgs() + 1;
> +    E->setArg(I, Reader.ReadExpr());
> }
> 
> -unsigned PCHStmtReader::VisitMemberExpr(MemberExpr *E) {
> +void PCHStmtReader::VisitMemberExpr(MemberExpr *E) {
>   VisitExpr(E);
> -  E->setBase(cast<Expr>(StmtStack.back()));
> +  E->setBase(Reader.ReadExpr());
>   E->setMemberDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
>   E->setMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setArrow(Record[Idx++]);
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
> +void PCHStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
>   VisitExpr(E);
> -  E->setBase(cast<Expr>(StmtStack.back()));
> +  E->setBase(Reader.ReadExpr());
>   E->setIsaMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setArrow(Record[Idx++]);
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitCastExpr(CastExpr *E) {
> +void PCHStmtReader::VisitCastExpr(CastExpr *E) {
>   VisitExpr(E);
> -  E->setSubExpr(cast<Expr>(StmtStack.back()));
> +  E->setSubExpr(Reader.ReadExpr());
>   E->setCastKind((CastExpr::CastKind)Record[Idx++]);
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitBinaryOperator(BinaryOperator *E) {
> +void PCHStmtReader::VisitBinaryOperator(BinaryOperator *E) {
>   VisitExpr(E);
> -  E->setLHS(cast<Expr>(StmtStack.end()[-2]));
> -  E->setRHS(cast<Expr>(StmtStack.end()[-1]));
> +  E->setLHS(Reader.ReadExpr());
> +  E->setRHS(Reader.ReadExpr());
>   E->setOpcode((BinaryOperator::Opcode)Record[Idx++]);
>   E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 2;
> }
> 
> -unsigned PCHStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
> +void PCHStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
>   VisitBinaryOperator(E);
>   E->setComputationLHSType(Reader.GetType(Record[Idx++]));
>   E->setComputationResultType(Reader.GetType(Record[Idx++]));
> -  return 2;
> }
> 
> -unsigned PCHStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
> +void PCHStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
>   VisitExpr(E);
> -  E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3]));
> -  E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
> -  E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1]));
> +  E->setCond(Reader.ReadExpr());
> +  E->setLHS(Reader.ReadExpr());
> +  E->setRHS(Reader.ReadExpr());
>   E->setQuestionLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 3;
> }
> 
> -unsigned PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
> +void PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
>   VisitCastExpr(E);
>   E->setLvalueCast(Record[Idx++]);
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
> +void PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
>   VisitCastExpr(E);
>   E->setTypeInfoAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
> +void PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
>   VisitExplicitCastExpr(E);
>   E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
> +void PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
>   VisitExpr(E);
>   E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
> -  E->setInitializer(cast<Expr>(StmtStack.back()));
> +  E->setInitializer(Reader.ReadExpr());
>   E->setFileScope(Record[Idx++]);
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
> +void PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
>   VisitExpr(E);
> -  E->setBase(cast<Expr>(StmtStack.back()));
> +  E->setBase(Reader.ReadExpr());
>   E->setAccessor(Reader.GetIdentifierInfo(Record, Idx));
>   E->setAccessorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitInitListExpr(InitListExpr *E) {
> +void PCHStmtReader::VisitInitListExpr(InitListExpr *E) {
>   VisitExpr(E);
>   unsigned NumInits = Record[Idx++];
>   E->reserveInits(*Reader.getContext(), NumInits);
>   for (unsigned I = 0; I != NumInits; ++I)
> -    E->updateInit(*Reader.getContext(), I,
> -                  cast<Expr>(StmtStack[StmtStack.size() - NumInits - 1 + I]));
> -  E->setSyntacticForm(cast_or_null<InitListExpr>(StmtStack.back()));
> +    E->updateInit(*Reader.getContext(), I, Reader.ReadExpr());
> +  E->setSyntacticForm(cast_or_null<InitListExpr>(Reader.ReadStmt()));
>   E->setLBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setInitializedFieldInUnion(
>                       cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++])));
>   E->sawArrayRangeDesignator(Record[Idx++]);
> -  return NumInits + 1;
> }
> 
> -unsigned PCHStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
> +void PCHStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
>   typedef DesignatedInitExpr::Designator Designator;
> 
>   VisitExpr(E);
>   unsigned NumSubExprs = Record[Idx++];
>   assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
>   for (unsigned I = 0; I != NumSubExprs; ++I)
> -    E->setSubExpr(I, cast<Expr>(StmtStack[StmtStack.size() - NumSubExprs + I]));
> +    E->setSubExpr(I, Reader.ReadExpr());
>   E->setEqualOrColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setGNUSyntax(Record[Idx++]);
> 
> @@ -733,144 +657,128 @@
>   }
>   E->setDesignators(*Reader.getContext(), 
>                     Designators.data(), Designators.size());
> -
> -  return NumSubExprs;
> }
> 
> -unsigned PCHStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
> +void PCHStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
>   VisitExpr(E);
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitVAArgExpr(VAArgExpr *E) {
> +void PCHStmtReader::VisitVAArgExpr(VAArgExpr *E) {
>   VisitExpr(E);
> -  E->setSubExpr(cast<Expr>(StmtStack.back()));
> +  E->setSubExpr(Reader.ReadExpr());
>   E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
> +void PCHStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
>   VisitExpr(E);
>   E->setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   Reader.SetLabelOf(E, Record[Idx++]);
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitStmtExpr(StmtExpr *E) {
> +void PCHStmtReader::VisitStmtExpr(StmtExpr *E) {
>   VisitExpr(E);
>   E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  E->setSubStmt(cast_or_null<CompoundStmt>(StmtStack.back()));
> -  return 1;
> +  E->setSubStmt(cast_or_null<CompoundStmt>(Reader.ReadStmt()));
> }
> 
> -unsigned PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
> +void PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
>   VisitExpr(E);
>   E->setArgType1(Reader.GetType(Record[Idx++]));
>   E->setArgType2(Reader.GetType(Record[Idx++]));
>   E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitChooseExpr(ChooseExpr *E) {
> +void PCHStmtReader::VisitChooseExpr(ChooseExpr *E) {
>   VisitExpr(E);
> -  E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3]));
> -  E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
> -  E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1]));
> +  E->setCond(Reader.ReadExpr());
> +  E->setLHS(Reader.ReadExpr());
> +  E->setRHS(Reader.ReadExpr());
>   E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 3;
> }
> 
> -unsigned PCHStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
> +void PCHStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
>   VisitExpr(E);
>   E->setTokenLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
> +void PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
>   VisitExpr(E);
> +  llvm::SmallVector<Expr *, 16> Exprs;
>   unsigned NumExprs = Record[Idx++];
> -  E->setExprs(*Reader.getContext(),
> -              (Expr **)&StmtStack[StmtStack.size() - NumExprs], NumExprs);
> +  while (NumExprs--)
> +    Exprs.push_back(Reader.ReadExpr());
> +  E->setExprs(*Reader.getContext(), Exprs.data(), Exprs.size());
>   E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return NumExprs;
> }
> 
> -unsigned PCHStmtReader::VisitBlockExpr(BlockExpr *E) {
> +void PCHStmtReader::VisitBlockExpr(BlockExpr *E) {
>   VisitExpr(E);
>   E->setBlockDecl(cast_or_null<BlockDecl>(Reader.GetDecl(Record[Idx++])));
>   E->setHasBlockDeclRefExprs(Record[Idx++]);
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
> +void PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
>   VisitExpr(E);
>   E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setByRef(Record[Idx++]);
>   E->setConstQualAdded(Record[Idx++]);
> -  E->setCopyConstructorExpr(cast_or_null<Expr>(StmtStack.back()));
> -  return 1;
> +  E->setCopyConstructorExpr(Reader.ReadExpr());
> }
> 
> //===----------------------------------------------------------------------===//
> // Objective-C Expressions and Statements
> 
> -unsigned PCHStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
> +void PCHStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
>   VisitExpr(E);
> -  E->setString(cast<StringLiteral>(StmtStack.back()));
> +  E->setString(cast<StringLiteral>(Reader.ReadStmt()));
>   E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
> +void PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
>   VisitExpr(E);
>   E->setEncodedTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
>   E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
> +void PCHStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
>   VisitExpr(E);
>   E->setSelector(Reader.GetSelector(Record, Idx));
>   E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
> +void PCHStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
>   VisitExpr(E);
>   E->setProtocol(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
>   E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
> +void PCHStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
>   VisitExpr(E);
>   E->setDecl(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  E->setBase(cast<Expr>(StmtStack.back()));
> +  E->setBase(Reader.ReadExpr());
>   E->setIsArrow(Record[Idx++]);
>   E->setIsFreeIvar(Record[Idx++]);
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
> +void PCHStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
>   VisitExpr(E);
>   E->setProperty(cast<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  E->setBase(cast<Expr>(StmtStack.back()));
> -  return 1;
> +  E->setBase(Reader.ReadExpr());
> }
> 
> -unsigned PCHStmtReader::VisitObjCImplicitSetterGetterRefExpr(
> +void PCHStmtReader::VisitObjCImplicitSetterGetterRefExpr(
>                                       ObjCImplicitSetterGetterRefExpr *E) {
>   VisitExpr(E);
>   E->setGetterMethod(
> @@ -879,13 +787,12 @@
>                  cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
>   E->setInterfaceDecl(
>               cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
> -  E->setBase(cast_or_null<Expr>(StmtStack.back()));
> +  E->setBase(Reader.ReadExpr());
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
> +void PCHStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
>   VisitExpr(E);
>   assert(Record[Idx] == E->getNumArgs());
>   ++Idx;
> @@ -893,8 +800,7 @@
>     = static_cast<ObjCMessageExpr::ReceiverKind>(Record[Idx++]);
>   switch (Kind) {
>   case ObjCMessageExpr::Instance:
> -    E->setInstanceReceiver(
> -         cast_or_null<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1]));
> +    E->setInstanceReceiver(Reader.ReadExpr());
>     break;
> 
>   case ObjCMessageExpr::Class:
> @@ -921,193 +827,168 @@
>   E->setRightLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> 
>   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
> -    E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I]));
> -  return E->getNumArgs() + (Kind == ObjCMessageExpr::Instance);
> +    E->setArg(I, Reader.ReadExpr());
> }
> 
> -unsigned PCHStmtReader::VisitObjCSuperExpr(ObjCSuperExpr *E) {
> +void PCHStmtReader::VisitObjCSuperExpr(ObjCSuperExpr *E) {
>   VisitExpr(E);
>   E->setLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
> +void PCHStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
>   VisitStmt(S);
> -  S->setElement(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 3]));
> -  S->setCollection(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
> -  S->setBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1]));
> +  S->setElement(Reader.ReadStmt());
> +  S->setCollection(Reader.ReadExpr());
> +  S->setBody(Reader.ReadStmt());
>   S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 3;
> }
> 
> -unsigned PCHStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
> +void PCHStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
>   VisitStmt(S);
> -  S->setCatchBody(cast_or_null<Stmt>(StmtStack.back()));
> +  S->setCatchBody(Reader.ReadStmt());
>   S->setCatchParamDecl(cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
>   S->setAtCatchLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
> +void PCHStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
>   VisitStmt(S);
> -  S->setFinallyBody(StmtStack.back());
> +  S->setFinallyBody(Reader.ReadStmt());
>   S->setAtFinallyLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
> +void PCHStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
>   VisitStmt(S);
>   assert(Record[Idx] == S->getNumCatchStmts());
>   ++Idx;
>   bool HasFinally = Record[Idx++];
> -  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
> -    unsigned Offset = StmtStack.size() - N - HasFinally + I;
> -    S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(StmtStack[Offset]));
> -  }
> +  S->setTryBody(Reader.ReadStmt());
> +  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
> +    S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Reader.ReadStmt()));
> 
> -  unsigned TryOffset
> -    = StmtStack.size() - S->getNumCatchStmts() - HasFinally - 1;
> -  S->setTryBody(cast_or_null<Stmt>(StmtStack[TryOffset]));
>   if (HasFinally)
> -    S->setFinallyStmt(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1]));
> +    S->setFinallyStmt(Reader.ReadStmt());
>   S->setAtTryLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1 + S->getNumCatchStmts() + HasFinally;
> }
> 
> -unsigned PCHStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
> +void PCHStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
>   VisitStmt(S);
> -  S->setSynchExpr(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 2]));
> -  S->setSynchBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1]));
> +  S->setSynchExpr(Reader.ReadStmt());
> +  S->setSynchBody(Reader.ReadStmt());
>   S->setAtSynchronizedLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 2;
> }
> 
> -unsigned PCHStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
> +void PCHStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
>   VisitStmt(S);
> -  S->setThrowExpr(StmtStack.back());
> +  S->setThrowExpr(Reader.ReadStmt());
>   S->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1;
> }
> 
> //===----------------------------------------------------------------------===//
> // C++ Expressions and Statements
> 
> -unsigned PCHStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
> -  unsigned num = VisitCallExpr(E);
> +void PCHStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
> +  VisitCallExpr(E);
>   E->setOperator((OverloadedOperatorKind)Record[Idx++]);
> -  return num;
> }
> 
> -unsigned PCHStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
> +void PCHStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
>   VisitExpr(E);
> -  assert(Record[Idx] == E->getNumArgs() &&
> -         "Read wrong record during creation ?");
> +  assert(Record[Idx] == E->getNumArgs() &&"Read wrong record during creation?");
>   ++Idx; // NumArgs;
>   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
> -    E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I]));
> +    E->setArg(I, Reader.ReadExpr());
>   E->setConstructor(cast<CXXConstructorDecl>(Reader.GetDecl(Record[Idx++])));
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setElidable(Record[Idx++]);  
>   E->setRequiresZeroInitialization(Record[Idx++]);
>   E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
> -  return E->getNumArgs();
> }
> 
> -unsigned PCHStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
> -  unsigned num = VisitExplicitCastExpr(E);
> +void PCHStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
> +  VisitExplicitCastExpr(E);
>   E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return num;
> }
> 
> -unsigned PCHStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
> +void PCHStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
>   return VisitCXXNamedCastExpr(E);
> }
> 
> -unsigned PCHStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
> +void PCHStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
>   return VisitCXXNamedCastExpr(E);
> }
> 
> -unsigned PCHStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
> +void PCHStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
>   return VisitCXXNamedCastExpr(E);
> }
> 
> -unsigned PCHStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
> +void PCHStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
>   return VisitCXXNamedCastExpr(E);
> }
> 
> -unsigned PCHStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
> -  unsigned num = VisitExplicitCastExpr(E);
> +void PCHStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
> +  VisitExplicitCastExpr(E);
>   E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return num;
> }
> 
> -unsigned PCHStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
> +void PCHStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
>   VisitExpr(E);
>   E->setValue(Record[Idx++]);
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
> +void PCHStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
>   VisitExpr(E);
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
> +void PCHStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
>   VisitExpr(E);
>   E->setSourceRange(Reader.ReadSourceRange(Record, Idx));
>   if (E->isTypeOperand()) { // typeid(int)
>     E->setTypeOperandSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
> -    return 0;
> +    return;
>   }
> 
>   // typeid(42+2)
> -  E->setExprOperand(cast<Expr>(StmtStack.back()));
> -  return 1;
> +  E->setExprOperand(Reader.ReadExpr());
> }
> 
> -unsigned PCHStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
> +void PCHStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
>   VisitExpr(E);
>   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setImplicit(Record[Idx++]);
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
> +void PCHStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
>   VisitExpr(E);
>   E->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  E->setSubExpr(cast_or_null<Expr>(StmtStack.back()));
> -  return 1;
> +  E->setSubExpr(Reader.ReadExpr());
> }
> 
> -unsigned PCHStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
> +void PCHStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
>   VisitExpr(E);
>   E->setUsedLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   bool HasStoredExpr = Record[Idx++];
> -  if (!HasStoredExpr) return 0;
> -  E->setExpr(cast<Expr>(StmtStack.back()));
> -  return 1;
> +  if (!HasStoredExpr) return;
> +  E->setExpr(Reader.ReadExpr());
> }
> 
> -unsigned PCHStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
> +void PCHStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
>   VisitExpr(E);
>   E->setTemporary(Reader.ReadCXXTemporary(Record, Idx));
> -  E->setSubExpr(cast<Expr>(StmtStack.back()));
> -  return 1;
> +  E->setSubExpr(Reader.ReadExpr());
> }
> 
> -unsigned PCHStmtReader::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
> +void PCHStmtReader::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
>   VisitExpr(E);
>   E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 0;
> }
> 
> -unsigned PCHStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
> +void PCHStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
>   VisitExpr(E);
>   E->setGlobalNew(Record[Idx++]);
>   E->setParenTypeId(Record[Idx++]);
> @@ -1127,31 +1008,25 @@
>                        NumCtorArgs);
> 
>   // Install all the subexpressions.
> -  unsigned TotalSubExprs = E->raw_arg_end()-E->raw_arg_begin();
> -  unsigned SSIdx = StmtStack.size()-TotalSubExprs;
>   for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
>        I != e; ++I)
> -    *I = StmtStack[SSIdx++];
> -  
> -  return TotalSubExprs;
> +    *I = Reader.ReadStmt();
> }
> 
> -unsigned PCHStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
> +void PCHStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
>   VisitExpr(E);
>   E->setGlobalDelete(Record[Idx++]);
>   E->setArrayForm(Record[Idx++]);
>   E->setOperatorDelete(
>                      cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
> -  E->setArgument(cast_or_null<Expr>(StmtStack.back()));
> +  E->setArgument(Reader.ReadExpr());
>   E->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
> -  return 1;
> }
> 
> -unsigned
> -PCHStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
> +void PCHStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
>   VisitExpr(E);
> 
> -  E->setBase(cast_or_null<Expr>(StmtStack.back()));
> +  E->setBase(Reader.ReadExpr());
>   E->setArrow(Record[Idx++]);
>   E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx));
>   E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
> @@ -1165,11 +1040,9 @@
>     E->setDestroyedType(II, Reader.ReadSourceLocation(Record, Idx));
>   else
>     E->setDestroyedType(Reader.GetTypeSourceInfo(Record, Idx));
> -  
> -  return 1;
> }
> 
> -unsigned PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
> +void PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
>   VisitExpr(E);
>   unsigned NumTemps = Record[Idx++];
>   if (NumTemps) {
> @@ -1177,24 +1050,21 @@
>     for (unsigned i = 0; i != NumTemps; ++i)
>       E->setTemporary(i, Reader.ReadCXXTemporary(Record, Idx));
>   }
> -  E->setSubExpr(cast<Expr>(StmtStack.back()));
> -  return 1;
> +  E->setSubExpr(Reader.ReadExpr());
> }
> 
> -unsigned
> +void
> PCHStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
>   VisitExpr(E);
> -  unsigned NumExprs = 0;
> 
>   unsigned NumTemplateArgs = Record[Idx++];
>   assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
>          "Read wrong record during creation ?");
>   if (E->hasExplicitTemplateArgs())
> -    NumExprs
> -      = ReadExplicitTemplateArgumentList(*E->getExplicitTemplateArgumentList(),
> -                                         NumTemplateArgs, StmtStack.end());
> +    ReadExplicitTemplateArgumentList(*E->getExplicitTemplateArgumentList(),
> +                                     NumTemplateArgs);
> 
> -  E->setBase(cast_or_null<Expr>(StmtStack.back()));
> +  E->setBase(Reader.ReadExpr());
>   E->setBaseType(Reader.GetType(Record[Idx++]));
>   E->setArrow(Record[Idx++]);
>   E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx));
> @@ -1204,58 +1074,47 @@
>                         cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++])));
>   E->setMember(Reader.ReadDeclarationName(Record, Idx));
>   E->setMemberLoc(Reader.ReadSourceLocation(Record, Idx));
> -  
> -  return NumExprs + 1;
> }
> 
> -unsigned
> +void
> PCHStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
>   VisitExpr(E);
> -  unsigned NumExprs = 0;
> 
>   unsigned NumTemplateArgs = Record[Idx++];
>   assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
>          "Read wrong record during creation ?");
>   if (E->hasExplicitTemplateArgs())
> -    NumExprs
> -      = ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
> -                                         NumTemplateArgs, StmtStack.end());
> +    ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
> +                                     NumTemplateArgs);
> 
>   E->setDeclName(Reader.ReadDeclarationName(Record, Idx));
>   E->setLocation(Reader.ReadSourceLocation(Record, Idx));
>   E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
>   E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
> -  return NumExprs;
> }
> 
> -unsigned
> +void
> PCHStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
>   VisitExpr(E);
>   assert(Record[Idx] == E->arg_size() && "Read wrong record during creation ?");
>   ++Idx; // NumArgs;
>   for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
> -    E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I]));
> +    E->setArg(I, Reader.ReadExpr());
>   E->setTypeBeginLoc(Reader.ReadSourceLocation(Record, Idx));
>   E->setTypeAsWritten(Reader.GetType(Record[Idx++]));
>   E->setLParenLoc(Reader.ReadSourceLocation(Record, Idx));
>   E->setRParenLoc(Reader.ReadSourceLocation(Record, Idx));
> -  return E->arg_size();
> }
> 
> -unsigned PCHStmtReader::VisitOverloadExpr(OverloadExpr *E) {
> +void PCHStmtReader::VisitOverloadExpr(OverloadExpr *E) {
>   VisitExpr(E);
> -  unsigned NumExprs = 0;
> 
>   unsigned NumTemplateArgs = Record[Idx++];
>   assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
>          "Read wrong record during creation ?");
> -  if (E->hasExplicitTemplateArgs()) {
> -    llvm::SmallVectorImpl<Stmt *>::iterator EndOfExprs = StmtStack.end();
> -    if (isa<UnresolvedMemberExpr>(E))
> -      --EndOfExprs; // UnresolvedMemberExpr contains an Expr.
> -    NumExprs = ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
> -                                                NumTemplateArgs, EndOfExprs);
> -  }
> +  if (E->hasExplicitTemplateArgs())
> +    ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
> +                                     NumTemplateArgs);
> 
>   unsigned NumDecls = Record[Idx++];
>   UnresolvedSet<8> Decls;
> @@ -1270,40 +1129,63 @@
>   E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
>   E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
>   E->setNameLoc(Reader.ReadSourceLocation(Record, Idx));
> -  return NumExprs;
> }
> 
> -unsigned PCHStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
> -  unsigned NumExprs = VisitOverloadExpr(E);
> +void PCHStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
> +  VisitOverloadExpr(E);
>   E->setArrow(Record[Idx++]);
>   E->setHasUnresolvedUsing(Record[Idx++]);
> -  E->setBase(cast_or_null<Expr>(StmtStack.back()));
> +  E->setBase(Reader.ReadExpr());
>   E->setBaseType(Reader.GetType(Record[Idx++]));
>   E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx));
> -  return NumExprs + 1;
> }
> 
> -unsigned PCHStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
> -  unsigned NumExprs = VisitOverloadExpr(E);
> +void PCHStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
> +  VisitOverloadExpr(E);
>   E->setRequiresADL(Record[Idx++]);
>   E->setOverloaded(Record[Idx++]);
>   E->setNamingClass(cast_or_null<CXXRecordDecl>(Reader.GetDecl(Record[Idx++])));
> -  return NumExprs;
> }
> 
> +Stmt *PCHReader::ReadStmt() {
> +  switch (ReadingKind) {
> +  case Read_Decl:
> +  case Read_Type:
> +    // Read a statement from the current DeclCursor.
> +    return ReadStmtFromStream(DeclsCursor);
> +  case Read_Stmt:
> +    // Subexpressions are stored from last to first, so the next Stmt we need
> +    // will be at the back of the stack.
> +    assert(!StmtStack.empty() && "Read too many sub statements!");
> +    return StmtStack.pop_back_val();
> +  }
> +
> +  llvm_unreachable("ReadingKind not set ?");
> +  return 0;
> +}
> +
> +Expr *PCHReader::ReadExpr() {
> +  return cast_or_null<Expr>(ReadStmt());
> +}
> 
> // Within the bitstream, expressions are stored in Reverse Polish
> // Notation, with each of the subexpressions preceding the
> -// expression they are stored in. To evaluate expressions, we
> -// continue reading expressions and placing them on the stack, with
> -// expressions having operands removing those operands from the
> +// expression they are stored in. Subexpressions are stored from last to first.
> +// To evaluate expressions, we continue reading expressions and placing them on
> +// the stack, with expressions having operands removing those operands from the
> // stack. Evaluation terminates when we see a STMT_STOP record, and
> // the single remaining expression on the stack is our result.
> -Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) {
> +Stmt *PCHReader::ReadStmtFromStream(llvm::BitstreamCursor &Cursor) {
> +
> +  ReadingKindTracker ReadingKind(Read_Stmt, *this);
> +  
> +#ifndef NDEBUG
> +  unsigned PrevNumStmts = StmtStack.size();
> +#endif
> +
>   RecordData Record;
>   unsigned Idx;
> -  llvm::SmallVector<Stmt *, 16> StmtStack;
> -  PCHStmtReader Reader(*this, Record, Idx, StmtStack);
> +  PCHStmtReader Reader(*this, Record, Idx);
>   Stmt::EmptyShell Empty;
> 
>   while (true) {
> @@ -1709,17 +1591,17 @@
> 
>     ++NumStatementsRead;
> 
> -    if (S) {
> -      unsigned NumSubStmts = Reader.Visit(S);
> -      while (NumSubStmts > 0) {
> -        StmtStack.pop_back();
> -        --NumSubStmts;
> -      }
> -    }
> +    if (S)
> +      Reader.Visit(S);
> 
>     assert(Idx == Record.size() && "Invalid deserialization of statement");
>     StmtStack.push_back(S);
>   }
> -  assert(StmtStack.size() == 1 && "Extra expressions on stack!");
> -  return StmtStack.back();
> +
> +#ifndef NDEBUG
> +  assert(StmtStack.size() > PrevNumStmts && "Read too many sub stmts!");
> +  assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
> +#endif
> +
> +  return StmtStack.pop_back_val();
> }
> 
> Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=107087&r1=107086&r2=107087&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
> +++ cfe/trunk/lib/Frontend/PCHWriter.cpp Mon Jun 28 17:28:35 2010
> @@ -2056,8 +2056,8 @@
> 
> PCHWriter::PCHWriter(llvm::BitstreamWriter &Stream)
>   : Stream(Stream), NextTypeID(pch::NUM_PREDEF_TYPE_IDS),
> -    NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0),
> -    NumVisibleDeclContexts(0), EmittingStmts(false) { }
> +    CollectedStmts(&StmtsToEmit), NumStatements(0), NumMacros(0),
> +    NumLexicalDeclContexts(0), NumVisibleDeclContexts(0) { }
> 
> void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
>                          const char *isysroot) {
> 
> Modified: cfe/trunk/lib/Frontend/PCHWriterStmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterStmt.cpp?rev=107087&r1=107086&r2=107087&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/PCHWriterStmt.cpp (original)
> +++ cfe/trunk/lib/Frontend/PCHWriterStmt.cpp Mon Jun 28 17:28:35 2010
> @@ -147,43 +147,8 @@
>   };
> }
> 
> -/// \brief Return the number of Exprs contained in the given TemplateArgument.
> -static unsigned NumExprsContainedIn(const TemplateArgument &Arg) {
> -  switch (Arg.getKind()) {
> -  default: break;
> -  case TemplateArgument::Expression:
> -    return 1;
> -  case TemplateArgument::Pack: {
> -    unsigned Count = 0;
> -    for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end();
> -           I != E; ++I)
> -      Count += NumExprsContainedIn(*I);
> -    return Count;
> -  }
> -  }
> -  
> -  return 0;
> -}
> -
> -/// \brief Return the number of Exprs contained in the given
> -/// ExplicitTemplateArgumentList.
> -static unsigned NumExprsContainedIn(const ExplicitTemplateArgumentList &Args) {
> -  unsigned Count = 0;
> -  for (unsigned i=0; i != Args.NumTemplateArgs; ++i) {
> -    const TemplateArgumentLoc &ArgLoc = Args.getTemplateArgs()[i];
> -    const TemplateArgument &TemplA = ArgLoc.getArgument();
> -    Count += NumExprsContainedIn(TemplA);
> -    if (TemplA.getKind() == TemplateArgument::Expression &&
> -        TemplA.getAsExpr() != ArgLoc.getLocInfo().getAsExpr())
> -      ++Count; // 1 in TemplateArgumentLocInfo.
> -  }
> -  
> -  return Count;
> -}
> -
> void PCHStmtWriter::
> AddExplicitTemplateArgumentList(const ExplicitTemplateArgumentList &Args) {
> -  Record.push_back(NumExprsContainedIn(Args));
>   Writer.AddSourceLocation(Args.LAngleLoc, Record);
>   Writer.AddSourceLocation(Args.RAngleLoc, Record);
>   for (unsigned i=0; i != Args.NumTemplateArgs; ++i)
> @@ -204,7 +169,7 @@
>   Record.push_back(S->size());
>   for (CompoundStmt::body_iterator CS = S->body_begin(), CSEnd = S->body_end();
>        CS != CSEnd; ++CS)
> -    Writer.WriteSubStmt(*CS);
> +    Writer.AddStmt(*CS);
>   Writer.AddSourceLocation(S->getLBracLoc(), Record);
>   Writer.AddSourceLocation(S->getRBracLoc(), Record);
>   Code = pch::STMT_COMPOUND;
> @@ -212,14 +177,14 @@
> 
> void PCHStmtWriter::VisitSwitchCase(SwitchCase *S) {
>   VisitStmt(S);
> -  Record.push_back(Writer.RecordSwitchCaseID(S));
> +  Record.push_back(Writer.getSwitchCaseID(S));
> }
> 
> void PCHStmtWriter::VisitCaseStmt(CaseStmt *S) {
>   VisitSwitchCase(S);
> -  Writer.WriteSubStmt(S->getLHS());
> -  Writer.WriteSubStmt(S->getRHS());
> -  Writer.WriteSubStmt(S->getSubStmt());
> +  Writer.AddStmt(S->getLHS());
> +  Writer.AddStmt(S->getRHS());
> +  Writer.AddStmt(S->getSubStmt());
>   Writer.AddSourceLocation(S->getCaseLoc(), Record);
>   Writer.AddSourceLocation(S->getEllipsisLoc(), Record);
>   Writer.AddSourceLocation(S->getColonLoc(), Record);
> @@ -228,7 +193,7 @@
> 
> void PCHStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
>   VisitSwitchCase(S);
> -  Writer.WriteSubStmt(S->getSubStmt());
> +  Writer.AddStmt(S->getSubStmt());
>   Writer.AddSourceLocation(S->getDefaultLoc(), Record);
>   Writer.AddSourceLocation(S->getColonLoc(), Record);
>   Code = pch::STMT_DEFAULT;
> @@ -237,7 +202,7 @@
> void PCHStmtWriter::VisitLabelStmt(LabelStmt *S) {
>   VisitStmt(S);
>   Writer.AddIdentifierRef(S->getID(), Record);
> -  Writer.WriteSubStmt(S->getSubStmt());
> +  Writer.AddStmt(S->getSubStmt());
>   Writer.AddSourceLocation(S->getIdentLoc(), Record);
>   Record.push_back(Writer.GetLabelID(S));
>   Code = pch::STMT_LABEL;
> @@ -246,9 +211,9 @@
> void PCHStmtWriter::VisitIfStmt(IfStmt *S) {
>   VisitStmt(S);
>   Writer.AddDeclRef(S->getConditionVariable(), Record);
> -  Writer.WriteSubStmt(S->getCond());
> -  Writer.WriteSubStmt(S->getThen());
> -  Writer.WriteSubStmt(S->getElse());
> +  Writer.AddStmt(S->getCond());
> +  Writer.AddStmt(S->getThen());
> +  Writer.AddStmt(S->getElse());
>   Writer.AddSourceLocation(S->getIfLoc(), Record);
>   Writer.AddSourceLocation(S->getElseLoc(), Record);
>   Code = pch::STMT_IF;
> @@ -257,28 +222,28 @@
> void PCHStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
>   VisitStmt(S);
>   Writer.AddDeclRef(S->getConditionVariable(), Record);
> -  Writer.WriteSubStmt(S->getCond());
> -  Writer.WriteSubStmt(S->getBody());
> +  Writer.AddStmt(S->getCond());
> +  Writer.AddStmt(S->getBody());
>   Writer.AddSourceLocation(S->getSwitchLoc(), Record);
>   for (SwitchCase *SC = S->getSwitchCaseList(); SC;
>        SC = SC->getNextSwitchCase())
> -    Record.push_back(Writer.getSwitchCaseID(SC));
> +    Record.push_back(Writer.RecordSwitchCaseID(SC));
>   Code = pch::STMT_SWITCH;
> }
> 
> void PCHStmtWriter::VisitWhileStmt(WhileStmt *S) {
>   VisitStmt(S);
>   Writer.AddDeclRef(S->getConditionVariable(), Record);
> -  Writer.WriteSubStmt(S->getCond());
> -  Writer.WriteSubStmt(S->getBody());
> +  Writer.AddStmt(S->getCond());
> +  Writer.AddStmt(S->getBody());
>   Writer.AddSourceLocation(S->getWhileLoc(), Record);
>   Code = pch::STMT_WHILE;
> }
> 
> void PCHStmtWriter::VisitDoStmt(DoStmt *S) {
>   VisitStmt(S);
> -  Writer.WriteSubStmt(S->getCond());
> -  Writer.WriteSubStmt(S->getBody());
> +  Writer.AddStmt(S->getCond());
> +  Writer.AddStmt(S->getBody());
>   Writer.AddSourceLocation(S->getDoLoc(), Record);
>   Writer.AddSourceLocation(S->getWhileLoc(), Record);
>   Writer.AddSourceLocation(S->getRParenLoc(), Record);
> @@ -287,11 +252,11 @@
> 
> void PCHStmtWriter::VisitForStmt(ForStmt *S) {
>   VisitStmt(S);
> -  Writer.WriteSubStmt(S->getInit());
> -  Writer.WriteSubStmt(S->getCond());
> +  Writer.AddStmt(S->getInit());
> +  Writer.AddStmt(S->getCond());
>   Writer.AddDeclRef(S->getConditionVariable(), Record);
> -  Writer.WriteSubStmt(S->getInc());
> -  Writer.WriteSubStmt(S->getBody());
> +  Writer.AddStmt(S->getInc());
> +  Writer.AddStmt(S->getBody());
>   Writer.AddSourceLocation(S->getForLoc(), Record);
>   Writer.AddSourceLocation(S->getLParenLoc(), Record);
>   Writer.AddSourceLocation(S->getRParenLoc(), Record);
> @@ -310,7 +275,7 @@
>   VisitStmt(S);
>   Writer.AddSourceLocation(S->getGotoLoc(), Record);
>   Writer.AddSourceLocation(S->getStarLoc(), Record);
> -  Writer.WriteSubStmt(S->getTarget());
> +  Writer.AddStmt(S->getTarget());
>   Code = pch::STMT_INDIRECT_GOTO;
> }
> 
> @@ -328,7 +293,7 @@
> 
> void PCHStmtWriter::VisitReturnStmt(ReturnStmt *S) {
>   VisitStmt(S);
> -  Writer.WriteSubStmt(S->getRetValue());
> +  Writer.AddStmt(S->getRetValue());
>   Writer.AddSourceLocation(S->getReturnLoc(), Record);
>   Writer.AddDeclRef(S->getNRVOCandidate(), Record);
>   Code = pch::STMT_RETURN;
> @@ -354,25 +319,25 @@
>   Record.push_back(S->isVolatile());
>   Record.push_back(S->isSimple());
>   Record.push_back(S->isMSAsm());
> -  Writer.WriteSubStmt(S->getAsmString());
> +  Writer.AddStmt(S->getAsmString());
> 
>   // Outputs
>   for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {      
>     Writer.AddIdentifierRef(S->getOutputIdentifier(I), Record);
> -    Writer.WriteSubStmt(S->getOutputConstraintLiteral(I));
> -    Writer.WriteSubStmt(S->getOutputExpr(I));
> +    Writer.AddStmt(S->getOutputConstraintLiteral(I));
> +    Writer.AddStmt(S->getOutputExpr(I));
>   }
> 
>   // Inputs
>   for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
>     Writer.AddIdentifierRef(S->getInputIdentifier(I), Record);
> -    Writer.WriteSubStmt(S->getInputConstraintLiteral(I));
> -    Writer.WriteSubStmt(S->getInputExpr(I));
> +    Writer.AddStmt(S->getInputConstraintLiteral(I));
> +    Writer.AddStmt(S->getInputExpr(I));
>   }
> 
>   // Clobbers
>   for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
> -    Writer.WriteSubStmt(S->getClobber(I));
> +    Writer.AddStmt(S->getClobber(I));
> 
>   Code = pch::STMT_ASM;
> }
> @@ -417,7 +382,7 @@
> 
> void PCHStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getSubExpr());
> +  Writer.AddStmt(E->getSubExpr());
>   Code = pch::EXPR_IMAGINARY_LITERAL;
> }
> 
> @@ -449,13 +414,13 @@
>   VisitExpr(E);
>   Writer.AddSourceLocation(E->getLParen(), Record);
>   Writer.AddSourceLocation(E->getRParen(), Record);
> -  Writer.WriteSubStmt(E->getSubExpr());
> +  Writer.AddStmt(E->getSubExpr());
>   Code = pch::EXPR_PAREN;
> }
> 
> void PCHStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getSubExpr());
> +  Writer.AddStmt(E->getSubExpr());
>   Record.push_back(E->getOpcode()); // FIXME: stable encoding
>   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
>   Code = pch::EXPR_UNARY_OPERATOR;
> @@ -493,7 +458,7 @@
>     }
>   }
>   for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
> -    Writer.WriteSubStmt(E->getIndexExpr(I));
> +    Writer.AddStmt(E->getIndexExpr(I));
>   Code = pch::EXPR_OFFSETOF;
> }
> 
> @@ -504,7 +469,7 @@
>     Writer.AddTypeSourceInfo(E->getArgumentTypeInfo(), Record);
>   else {
>     Record.push_back(0);
> -    Writer.WriteSubStmt(E->getArgumentExpr());
> +    Writer.AddStmt(E->getArgumentExpr());
>   }
>   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
>   Writer.AddSourceLocation(E->getRParenLoc(), Record);
> @@ -513,8 +478,8 @@
> 
> void PCHStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getLHS());
> -  Writer.WriteSubStmt(E->getRHS());
> +  Writer.AddStmt(E->getLHS());
> +  Writer.AddStmt(E->getRHS());
>   Writer.AddSourceLocation(E->getRBracketLoc(), Record);
>   Code = pch::EXPR_ARRAY_SUBSCRIPT;
> }
> @@ -523,16 +488,16 @@
>   VisitExpr(E);
>   Record.push_back(E->getNumArgs());
>   Writer.AddSourceLocation(E->getRParenLoc(), Record);
> -  Writer.WriteSubStmt(E->getCallee());
> +  Writer.AddStmt(E->getCallee());
>   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
>        Arg != ArgEnd; ++Arg)
> -    Writer.WriteSubStmt(*Arg);
> +    Writer.AddStmt(*Arg);
>   Code = pch::EXPR_CALL;
> }
> 
> void PCHStmtWriter::VisitMemberExpr(MemberExpr *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getBase());
> +  Writer.AddStmt(E->getBase());
>   Writer.AddDeclRef(E->getMemberDecl(), Record);
>   Writer.AddSourceLocation(E->getMemberLoc(), Record);
>   Record.push_back(E->isArrow());
> @@ -543,7 +508,7 @@
> 
> void PCHStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getBase());
> +  Writer.AddStmt(E->getBase());
>   Writer.AddSourceLocation(E->getIsaMemberLoc(), Record);
>   Record.push_back(E->isArrow());
>   Code = pch::EXPR_OBJC_ISA;
> @@ -551,14 +516,14 @@
> 
> void PCHStmtWriter::VisitCastExpr(CastExpr *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getSubExpr());
> +  Writer.AddStmt(E->getSubExpr());
>   Record.push_back(E->getCastKind()); // FIXME: stable encoding
> }
> 
> void PCHStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getLHS());
> -  Writer.WriteSubStmt(E->getRHS());
> +  Writer.AddStmt(E->getLHS());
> +  Writer.AddStmt(E->getRHS());
>   Record.push_back(E->getOpcode()); // FIXME: stable encoding
>   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
>   Code = pch::EXPR_BINARY_OPERATOR;
> @@ -573,9 +538,9 @@
> 
> void PCHStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getCond());
> -  Writer.WriteSubStmt(E->getLHS());
> -  Writer.WriteSubStmt(E->getRHS());
> +  Writer.AddStmt(E->getCond());
> +  Writer.AddStmt(E->getLHS());
> +  Writer.AddStmt(E->getRHS());
>   Writer.AddSourceLocation(E->getQuestionLoc(), Record);
>   Writer.AddSourceLocation(E->getColonLoc(), Record);
>   Code = pch::EXPR_CONDITIONAL_OPERATOR;
> @@ -603,14 +568,14 @@
>   VisitExpr(E);
>   Writer.AddSourceLocation(E->getLParenLoc(), Record);
>   Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
> -  Writer.WriteSubStmt(E->getInitializer());
> +  Writer.AddStmt(E->getInitializer());
>   Record.push_back(E->isFileScope());
>   Code = pch::EXPR_COMPOUND_LITERAL;
> }
> 
> void PCHStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getBase());
> +  Writer.AddStmt(E->getBase());
>   Writer.AddIdentifierRef(&E->getAccessor(), Record);
>   Writer.AddSourceLocation(E->getAccessorLoc(), Record);
>   Code = pch::EXPR_EXT_VECTOR_ELEMENT;
> @@ -620,8 +585,8 @@
>   VisitExpr(E);
>   Record.push_back(E->getNumInits());
>   for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
> -    Writer.WriteSubStmt(E->getInit(I));
> -  Writer.WriteSubStmt(E->getSyntacticForm());
> +    Writer.AddStmt(E->getInit(I));
> +  Writer.AddStmt(E->getSyntacticForm());
>   Writer.AddSourceLocation(E->getLBraceLoc(), Record);
>   Writer.AddSourceLocation(E->getRBraceLoc(), Record);
>   Writer.AddDeclRef(E->getInitializedFieldInUnion(), Record);
> @@ -633,7 +598,7 @@
>   VisitExpr(E);
>   Record.push_back(E->getNumSubExprs());
>   for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
> -    Writer.WriteSubStmt(E->getSubExpr(I));
> +    Writer.AddStmt(E->getSubExpr(I));
>   Writer.AddSourceLocation(E->getEqualOrColonLoc(), Record);
>   Record.push_back(E->usesGNUSyntax());
>   for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
> @@ -673,7 +638,7 @@
> 
> void PCHStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getSubExpr());
> +  Writer.AddStmt(E->getSubExpr());
>   Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
>   Writer.AddSourceLocation(E->getRParenLoc(), Record);
>   Code = pch::EXPR_VA_ARG;
> @@ -689,7 +654,7 @@
> 
> void PCHStmtWriter::VisitStmtExpr(StmtExpr *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getSubStmt());
> +  Writer.AddStmt(E->getSubStmt());
>   Writer.AddSourceLocation(E->getLParenLoc(), Record);
>   Writer.AddSourceLocation(E->getRParenLoc(), Record);
>   Code = pch::EXPR_STMT;
> @@ -706,9 +671,9 @@
> 
> void PCHStmtWriter::VisitChooseExpr(ChooseExpr *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getCond());
> -  Writer.WriteSubStmt(E->getLHS());
> -  Writer.WriteSubStmt(E->getRHS());
> +  Writer.AddStmt(E->getCond());
> +  Writer.AddStmt(E->getLHS());
> +  Writer.AddStmt(E->getRHS());
>   Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
>   Writer.AddSourceLocation(E->getRParenLoc(), Record);
>   Code = pch::EXPR_CHOOSE;
> @@ -724,7 +689,7 @@
>   VisitExpr(E);
>   Record.push_back(E->getNumSubExprs());
>   for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
> -    Writer.WriteSubStmt(E->getExpr(I));
> +    Writer.AddStmt(E->getExpr(I));
>   Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
>   Writer.AddSourceLocation(E->getRParenLoc(), Record);
>   Code = pch::EXPR_SHUFFLE_VECTOR;
> @@ -743,7 +708,7 @@
>   Writer.AddSourceLocation(E->getLocation(), Record);
>   Record.push_back(E->isByRef());
>   Record.push_back(E->isConstQualAdded());
> -  Writer.WriteSubStmt(E->getCopyConstructorExpr());
> +  Writer.AddStmt(E->getCopyConstructorExpr());
>   Code = pch::EXPR_BLOCK_DECL_REF;
> }
> 
> @@ -753,7 +718,7 @@
> 
> void PCHStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
>   VisitExpr(E);
> -  Writer.WriteSubStmt(E->getString());
> +  Writer.AddStmt(E->getString());
>   Writer.AddSourceLocation(E->getAtLoc(), Record);
>   Code = pch::EXPR_OBJC_STRING_LITERAL;
> }
> @@ -786,7 +751,7 @@
>   VisitExpr(E);
>   Writer.AddDeclRef(E->getDecl(), Record);
>   Writer.AddSourceLocation(E->getLocation(), Record);
> -  Writer.WriteSubStmt(E->getBase());
> +  Writer.AddStmt(E->getBase());
>   Record.push_back(E->isArrow());
>   Record.push_back(E->isFreeIvar());
>   Code = pch::EXPR_OBJC_IVAR_REF_EXPR;
> @@ -796,7 +761,7 @@
>   VisitExpr(E);
>   Writer.AddDeclRef(E->getProperty(), Record);
>   Writer.AddSourceLocation(E->getLocation(), Record);
> -  Writer.WriteSubStmt(E->getBase());
> +  Writer.AddStmt(E->getBase());
>   Code = pch::EXPR_OBJC_PROPERTY_REF_EXPR;
> }
> 
> @@ -808,7 +773,7 @@
> 
>   // NOTE: InterfaceDecl and Base are mutually exclusive.
>   Writer.AddDeclRef(E->getInterfaceDecl(), Record);
> -  Writer.WriteSubStmt(E->getBase());
> +  Writer.AddStmt(E->getBase());
>   Writer.AddSourceLocation(E->getLocation(), Record);
>   Writer.AddSourceLocation(E->getClassLoc(), Record);
>   Code = pch::EXPR_OBJC_KVC_REF_EXPR;
> @@ -820,7 +785,7 @@
>   Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
>   switch (E->getReceiverKind()) {
>   case ObjCMessageExpr::Instance:
> -    Writer.WriteSubStmt(E->getInstanceReceiver());
> +    Writer.AddStmt(E->getInstanceReceiver());
>     break;
> 
>   case ObjCMessageExpr::Class:
> @@ -847,7 +812,7 @@
> 
>   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
>        Arg != ArgEnd; ++Arg)
> -    Writer.WriteSubStmt(*Arg);
> +    Writer.AddStmt(*Arg);
>   Code = pch::EXPR_OBJC_MESSAGE_EXPR;
> }
> 
> @@ -859,16 +824,16 @@
> 
> void PCHStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
>   VisitStmt(S);
> -  Writer.WriteSubStmt(S->getElement());
> -  Writer.WriteSubStmt(S->getCollection());
> -  Writer.WriteSubStmt(S->getBody());
> +  Writer.AddStmt(S->getElement());
> +  Writer.AddStmt(S->getCollection());
> +  Writer.AddStmt(S->getBody());
>   Writer.AddSourceLocation(S->getForLoc(), Record);
>   Writer.AddSourceLocation(S->getRParenLoc(), Record);
>   Code = pch::STMT_OBJC_FOR_COLLECTION;
> }
> 
> void PCHStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
> -  Writer.WriteSubStmt(S->getCatchBody());
> +  Writer.AddStmt(S->getCatchBody());
>   Writer.AddDeclRef(S->getCatchParamDecl(), Record);
>   Writer.AddSourceLocation(S->getAtCatchLoc(), Record);
>   Writer.AddSourceLocation(S->getRParenLoc(), Record);
> @@ -876,7 +841,7 @@
> }
> 
> void PCHStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
> -  Writer.WriteSubStmt(S->getFinallyBody());
> +  Writer.AddStmt(S->getFinallyBody());
>   Writer.AddSourceLocation(S->getAtFinallyLoc(), Record);
>   Code = pch::STMT_OBJC_FINALLY;
> }
> @@ -884,24 +849,24 @@
> void PCHStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
>   Record.push_back(S->getNumCatchStmts());
>   Record.push_back(S->getFinallyStmt() != 0);
> -  Writer.WriteSubStmt(S->getTryBody());
> +  Writer.AddStmt(S->getTryBody());
>   for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
> -    Writer.WriteSubStmt(S->getCatchStmt(I));
> +    Writer.AddStmt(S->getCatchStmt(I));
>   if (S->getFinallyStmt())
> -    Writer.WriteSubStmt(S->getFinallyStmt());
> +    Writer.AddStmt(S->getFinallyStmt());
>   Writer.AddSourceLocation(S->getAtTryLoc(), Record);
>   Code = pch::STMT_OBJC_AT_TRY;
> }
> 
> void PCHStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
> -  Writer.WriteSubStmt(S->getSynchExpr());
> -  Writer.WriteSubStmt(S->getSynchBody());
> +  Writer.AddStmt(S->getSynchExpr());
> +  Writer.AddStmt(S->getSynchBody());
>   Writer.AddSourceLocation(S->getAtSynchronizedLoc(), Record);
>   Code = pch::STMT_OBJC_AT_SYNCHRONIZED;
> }
> 
> void PCHStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
> -  Writer.WriteSubStmt(S->getThrowExpr());
> +  Writer.AddStmt(S->getThrowExpr());
>   Writer.AddSourceLocation(S->getThrowLoc(), Record);
>   Code = pch::STMT_OBJC_AT_THROW;
> }
> @@ -925,7 +890,7 @@
>   VisitExpr(E);
>   Record.push_back(E->getNumArgs());
>   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
> -    Writer.WriteSubStmt(E->getArg(I));
> +    Writer.AddStmt(E->getArg(I));
>   Writer.AddDeclRef(E->getConstructor(), Record);
>   Writer.AddSourceLocation(E->getLocation(), Record);
>   Record.push_back(E->isElidable());
> @@ -986,7 +951,7 @@
>     Writer.AddTypeSourceInfo(E->getTypeOperandSourceInfo(), Record);
>     Code = pch::EXPR_CXX_TYPEID_TYPE;
>   } else {
> -    Writer.WriteSubStmt(E->getExprOperand());
> +    Writer.AddStmt(E->getExprOperand());
>     Code = pch::EXPR_CXX_TYPEID_EXPR;
>   }
> }
> @@ -1001,7 +966,7 @@
> void PCHStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
>   VisitExpr(E);
>   Writer.AddSourceLocation(E->getThrowLoc(), Record);
> -  Writer.WriteSubStmt(E->getSubExpr());
> +  Writer.AddStmt(E->getSubExpr());
>   Code = pch::EXPR_CXX_THROW;
> }
> 
> @@ -1010,7 +975,7 @@
>   Writer.AddSourceLocation(E->getUsedLocation(), Record);
>   if (E->isExprStored()) {
>     Record.push_back(1);
> -    Writer.WriteSubStmt(E->getExpr());
> +    Writer.AddStmt(E->getExpr());
>   } else {
>     Record.push_back(0);
>   }
> @@ -1021,7 +986,7 @@
> void PCHStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
>   VisitExpr(E);
>   Writer.AddCXXTemporary(E->getTemporary(), Record);
> -  Writer.WriteSubStmt(E->getSubExpr());
> +  Writer.AddStmt(E->getSubExpr());
>   Code = pch::EXPR_CXX_BIND_TEMPORARY;
> }
> 
> @@ -1047,7 +1012,7 @@
>   Writer.AddSourceLocation(E->getEndLoc(), Record);
>   for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
>        I != e; ++I)
> -    Writer.WriteSubStmt(*I);
> +    Writer.AddStmt(*I);
> 
>   Code = pch::EXPR_CXX_NEW;
> }
> @@ -1057,7 +1022,7 @@
>   Record.push_back(E->isGlobalDelete());
>   Record.push_back(E->isArrayForm());
>   Writer.AddDeclRef(E->getOperatorDelete(), Record);
> -  Writer.WriteSubStmt(E->getArgument());
> +  Writer.AddStmt(E->getArgument());
>   Writer.AddSourceLocation(E->getSourceRange().getBegin(), Record);
> 
>   Code = pch::EXPR_CXX_DELETE;
> @@ -1091,7 +1056,7 @@
>   for (unsigned i = 0, e = E->getNumTemporaries(); i != e; ++i)
>     Writer.AddCXXTemporary(E->getTemporary(i), Record);
> 
> -  Writer.WriteSubStmt(E->getSubExpr());
> +  Writer.AddStmt(E->getSubExpr());
>   Code = pch::EXPR_CXX_EXPR_WITH_TEMPORARIES;
> }
> 
> @@ -1113,9 +1078,9 @@
>   }
> 
>   if (!E->isImplicitAccess())
> -    Writer.WriteSubStmt(E->getBase());
> +    Writer.AddStmt(E->getBase());
>   else
> -    Writer.WriteSubStmt(0);
> +    Writer.AddStmt(0);
>   Writer.AddTypeRef(E->getBaseType(), Record);
>   Record.push_back(E->isArrow());
>   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
> @@ -1156,7 +1121,7 @@
>   Record.push_back(E->arg_size());
>   for (CXXUnresolvedConstructExpr::arg_iterator
>          ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
> -    Writer.WriteSubStmt(*ArgI);
> +    Writer.AddStmt(*ArgI);
>   Writer.AddSourceLocation(E->getTypeBeginLoc(), Record);
>   Writer.AddTypeRef(E->getTypeAsWritten(), Record);
>   Writer.AddSourceLocation(E->getLParenLoc(), Record);
> @@ -1196,7 +1161,7 @@
>   VisitOverloadExpr(E);
>   Record.push_back(E->isArrow());
>   Record.push_back(E->hasUnresolvedUsing());
> -  Writer.WriteSubStmt(!E->isImplicitAccess() ? E->getBase() : 0);
> +  Writer.AddStmt(!E->isImplicitAccess() ? E->getBase() : 0);
>   Writer.AddTypeRef(E->getBaseType(), Record);
>   Writer.AddSourceLocation(E->getOperatorLoc(), Record);
>   Code = pch::EXPR_CXX_UNRESOLVED_MEMBER;
> @@ -1246,12 +1211,16 @@
>   RecordData Record;
>   PCHStmtWriter Writer(*this, Record);
>   ++NumStatements;
> -
> +  
>   if (!S) {
>     Stream.EmitRecord(pch::STMT_NULL_PTR, Record);
>     return;
>   }
> 
> +  // Redirect PCHWriter::AddStmt to collect sub stmts.
> +  llvm::SmallVector<Stmt *, 16> SubStmts;
> +  CollectedStmts = &SubStmts;
> +
>   Writer.Code = pch::STMT_NULL_PTR;
>   Writer.Visit(S);
> 
> @@ -1263,6 +1232,17 @@
>     assert(0 && "Unhandled sub statement writing PCH file");
>   }
> #endif
> +
> +  // Revert PCHWriter::AddStmt.
> +  CollectedStmts = &StmtsToEmit;
> +
> +  // Write the sub stmts in reverse order, last to first. When reading them back
> +  // we will read them in correct order by "pop"ing them from the Stmts stack.
> +  // This simplifies reading and allows to store a variable number of sub stmts
> +  // without knowing it in advance.
> +  while (!SubStmts.empty())
> +    WriteSubStmt(SubStmts.pop_back_val());
> +  
>   Stream.EmitRecord(Writer.Code, Record);
> }
> 
> @@ -1270,41 +1250,18 @@
> /// queue via AddStmt().
> void PCHWriter::FlushStmts() {
>   RecordData Record;
> -  PCHStmtWriter Writer(*this, Record);
> -  
> -  EmittingStmts = true;
> 
>   for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
> -    ++NumStatements;
> -    Stmt *S = StmtsToEmit[I];
> -
> -    if (!S) {
> -      Stream.EmitRecord(pch::STMT_NULL_PTR, Record);
> -      Stream.EmitRecord(pch::STMT_STOP, Record);
> -      continue;
> -    }
> -
> -    Writer.Code = pch::STMT_NULL_PTR;
> -    Writer.Visit(S);
> -#ifndef NDEBUG
> -    if (Writer.Code == pch::STMT_NULL_PTR) {
> -      S->dump();
> -      assert(0 && "Unhandled expression writing PCH file");
> -    }
> -#endif
> -    Stream.EmitRecord(Writer.Code, Record);
> -
> +    WriteSubStmt(StmtsToEmit[I]);
> +    
>     assert(N == StmtsToEmit.size() &&
>            "Substatement writen via AddStmt rather than WriteSubStmt!");
> 
>     // Note that we are at the end of a full expression. Any
>     // expression records that follow this one are part of a different
>     // expression.
> -    Record.clear();
>     Stream.EmitRecord(pch::STMT_STOP, Record);
>   }
> 
> -  EmittingStmts = false;
> -
>   StmtsToEmit.clear();
> }
> 
> Modified: cfe/trunk/test/PCH/exprs.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.c?rev=107087&r1=107086&r2=107087&view=diff
> ==============================================================================
> --- cfe/trunk/test/PCH/exprs.c (original)
> +++ cfe/trunk/test/PCH/exprs.c Mon Jun 28 17:28:35 2010
> @@ -59,6 +59,8 @@
> // CompoundAssignOperator
> addeq_result *int_ptr6 = &integer;
> 
> +add_result_with_typeinfo *int_typeinfo_ptr6;
> +
> // ConditionalOperator
> conditional_operator *double_ptr4 = &floating;
> 
> 
> Modified: cfe/trunk/test/PCH/exprs.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.h?rev=107087&r1=107086&r2=107087&view=diff
> ==============================================================================
> --- cfe/trunk/test/PCH/exprs.h (original)
> +++ cfe/trunk/test/PCH/exprs.h Mon Jun 28 17:28:35 2010
> @@ -72,6 +72,8 @@
> // CompoundLiteral
> typedef typeof((struct S){.x = 3.5}) compound_literal;
> 
> +typedef typeof(i + sizeof(int[i + Enumerator])) add_result_with_typeinfo;
> +
> // ExtVectorElementExpr
> typedef __attribute__(( ext_vector_type(2) )) double double2;
> extern double2 vec2, vec2b;
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list