[all-commits] [llvm/llvm-project] 190a75: [coroutines] Introduce [[clang::coro_disable_lifet...
Utkarsh Saxena via All-commits
all-commits at lists.llvm.org
Fri Jan 5 01:07:18 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 190a75b5f12d3872a5a26d6079d62adae40f147d
https://github.com/llvm/llvm-project/commit/190a75b5f12d3872a5a26d6079d62adae40f147d
Author: Utkarsh Saxena <usx at google.com>
Date: 2024-01-05 (Fri, 05 Jan 2024)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/include/clang/Basic/Attr.td
M clang/include/clang/Basic/AttrDocs.td
M clang/lib/Sema/SemaInit.cpp
M clang/test/Misc/pragma-attribute-supported-attributes-list.test
M clang/test/SemaCXX/coro-lifetimebound.cpp
Log Message:
-----------
[coroutines] Introduce [[clang::coro_disable_lifetimebound]] (#76818)
Lifetime-bound analysis of reference parameters of coroutines and
coroutine wrappers is helpful in surfacing memory bugs associated with
using temporaries and stack variables in call expressions in plain
return statements.
This is the default semantics of `[[clang::coro_lifetimebound]]`. But it
should be okay to relax the requirements for a function when the
reference arguments are not lifetime bound. For example:
A coroutine wrapper accepts a reference parameter but does not pass it
to the underlying coroutine call.
```cpp
[[clang::coro_wrapper]] Task<int> wrapper(const Request& req) {
return req.shouldCallA() ? coroA() : coroB();
}
```
Or passes it the coroutine by value
```cpp
Task<int> coro(std::string s) { co_return s.size(); }
[[clang::coro_wrapper]] wrapper(const std::string& s) { return coro(s); }
```
This patch allows functions to be annotated with
`[[clang::coro_disable_lifetime_bound]]` to disable lifetime bound
analysis for all calls to this function.
---
One missing piece here is a note suggesting using this annotation in
cases of lifetime warnings. This would require some more tweaks in the
lifetimebound analysis to recognize violations involving coroutines only
and produce this note only in those cases.
More information about the All-commits
mailing list