[clang] [clang] WIP: Warn on mismatched RequiresCapability attributes (PR #67520)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 30 05:51:25 PDT 2024


Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/67520 at github.com>


tbaederr wrote:

Updated the branch.

This now warns:
```c++

#define LOCKABLE            __attribute__ ((lockable))
#define EXCLUSIVE_LOCKS_REQUIRED(...)  __attribute__ ((exclusive_locks_required(__VA_ARGS__)))

struct LOCKABLE Mutex {};
struct Mutex mu1;
struct Mutex mu2;

int Foo_fun1(int i)
  // EXCLUSIVE_LOCKS_REQUIRED(mu2)
  ;

void callsFoo() {
  int a = 10;
  Foo_fun1(a);
}

int Foo_fun1(int i)
  EXCLUSIVE_LOCKS_REQUIRED(mu1)
{
  return i;
}
```
```console
./array.cpp:33:5: warning: attribute mismatch between function declarations of 'Foo_fun1' [-Wthread-safety-attributes]
   33 | int Foo_fun1(int i)
      |     ^
1 warning generated.
```
I started collecting the attribute arguments in a `std::set`, but didn't really end up using them in the end, at least not yet.



https://github.com/llvm/llvm-project/pull/67520


More information about the cfe-commits mailing list