From 8a50733034edd6a349b34e2b9f0c8d0a874846d3 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 2 Jul 2010 23:30:15 +0000 Subject: [PATCH] Fix broken PCH support for CXXDefaultArgExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107541 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ExprCXX.h | 13 +++---------- lib/Frontend/PCHReaderStmt.cpp | 19 +++++++++++++------ lib/Frontend/PCHWriterStmt.cpp | 13 +++++++------ 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 4514f96f08..6da32bacd3 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -465,7 +465,6 @@ class CXXDefaultArgExpr : public Expr { /// \brief The location where the default argument expression was used. SourceLocation Loc; -protected: CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) : Expr(SC, param->hasUnparsedDefaultArg() @@ -504,9 +503,6 @@ public: // Retrieve the parameter that the argument was created from. const ParmVarDecl *getParam() const { return Param.getPointer(); } ParmVarDecl *getParam() { return Param.getPointer(); } - - /// isExprStored - Return true if this expression owns the expression. - bool isExprStored() const { return Param.getInt(); } // Retrieve the actual argument to the function call. const Expr *getExpr() const { @@ -519,16 +515,10 @@ public: return *reinterpret_cast (this + 1); return getParam()->getDefaultArg(); } - - void setExpr(Expr *E) { - Param.setInt(true); - Param.setPointer((ParmVarDecl*)E); - } /// \brief Retrieve the location where this default argument was actually /// used. SourceLocation getUsedLocation() const { return Loc; } - void setUsedLocation(SourceLocation L) { Loc = L; } virtual SourceRange getSourceRange() const { // Default argument expressions have no representation in the @@ -544,6 +534,9 @@ public: // Iterators virtual child_iterator child_begin(); virtual child_iterator child_end(); + + friend class PCHStmtReader; + friend class PCHStmtWriter; }; /// CXXTemporary - Represents a C++ temporary. diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp index b9751e8496..c2dea3adc2 100644 --- a/lib/Frontend/PCHReaderStmt.cpp +++ b/lib/Frontend/PCHReaderStmt.cpp @@ -982,10 +982,11 @@ void PCHStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) { void PCHStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { VisitExpr(E); - E->setUsedLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); - bool HasStoredExpr = Record[Idx++]; - if (!HasStoredExpr) return; - E->setExpr(Reader.ReadSubExpr()); + + assert(Record[Idx] == E->Param.getInt() && "We messed up at creation ?"); + ++Idx; // HasOtherExprStored and SubExpr was handled during creation. + E->Param.setPointer(cast(Reader.GetDecl(Record[Idx++]))); + E->Loc = Reader.ReadSourceLocation(Record, Idx); } void PCHStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { @@ -1552,9 +1553,15 @@ Stmt *PCHReader::ReadStmtFromStream(llvm::BitstreamCursor &Cursor) { case pch::EXPR_CXX_THROW: S = new (Context) CXXThrowExpr(Empty); break; - case pch::EXPR_CXX_DEFAULT_ARG: - S = new (Context) CXXDefaultArgExpr(Empty); + case pch::EXPR_CXX_DEFAULT_ARG: { + bool HasOtherExprStored = Record[PCHStmtReader::NumExprFields]; + if (HasOtherExprStored) { + Expr *SubExpr = ReadSubExpr(); + S = CXXDefaultArgExpr::Create(*Context, SourceLocation(), 0, SubExpr); + } else + S = new (Context) CXXDefaultArgExpr(Empty); break; + } case pch::EXPR_CXX_BIND_TEMPORARY: S = new (Context) CXXBindTemporaryExpr(Empty); break; diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp index 11b1afd373..12fcde845e 100644 --- a/lib/Frontend/PCHWriterStmt.cpp +++ b/lib/Frontend/PCHWriterStmt.cpp @@ -983,13 +983,14 @@ void PCHStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) { void PCHStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { VisitExpr(E); - Writer.AddSourceLocation(E->getUsedLocation(), Record); - if (E->isExprStored()) { - Record.push_back(1); + + bool HasOtherExprStored = E->Param.getInt(); + // Store these first, the reader reads them before creation. + Record.push_back(HasOtherExprStored); + if (HasOtherExprStored) Writer.AddStmt(E->getExpr()); - } else { - Record.push_back(0); - } + Writer.AddDeclRef(E->getParam(), Record); + Writer.AddSourceLocation(E->getUsedLocation(), Record); Code = pch::EXPR_CXX_DEFAULT_ARG; } -- 2.40.0