[cfe-commits] r107541 - in /cfe/trunk: include/clang/AST/ExprCXX.h lib/Frontend/PCHReaderStmt.cpp lib/Frontend/PCHWriterStmt.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Jul 2 16:30:15 PDT 2010


Author: akirtzidis
Date: Fri Jul  2 18:30:15 2010
New Revision: 107541

URL: http://llvm.org/viewvc/llvm-project?rev=107541&view=rev
Log:
Fix broken PCH support for CXXDefaultArgExpr.

Modified:
    cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
    cfe/trunk/lib/Frontend/PCHWriterStmt.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=107541&r1=107540&r2=107541&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Fri Jul  2 18:30:15 2010
@@ -465,7 +465,6 @@
   /// \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 @@
   // 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 @@
       return *reinterpret_cast<Expr **> (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 @@
   // Iterators
   virtual child_iterator child_begin();
   virtual child_iterator child_end();
+
+  friend class PCHStmtReader;
+  friend class PCHStmtWriter;
 };
 
 /// CXXTemporary - Represents a C++ temporary.

Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=107541&r1=107540&r2=107541&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Fri Jul  2 18:30:15 2010
@@ -982,10 +982,11 @@
 
 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<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
+  E->Loc = Reader.ReadSourceLocation(Record, Idx);
 }
 
 void PCHStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
@@ -1552,9 +1553,15 @@
     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;

Modified: cfe/trunk/lib/Frontend/PCHWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterStmt.cpp?rev=107541&r1=107540&r2=107541&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterStmt.cpp Fri Jul  2 18:30:15 2010
@@ -983,13 +983,14 @@
 
 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;
 }





More information about the cfe-commits mailing list