[clang] Thread Safety Analysis: Basic capability alias-analysis (PR #142955)
Marco Elver via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 4 01:48:12 PDT 2025
melver wrote:
Just FYI - I rebased the kernel patches, and attempted to apply -Wthread-safety to kernel/sched/, which previously was impossible.
With this PR, it *does* work with modest changes (most are annotations, only few some small code changes): https://git.kernel.org/pub/scm/linux/kernel/git/melver/linux.git/log/?h=cap-analysis/dev
I also discovered that with this form of alias analysis, we can take care of a function acquiring a capability inside a returned object with a hack like this:
```
+#define __acquire_ret(call, ret_expr) \
+ ({ \
+ __auto_type __ret = call; \
+ __acquire(ret_expr); \
+ __ret; \
+ })
+#define __acquires_ret __no_capability_analysis
...
+ * struct foo { spinlock_t lock; ... };
+ * ...
+ * #define myfunc(...) __acquire_ret(_myfunc(__VA_ARGS__), &__ret->lock)
+ * struct foo *_myfunc(int bar) __acquires_ret;
+ * ...
```
... which was necessary for taking care of kernel/sched.
https://github.com/llvm/llvm-project/pull/142955
More information about the cfe-commits
mailing list