[llvm-branch-commits] [cfe-branch] r309954 - Merging r308996:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Aug 3 09:12:52 PDT 2017


Author: hans
Date: Thu Aug  3 09:12:51 2017
New Revision: 309954

URL: http://llvm.org/viewvc/llvm-project?rev=309954&view=rev
Log:
Merging r308996:
------------------------------------------------------------------------
r308996 | gornishanov | 2017-07-25 11:01:49 -0700 (Tue, 25 Jul 2017) | 9 lines

[coroutines] Add serialization/deserialization of coroutines

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: EricWF, cfe-commits

Differential Revision: https://reviews.llvm.org/D35383
------------------------------------------------------------------------

Added:
    cfe/branches/release_50/test/PCH/coroutines.cpp
      - copied unchanged from r308996, cfe/trunk/test/PCH/coroutines.cpp
Modified:
    cfe/branches/release_50/   (props changed)
    cfe/branches/release_50/include/clang/AST/StmtCXX.h
    cfe/branches/release_50/include/clang/Serialization/ASTBitCodes.h
    cfe/branches/release_50/lib/AST/StmtCXX.cpp
    cfe/branches/release_50/lib/Serialization/ASTReaderStmt.cpp
    cfe/branches/release_50/lib/Serialization/ASTWriterStmt.cpp

Propchange: cfe/branches/release_50/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug  3 09:12:51 2017
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:308455,308824,308897,309058,309112-309113,309226,309327,309382-309383,309488,309503,309523,309722,309752
+/cfe/trunk:308455,308824,308897,308996,309058,309112-309113,309226,309327,309382-309383,309488,309503,309523,309722,309752
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_50/include/clang/AST/StmtCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/include/clang/AST/StmtCXX.h?rev=309954&r1=309953&r2=309954&view=diff
==============================================================================
--- cfe/branches/release_50/include/clang/AST/StmtCXX.h (original)
+++ cfe/branches/release_50/include/clang/AST/StmtCXX.h Thu Aug  3 09:12:51 2017
@@ -317,6 +317,7 @@ class CoroutineBodyStmt final
   unsigned NumParams;
 
   friend class ASTStmtReader;
+  friend class ASTReader;
   friend TrailingObjects;
 
   Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); }
@@ -347,6 +348,8 @@ private:
 
 public:
   static CoroutineBodyStmt *Create(const ASTContext &C, CtorArgs const &Args);
+  static CoroutineBodyStmt *Create(const ASTContext &C, EmptyShell,
+                                   unsigned NumParams);
 
   bool hasDependentPromiseType() const {
     return getPromiseDecl()->getType()->isDependentType();
@@ -444,6 +447,8 @@ public:
     SubStmts[SubStmt::PromiseCall] = PromiseCall;
   }
 
+  CoreturnStmt(EmptyShell) : CoreturnStmt({}, {}, {}) {}
+
   SourceLocation getKeywordLoc() const { return CoreturnLoc; }
 
   /// \brief Retrieve the operand of the 'co_return' statement. Will be nullptr

Modified: cfe/branches/release_50/include/clang/Serialization/ASTBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/include/clang/Serialization/ASTBitCodes.h?rev=309954&r1=309953&r2=309954&view=diff
==============================================================================
--- cfe/branches/release_50/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/branches/release_50/include/clang/Serialization/ASTBitCodes.h Thu Aug  3 09:12:51 2017
@@ -1545,9 +1545,14 @@ namespace clang {
 
       // ARC
       EXPR_OBJC_BRIDGED_CAST,     // ObjCBridgedCastExpr
-      
+
       STMT_MS_DEPENDENT_EXISTS,   // MSDependentExistsStmt
-      EXPR_LAMBDA                 // LambdaExpr
+      EXPR_LAMBDA,                // LambdaExpr
+      STMT_COROUTINE_BODY,
+      STMT_CORETURN,
+      EXPR_COAWAIT,
+      EXPR_COYIELD,
+      EXPR_DEPENDENT_COAWAIT,
     };
 
     /// \brief The kinds of designators that can occur in a

