Re: [PATCH tip/locking/core] compiler-context-analysis: Add support for multi-argument guarded_by

From: Peter Zijlstra

Date: Wed Mar 25 2026 - 11:54:01 EST


On Mon, Mar 23, 2026 at 04:39:41PM +0100, Marco Elver wrote:
> On Mon, 23 Mar 2026 at 16:33, Marco Elver <elver@xxxxxxxxxx> wrote:
> >
> > Clang 23 introduces support for multiple arguments in the `guarded_by`
> > and `pt_guarded_by` attributes [1]. This allows defining variables
> > protected by multiple context locks, where read access requires holding
> > at least one lock (shared or exclusive), and write access requires
> > holding all of them exclusively.
> >
> > To use the feature while maintaining compatibility with Clang 22, add
> > the `__guarded_by_any()` and `__pt_guarded_by_any()` macros. On Clang 23
> > and newer, these expand to the underlying attributes; with older Clang
> > versions, they fall back to a no-op (false negatives possible).
> >
> > Link: https://github.com/llvm/llvm-project/pull/186838 [1]
> > Requested-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> > Signed-off-by: Marco Elver <elver@xxxxxxxxxx>
>
> If we want to retain compatibility with Clang 22, we need
> __guarded_by_any, which ultimately maps to 'guarded_by' as well if we
> have Clang 23+.
>
> The alternative would be to wait a few weeks and then require Context
> Analysis to have a Clang 23 compiler. That'd avoid adding the new
> __guarded_by_any variant and we can just use __guarded_by as-is.
>
> We likely want to do that when Clang 23.1 is released anyway, because
> there were some other fixes (arrays of lock fix:
> https://github.com/llvm/llvm-project/pull/148551).
>
> Preferences?

I think we'll be okay just upping the requirement now. But I'll sit on
this a little until Debian's clang-23 build is fresh enough to includes
the awesome :-)