[PATCH] D31627: [coroutines] Skip over passthrough operator co_await

Gor Nishanov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 3 14:08:12 PDT 2017


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); });


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31627.93945.patch
Type: text/x-patch
Size: 1204 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170403/41017372/attachment-0001.bin>


More information about the cfe-commits mailing list