GorNishanov created this revision.

https://reviews.llvm.org/D31627

Files:
  lib/CodeGen/CGCoroutine.cpp
  test/CodeGenCoroutines/coro-await.cpp


Index: test/CodeGenCoroutines/coro-await.cpp
===================================================================
--- test/CodeGenCoroutines/coro-await.cpp
+++ test/CodeGenCoroutines/coro-await.cpp
@@ -228,3 +228,9 @@
   // CHECK: call void @_ZN5MyAggawEv(%struct.MyAgg* %
   // CHECK: call void @_ZN11AggrAwaiter12await_resumeEv(%struct.Aggr* sret %
 }
+
+// Verifies that we don't crash when awaiting on an lvalue.
+void AwaitLValue() {
+  suspend_always lval;
+  co_await lval;
+}
Index: lib/CodeGen/CGCoroutine.cpp
===================================================================
--- lib/CodeGen/CGCoroutine.cpp
+++ lib/CodeGen/CGCoroutine.cpp
@@ -142,6 +142,12 @@
                                     AwaitKind Kind, AggValueSlot aggSlot,
                                     bool ignoreResult) {
   auto *E = S.getCommonExpr();
+
+  // Skip paththrough operator co_await (present when awaiting on an LValue).
+  if (auto *UO = dyn_cast<UnaryOperator>(E))
+  if (UO->getOpcode() == UO_Coawait)
+    E = UO->getSubExpr();
+
   auto Binder =
       CodeGenFunction::OpaqueValueMappingData::bind(CGF, S.getOpaqueValue(), 
E);
   auto UnbindOnExit = llvm::make_scope_exit([&] { Binder.unbind(CGF); });


Index: test/CodeGenCoroutines/coro-await.cpp
===================================================================
--- test/CodeGenCoroutines/coro-await.cpp
+++ test/CodeGenCoroutines/coro-await.cpp
@@ -228,3 +228,9 @@
   // CHECK: call void @_ZN5MyAggawEv(%struct.MyAgg* %
   // CHECK: call void @_ZN11AggrAwaiter12await_resumeEv(%struct.Aggr* sret %
 }
+
+// Verifies that we don't crash when awaiting on an lvalue.
+void AwaitLValue() {
+  suspend_always lval;
+  co_await lval;
+}
Index: lib/CodeGen/CGCoroutine.cpp
===================================================================
--- lib/CodeGen/CGCoroutine.cpp
+++ lib/CodeGen/CGCoroutine.cpp
@@ -142,6 +142,12 @@
                                     AwaitKind Kind, AggValueSlot aggSlot,
                                     bool ignoreResult) {
   auto *E = S.getCommonExpr();
+
+  // Skip paththrough operator co_await (present when awaiting on an LValue).
+  if (auto *UO = dyn_cast<UnaryOperator>(E))
+  if (UO->getOpcode() == UO_Coawait)
+    E = UO->getSubExpr();
+
   auto Binder =
       CodeGenFunction::OpaqueValueMappingData::bind(CGF, S.getOpaqueValue(), E);
   auto UnbindOnExit = llvm::make_scope_exit([&] { Binder.unbind(CGF); });
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D31627: [coroutines] ... Gor Nishanov via Phabricator via cfe-commits

Reply via email to