Modified: cfe/branches/release_50/lib/AST/StmtCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/AST/StmtCXX.cpp?rev=309954&r1=309953&r2=309954&view=diff
==============================================================================
--- cfe/branches/release_50/lib/AST/StmtCXX.cpp (original)
+++ cfe/branches/release_50/lib/AST/StmtCXX.cpp Thu Aug  3 09:12:51 2017
@@ -96,6 +96,20 @@ CoroutineBodyStmt *CoroutineBodyStmt::Cr
   return new (Mem) CoroutineBodyStmt(Args);
 }
 
+CoroutineBodyStmt *CoroutineBodyStmt::Create(const ASTContext &C, EmptyShell,
+                                             unsigned NumParams) {
+  std::size_t Size = totalSizeToAlloc<Stmt *>(
+      CoroutineBodyStmt::FirstParamMove + NumParams);
+
+  void *Mem = C.Allocate(Size, alignof(CoroutineBodyStmt));
+  auto *Result = new (Mem) CoroutineBodyStmt(CtorArgs());
+  Result->NumParams = NumParams;
+  auto *ParamBegin = Result->getStoredStmts() + SubStmt::FirstParamMove;
+  std::uninitialized_fill(ParamBegin, ParamBegin + NumParams,
+                          static_cast<Stmt *>(nullptr));
+  return Result;
+}
+
 CoroutineBodyStmt::CoroutineBodyStmt(CoroutineBodyStmt::CtorArgs const &Args)
     : Stmt(CoroutineBodyStmtClass), NumParams(Args.ParamMoves.size()) {
   Stmt **SubStmts = getStoredStmts();

Modified: cfe/branches/release_50/lib/Serialization/ASTReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/Serialization/ASTReaderStmt.cpp?rev=309954&r1=309953&r2=309954&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/branches/release_50/lib/Serialization/ASTReaderStmt.cpp Thu Aug  3 09:12:51 2017
@@ -367,28 +367,45 @@ void ASTStmtReader::VisitMSAsmStmt(MSAsm
 }
 
 void ASTStmtReader::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) {
-  // FIXME: Implement coroutine serialization.
-  llvm_unreachable("unimplemented");
+  VisitStmt(S);
+  assert(Record.peekInt() == S->NumParams);
+  Record.skipInts(1);
+  auto *StoredStmts = S->getStoredStmts();
+  for (unsigned i = 0;
+       i < CoroutineBodyStmt::SubStmt::FirstParamMove + S->NumParams; ++i)
+    StoredStmts[i] = Record.readSubStmt();
 }
 
 void ASTStmtReader::VisitCoreturnStmt(CoreturnStmt *S) {
-  // FIXME: Implement coroutine serialization.
-  llvm_unreachable("unimplemented");
+  VisitStmt(S);
+  S->CoreturnLoc = Record.readSourceLocation();
+  for (auto &SubStmt: S->SubStmts)
+    SubStmt = Record.readSubStmt();
+  S->IsImplicit = Record.readInt() != 0;
 }
 
