EricWF created this revision. Previously Clang incorrectly ignored the expression of a void `co_return`. This patch addresses that bug.
I'm not quite sure if I got the code-gen right, but this patch is at least a start. https://reviews.llvm.org/D36070 Files: lib/CodeGen/CGCoroutine.cpp test/CodeGenCoroutines/coro-ret-void.cpp Index: test/CodeGenCoroutines/coro-ret-void.cpp =================================================================== --- test/CodeGenCoroutines/coro-ret-void.cpp +++ test/CodeGenCoroutines/coro-ret-void.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s +// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -munwind-tables -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s #include "Inputs/coroutine.h" @@ -21,6 +21,20 @@ // CHECK: call void @_ZNSt12experimental13coroutines_v113suspend_never12await_resumeEv(%"struct.std::experimental::coroutines_v1::suspend_never"* // CHECK: call void @_ZN5coro112promise_type11return_voidEv(%"struct.coro1::promise_type"* %__promise) +struct A { + A(); + ~A(); +}; + +coro1 f2() { + co_return(void) A{}; +} + +// CHECK-LABEL: define void @_Z2f2v( +// CHECK: call void @_ZN1AC1Ev(%struct.A* %[[AVar:.*]]) +// CHECK-NEXT: call void @_ZN1AD1Ev(%struct.A* %[[AVar]]) +// CHECK-NEXT: call void @_ZN5coro112promise_type11return_voidEv(%"struct.coro1::promise_type"* + struct coro2 { struct promise_type { coro2 get_return_object(); Index: lib/CodeGen/CGCoroutine.cpp =================================================================== --- lib/CodeGen/CGCoroutine.cpp +++ lib/CodeGen/CGCoroutine.cpp @@ -234,6 +234,13 @@ void CodeGenFunction::EmitCoreturnStmt(CoreturnStmt const &S) { ++CurCoro.Data->CoreturnCount; + const Expr *RV = S.getOperand(); + if (RV && RV->getType()->isVoidType()) { + // Make sure to evaluate the expression of a co_return with a void + // expression for side effects. + RunCleanupsScope cleanupScope(*this); + EmitIgnoredExpr(RV); + } EmitStmt(S.getPromiseCall()); EmitBranchThroughCleanup(CurCoro.Data->FinalJD); }
Index: test/CodeGenCoroutines/coro-ret-void.cpp =================================================================== --- test/CodeGenCoroutines/coro-ret-void.cpp +++ test/CodeGenCoroutines/coro-ret-void.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s +// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -munwind-tables -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s #include "Inputs/coroutine.h" @@ -21,6 +21,20 @@ // CHECK: call void @_ZNSt12experimental13coroutines_v113suspend_never12await_resumeEv(%"struct.std::experimental::coroutines_v1::suspend_never"* // CHECK: call void @_ZN5coro112promise_type11return_voidEv(%"struct.coro1::promise_type"* %__promise) +struct A { + A(); + ~A(); +}; + +coro1 f2() { + co_return(void) A{}; +} + +// CHECK-LABEL: define void @_Z2f2v( +// CHECK: call void @_ZN1AC1Ev(%struct.A* %[[AVar:.*]]) +// CHECK-NEXT: call void @_ZN1AD1Ev(%struct.A* %[[AVar]]) +// CHECK-NEXT: call void @_ZN5coro112promise_type11return_voidEv(%"struct.coro1::promise_type"* + struct coro2 { struct promise_type { coro2 get_return_object(); Index: lib/CodeGen/CGCoroutine.cpp =================================================================== --- lib/CodeGen/CGCoroutine.cpp +++ lib/CodeGen/CGCoroutine.cpp @@ -234,6 +234,13 @@ void CodeGenFunction::EmitCoreturnStmt(CoreturnStmt const &S) { ++CurCoro.Data->CoreturnCount; + const Expr *RV = S.getOperand(); + if (RV && RV->getType()->isVoidType()) { + // Make sure to evaluate the expression of a co_return with a void + // expression for side effects. + RunCleanupsScope cleanupScope(*this); + EmitIgnoredExpr(RV); + } EmitStmt(S.getPromiseCall()); EmitBranchThroughCleanup(CurCoro.Data->FinalJD); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits