llvm-project
llvm-project copied to clipboard
Question about static analisys (long lived coro references)
Is there are (or will be) clang diagnostic for coroutine frame "long lived outside references"?
Here what i mean:
// case 0: coroutine args
// coroutine_lifetimebound handles this, it cannot be handled on declaration, how this attribute tries to do,
// i think it should be more like clang::noescape
coro_t foo(int& i) {
co_await bar();
use(i); // possible UB, 'i' destroyed
}
// case 1: frame reference to outside
coro_t foo() {
// map is outside of coroutine frame (or someone have references to it outside of coroutine frame) and not global constant
auto& i = map[key];
// real co_await, e.g. not (await_ready == always true
// || await_suspend always return false
// || await_suspend always returns same handle which is accepted)
co_await bar();
use(i); // possible UB, someone deleted map[key] while coroutine was suspended, can happen even with single thread
}
In other words, will it be detectable sometime? Reference or reference like type (string_view. something which includes reference like type as member etc) which is created before suspension point and from source, which is escaped from coroutine frame somehow and used after it?