[PATCH] D87470: [Coroutine][Sema] Tighten the lifetime of symmetric transfer returned handle

Xun Li via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 10 10:27:05 PDT 2020


lxfind created this revision.
lxfind added reviewers: lewissbaker, wenlei, hoy, bruno, junparser, rjmccall.
Herald added subscribers: cfe-commits, dexonsmith, modocache.
Herald added a project: clang.
lxfind requested review of this revision.

In generating the code for symmetric transfer, a temporary object is created to store the returned handle from await_suspend() call of the awaiter. Previously this temp won't be cleaned up until very later, which ends up causing this temp to be spilled to the heap. However, we know that this temp will no longer be needed after the coro_resume call. We can clean it up right after.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87470

Files:
  clang/lib/Sema/SemaCoroutine.cpp


Index: clang/lib/Sema/SemaCoroutine.cpp
===================================================================
--- clang/lib/Sema/SemaCoroutine.cpp
+++ clang/lib/Sema/SemaCoroutine.cpp
@@ -398,8 +398,8 @@
            diag::warn_coroutine_handle_address_invalid_return_type)
         << JustAddress->getType();
 
-  return buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_resume,
-                          JustAddress);
+  return S.MaybeCreateExprWithCleanups(
+      buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_resume, JustAddress));
 }
 
 /// Build calls to await_ready, await_suspend, and await_resume for a co_await


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87470.291023.patch
Type: text/x-patch
Size: 626 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200910/153adcc4/attachment-0001.bin>


More information about the cfe-commits mailing list