[clang] [clang-tools-extra] [clang-tidy] Add support for use-after-suspend to bugprone-use-after-move (PR #172566)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 15 12:03:56 PST 2026
================
@@ -254,6 +255,33 @@ forget to add the reinitialization for this additional member. Instead, it is
safer to assign to the entire struct in one go, and this will also avoid the
use-after-move warning.
+Coroutines
+----------
+
+This check also searches for occurrences of "use-after-suspend" in C++
+coroutines. This can be used, for example, to detect when a coroutine accesses
+thread-local data after a suspension point (i.e. ``co_yield`` or ``co_await``),
+where the reference or pointer used to access the data was acquired prior to
+the suspension point. Such situations can be dangerous as the referenced memory
+may belong to a different thread after suspension, or have been deallocated
+entirely by the time the coroutine resumes.
+
+Note that, for any use-after-suspend to be flagged,
+:option:`NonlocalAccessors` must be non-empty actually match some functions.
+For example, if we have:
+
+.. code-block:: c++
+
+ CustomAwaitable AwaitResponse();
+
+ int* thread_data = GetThreadLocalData();
+ co_await AwaitResponse(); // suspension
+ return *thread_data; // use after suspension
+
+then :option:`NonlocalAccessors` must match ``GetThreadLocalData``, and
----------------
vbvictor wrote:
```suggestion
then :option:`NonlocalAccessors` must have ``GetThreadLocalData``, and
```
Or I'm misunderstanding something?
https://github.com/llvm/llvm-project/pull/172566
More information about the cfe-commits
mailing list