[PATCH] D137866: [Coroutines] Do not add allocas for retcon coroutines

Sebastian Neubauer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 11 13:39:07 PST 2022


sebastian-ne created this revision.
sebastian-ne added reviewers: ChuanqiXu, jsilvanus.
Herald added a subscriber: hiraditya.
Herald added a project: All.
sebastian-ne requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Same as for async-style lowering, if there are no resume points in a
function, the coroutine frame pointer will be replaced by an undef,
making all accesses to the frame undefinde behavior.

Fix this by not adding allocas to the coroutine frame if there are no
resume points.

The test is new, I'll pre-commit if this is accepted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137866

Files:
  llvm/lib/Transforms/Coroutines/CoroFrame.cpp
  llvm/test/Transforms/Coroutines/coro-retcon.ll


Index: llvm/test/Transforms/Coroutines/coro-retcon.ll
===================================================================
--- llvm/test/Transforms/Coroutines/coro-retcon.ll
+++ llvm/test/Transforms/Coroutines/coro-retcon.ll
@@ -130,12 +130,17 @@
 define i8* @nosuspend(i8* %buffer, i32 %n) {
 ; CHECK-LABEL: @nosuspend(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    unreachable
+; CHECK-NEXT:    [[A:%.*]] = alloca i32, align 4
+; CHECK-NEXT:    store i32 [[N:%.*]], i32* [[A]], align 4
+; CHECK-NEXT:    call void @use_var_ptr(i32* nonnull [[A]])
+; CHECK-NEXT:    [[AL:%.*]] = load i32, i32* [[A]], align 4
+; CHECK-NEXT:    call void @use_var(i32 [[AL]])
+; CHECK-NEXT:    ret i8* null
 ;
 ; CORO-LABEL: @nosuspend(
 ; CORO-NEXT:  entry:
 ; CORO-NEXT:    [[FRAMEPTR:%.*]] = bitcast i8* undef to %nosuspend.Frame*
-; CORO-NEXT:    [[A:%.*]] = getelementptr inbounds [[NOSUSPEND_FRAME:%.*]], %nosuspend.Frame* [[FRAMEPTR]], i32 0, i32 0
+; CORO-NEXT:    [[A:%.*]] = alloca i32, align 4
 ; CORO-NEXT:    store i32 [[N:%.*]], i32* [[A]], align 4
 ; CORO-NEXT:    call void @use_var_ptr(i32* [[A]])
 ; CORO-NEXT:    [[AL:%.*]] = load i32, i32* [[A]], align 4
Index: llvm/lib/Transforms/Coroutines/CoroFrame.cpp
===================================================================
--- llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -2732,7 +2732,7 @@
       Shape.ABI != coro::ABI::RetconOnce)
     sinkLifetimeStartMarkers(F, Shape, Checker);
 
-  if (Shape.ABI != coro::ABI::Async || !Shape.CoroSuspends.empty())
+  if (Shape.ABI == coro::ABI::Switch || !Shape.CoroSuspends.empty())
     collectFrameAllocas(F, Shape, Checker, FrameData.Allocas);
   LLVM_DEBUG(dumpAllocas(FrameData.Allocas));
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137866.474851.patch
Type: text/x-patch
Size: 1739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221111/bc4832ba/attachment.bin>


More information about the llvm-commits mailing list