[all-commits] [llvm/llvm-project] 4b1cd2: Thread Safety Analysis: Don't treat function point...

Jameson Nash via All-commits all-commits at lists.llvm.org
Tue Jul 28 08:53:34 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4b1cd29ffb39ea94590869657e9170230155a979
      https://github.com/llvm/llvm-project/commit/4b1cd29ffb39ea94590869657e9170230155a979
  Author: Jameson Nash <vtjnash at gmail.com>
  Date:   2026-07-28 (Tue, 28 Jul 2026)

  Changed paths:
    M clang/docs/ThreadSafetyAnalysis.md
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/Analysis/ThreadSafety.cpp
    M clang/lib/Sema/SemaDeclAttr.cpp
    M clang/test/Sema/warn-thread-safety-analysis.c
    M clang/test/SemaCXX/warn-thread-safety-analysis.cpp
    M clang/test/SemaCXX/warn-thread-safety-parsing.cpp

  Log Message:
  -----------
  Thread Safety Analysis: Don't treat function pointer parameters as scoped capabilities (#211885)

Capability attributes on a parameter mean one of two unrelated things:
on a scoped-lockable parameter they describe the locks the passed scope
object holds, while on a function pointer parameter they describe the
requirements of the function called through the pointer. Since #191187
allowed the latter, both of the scoped-lockable code paths have been
misreading function pointer parameters as scope objects.

At a call site, the argument bound to the parameter was translated into
a capability and required to be held, so passing a callback that
requires a capability was reported as a missing lock named after the
callback:

```
void apply(fn_t fn EXCLUSIVE_LOCKS_REQUIRED(mu));
  static int my_fn() EXCLUSIVE_LOCKS_REQUIRED(mu);
  ...
  apply(my_fn); // warning: requires holding mutex 'fn'
```

In the callee, the same confusion seeded the parameter's capabilities
into the function's entry lockset, so they were considered held
throughout the body and the calls made through the pointer went
unchecked -- the opposite of what the annotation asks for.

Skip function pointer parameters in both places; their attributes are
already checked at the indirect call sites (by #191187), the same way as
for annotated function pointer variables and fields.

Assisted-by: Claude Opus 5



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list