[PATCH] D33797: [coroutines] Fix rebuilding of dependent coroutine parameters

Gor Nishanov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 1 13:03:13 PDT 2017


GorNishanov created this revision.

We were not handling correctly rebuilding of parameter and were not creating copies for them.
With this checking, we will be always rebuilding parameter moves in TreeTransform's TransformCoroutineBodyStmt.


https://reviews.llvm.org/D33797

Files:
  lib/Sema/CoroutineStmtBuilder.h
  lib/Sema/SemaCoroutine.cpp
  lib/Sema/TreeTransform.h
  test/CodeGenCoroutines/coro-params.cpp


Index: test/CodeGenCoroutines/coro-params.cpp
===================================================================
--- test/CodeGenCoroutines/coro-params.cpp
+++ test/CodeGenCoroutines/coro-params.cpp
@@ -93,3 +93,26 @@
   // CHECK-NEXT: call void @_ZN8MoveOnlyD1Ev(%struct.MoveOnly* %[[MoCopy]]
   // CHECK-NEXT: call i8* @llvm.coro.free(
 }
+
+// CHECK-LABEL: void @_Z16dependent_paramsI1AEvT_(%struct.A* %x
+template <typename T>
+void dependent_params(T x) {
+  // CHECK: %[[x_copy:.+]] = alloca %struct.A
+
+  // CHECK: call i8* @llvm.coro.begin
+  // CHECK-NEXT: call void @_ZN1AC1EOS_(%struct.A* %x1, %struct.A* dereferenceable(512) %x)
+  // CHECK-NEXT: call void @_ZNSt12experimental16coroutine_traitsIJv1AEE12promise_typeC1Ev
+
+  co_return;
+}
+
+struct A {
+  int WontFitIntoRegisterForSure[128];
+  A();
+  A(A&&);
+  ~A();
+};
+
+void call_dependent_params() {
+  dependent_params(A{});
+}
Index: lib/Sema/TreeTransform.h
===================================================================
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -6959,6 +6959,7 @@
       Builder.ReturnStmt = Res.get();
     }
   }
+  Builder.buildParameterMoves();
 
   return getDerived().RebuildCoroutineBodyStmt(Builder);
 }
Index: lib/Sema/SemaCoroutine.cpp
===================================================================
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -822,6 +822,12 @@
   return this->IsValid;
 }
 
+bool CoroutineStmtBuilder::buildParameterMoves() {
+  assert(this->IsValid && "coroutine already invalid");
+  assert(this->ParamMoves.empty() && "param moves already built");
+  return this->IsValid = makeParamMoves();
+}
+
 bool CoroutineStmtBuilder::buildDependentStatements() {
   assert(this->IsValid && "coroutine already invalid");
   assert(!this->IsPromiseDependentType &&
Index: lib/Sema/CoroutineStmtBuilder.h
===================================================================
--- lib/Sema/CoroutineStmtBuilder.h
+++ lib/Sema/CoroutineStmtBuilder.h
@@ -51,6 +51,9 @@
   /// name lookup.
   bool buildDependentStatements();
 
+  /// \brief Build just parameter moves. To use for rebuilding in TreeTransform.
+  bool buildParameterMoves();
+
   bool isInvalid() const { return !this->IsValid; }
 
 private:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33797.101087.patch
Type: text/x-patch
Size: 2264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170601/1b43bb1d/attachment.bin>


More information about the cfe-commits mailing list