-void ASTStmtReader::VisitCoawaitExpr(CoawaitExpr *S) {
-  // FIXME: Implement coroutine serialization.
-  llvm_unreachable("unimplemented");
+void ASTStmtReader::VisitCoawaitExpr(CoawaitExpr *E) {
+  VisitExpr(E);
+  E->KeywordLoc = ReadSourceLocation();
+  for (auto &SubExpr: E->SubExprs)
+    SubExpr = Record.readSubStmt();
+  E->OpaqueValue = cast_or_null<OpaqueValueExpr>(Record.readSubStmt());
+  E->setIsImplicit(Record.readInt() != 0);
 }
 
-void ASTStmtReader::VisitDependentCoawaitExpr(DependentCoawaitExpr *S) {
-  // FIXME: Implement coroutine serialization.
-  llvm_unreachable("unimplemented");
+void ASTStmtReader::VisitCoyieldExpr(CoyieldExpr *E) {
+  VisitExpr(E);
+  E->KeywordLoc = ReadSourceLocation();
+  for (auto &SubExpr: E->SubExprs)
+    SubExpr = Record.readSubStmt();
+  E->OpaqueValue = cast_or_null<OpaqueValueExpr>(Record.readSubStmt());
 }
 
-void ASTStmtReader::VisitCoyieldExpr(CoyieldExpr *S) {
-  // FIXME: Implement coroutine serialization.
-  llvm_unreachable("unimplemented");
+void ASTStmtReader::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
+  VisitExpr(E);
+  E->KeywordLoc = ReadSourceLocation();
+  for (auto &SubExpr: E->SubExprs)
+    SubExpr = Record.readSubStmt();
 }
 
 void ASTStmtReader::VisitCapturedStmt(CapturedStmt *S) {
@@ -3947,6 +3964,29 @@ Stmt *ASTReader::ReadStmtFromStream(Modu
       S = LambdaExpr::CreateDeserialized(Context, NumCaptures);
       break;
     }
+
+    case STMT_COROUTINE_BODY: {
+      unsigned NumParams = Record[ASTStmtReader::NumStmtFields];
+      S = CoroutineBodyStmt::Create(Context, Empty, NumParams);
+      break;
+    }
+
+    case STMT_CORETURN:
+      S = new (Context) CoreturnStmt(Empty);
+      break;
+
+    case EXPR_COAWAIT:
+      S = new (Context) CoawaitExpr(Empty);
+      break;
+
+    case EXPR_COYIELD:
+      S = new (Context) CoyieldExpr(Empty);
+      break;
+
+    case EXPR_DEPENDENT_COAWAIT:
+      S = new (Context) DependentCoawaitExpr(Empty);
+      break;
+
     }
 
     // We hit a STMT_STOP, so we're done with this expression.

Modified: cfe/branches/release_50/lib/Serialization/ASTWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/Serialization/ASTWriterStmt.cpp?rev=309954&r1=309953&r2=309954&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/branches/release_50/lib/Serialization/ASTWriterStmt.cpp Thu Aug  3 09:12:51 2017
@@ -286,7 +286,7 @@ void ASTStmtWriter::VisitMSAsmStmt(MSAsm
   }
 
   // Outputs
-  for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {      
+  for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
     Record.AddStmt(S->getOutputExpr(I));
     Record.AddString(S->getOutputConstraint(I));
   }
@@ -300,29 +300,48 @@ void ASTStmtWriter::VisitMSAsmStmt(MSAsm
   Code = serialization::STMT_MSASM;
 }
 
-void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) {
-  // FIXME: Implement coroutine serialization.
-  llvm_unreachable("unimplemented");
+void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
+  VisitStmt(CoroStmt);
+  Record.push_back(CoroStmt->getParamMoves().size());
+  for (Stmt *S : CoroStmt->children())
+    Record.AddStmt(S);
+  Code = serialization::STMT_COROUTINE_BODY;
 }
 
 void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
-  // FIXME: Implement coroutine serialization.
-  llvm_unreachable("unimplemented");
-}
-
-void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *S) {
-  // FIXME: Implement coroutine serialization.
-  llvm_unreachable("unimplemented");
-}
-
-void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *S) {
-  // FIXME: Implement coroutine serialization.
-  llvm_unreachable("unimplemented");
-}
-
-void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *S) {
-  // FIXME: Implement coroutine serialization.
-  llvm_unreachable("unimplemented");
+  VisitStmt(S);
+  Record.AddSourceLocation(S->getKeywordLoc());
+  Record.AddStmt(S->getOperand());
+  Record.AddStmt(S->getPromiseCall());
+  Record.push_back(S->isImplicit());
+  Code = serialization::STMT_CORETURN;
+}
+
+void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
+  VisitExpr(E);
+  Record.AddSourceLocation(E->getKeywordLoc());
+  for (Stmt *S : E->children())
+    Record.AddStmt(S);
+  Record.AddStmt(E->getOpaqueValue());
+}
+
+void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
+  VisitCoroutineSuspendExpr(E);
+  Record.push_back(E->isImplicit());
+  Code = serialization::EXPR_COAWAIT;
+}
+
+void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
+  VisitCoroutineSuspendExpr(E);
+  Code = serialization::EXPR_COYIELD;
+}
+
+void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
+  VisitExpr(E);
+  Record.AddSourceLocation(E->getKeywordLoc());
+  for (Stmt *S : E->children())
+    Record.AddStmt(S);
+  Code = serialization::EXPR_DEPENDENT_COAWAIT;
 }
 
 void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {




More information about the llvm-branch-commits mailing list