2020-02-04 02:09:39 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s
|
2017-05-24 22:19:48 +08:00
|
|
|
|
|
|
|
#include "Inputs/coroutine.h"
|
|
|
|
|
|
|
|
namespace coro = std::experimental::coroutines_v1;
|
|
|
|
|
|
|
|
struct coro1 {
|
|
|
|
struct promise_type {
|
|
|
|
coro1 get_return_object();
|
|
|
|
coro::suspend_never initial_suspend();
|
[Coroutines] Ensure co_await promise.final_suspend() does not throw
Summary:
This patch addresses https://bugs.llvm.org/show_bug.cgi?id=46256
The spec of coroutine requires that the expression co_await promise.final_suspend() shall not be potentially-throwing.
To check this, we recursively look at every call (including Call, MemberCall, OperatorCall and Constructor) in all code
generated by the final suspend, and ensure that the callees are declared with noexcept. We also look at any returned data
type that requires explicit destruction, and check their destructors for noexcept.
This patch does not check declarations with dependent types yet, which will be done in future patches.
Updated all tests to add noexcept to the required functions, and added a dedicated test for this patch.
This patch might start to cause existing codebase fail to compile because most people may not have been strict in tagging
all the related functions noexcept.
Reviewers: lewissbaker, modocache, junparser
Reviewed By: modocache
Subscribers: arphaman, junparser, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82029
2020-06-16 07:27:41 +08:00
|
|
|
coro::suspend_never final_suspend() noexcept;
|
2017-05-24 22:19:48 +08:00
|
|
|
void return_void();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
coro1 f() {
|
|
|
|
co_await coro::suspend_never{};
|
|
|
|
}
|
|
|
|
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z1fv(
|
2017-05-24 22:19:48 +08:00
|
|
|
// CHECK: call void @_ZNSt12experimental13coroutines_v113suspend_never12await_resumeEv(%"struct.std::experimental::coroutines_v1::suspend_never"*
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5coro112promise_type11return_voidEv(%"struct.coro1::promise_type"* {{[^,]*}} %__promise)
|
2017-05-24 22:19:48 +08:00
|
|
|
|
2017-07-31 15:48:13 +08:00
|
|
|
struct A {
|
|
|
|
A();
|
|
|
|
~A();
|
|
|
|
};
|
|
|
|
|
|
|
|
coro1 f2() {
|
|
|
|
co_return (void) A{};
|
|
|
|
}
|
|
|
|
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z2f2v(
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN1AC1Ev(%struct.A* {{[^,]*}} %[[AVar:.*]])
|
|
|
|
// CHECK-NEXT: call void @_ZN1AD1Ev(%struct.A* {{[^,]*}} %[[AVar]])
|
2017-07-31 15:48:13 +08:00
|
|
|
// CHECK-NEXT: call void @_ZN5coro112promise_type11return_voidEv(%"struct.coro1::promise_type"*
|
|
|
|
|
2017-05-24 22:19:48 +08:00
|
|
|
struct coro2 {
|
|
|
|
struct promise_type {
|
|
|
|
coro2 get_return_object();
|
|
|
|
coro::suspend_never initial_suspend();
|
[Coroutines] Ensure co_await promise.final_suspend() does not throw
Summary:
This patch addresses https://bugs.llvm.org/show_bug.cgi?id=46256
The spec of coroutine requires that the expression co_await promise.final_suspend() shall not be potentially-throwing.
To check this, we recursively look at every call (including Call, MemberCall, OperatorCall and Constructor) in all code
generated by the final suspend, and ensure that the callees are declared with noexcept. We also look at any returned data
type that requires explicit destruction, and check their destructors for noexcept.
This patch does not check declarations with dependent types yet, which will be done in future patches.
Updated all tests to add noexcept to the required functions, and added a dedicated test for this patch.
This patch might start to cause existing codebase fail to compile because most people may not have been strict in tagging
all the related functions noexcept.
Reviewers: lewissbaker, modocache, junparser
Reviewed By: modocache
Subscribers: arphaman, junparser, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82029
2020-06-16 07:27:41 +08:00
|
|
|
coro::suspend_never final_suspend() noexcept;
|
2017-05-24 22:19:48 +08:00
|
|
|
void return_value(int);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
coro2 g() {
|
|
|
|
co_return 42;
|
|
|
|
}
|
|
|
|
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z1gv(
|
2017-05-24 22:19:48 +08:00
|
|
|
// CHECK: call void @_ZNSt12experimental13coroutines_v113suspend_never12await_resumeEv(%"struct.std::experimental::coroutines_v1::suspend_never"*
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5coro212promise_type12return_valueEi(%"struct.coro2::promise_type"* {{[^,]*}} %__promise, i32 42)
|