[PATCH] D153131: [clang analysis][thread-safety] Handle return-by-reference...

Clement Courbet via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 28 08:10:17 PDT 2023


courbet added a comment.

In D153131#4456019 <https://reviews.llvm.org/D153131#4456019>, @aaronpuchert wrote:

> Tried this on our code base, and the number of new warnings seems acceptable. I'll still need to look through them in more detail, but there is one suspicious warning that boils down to this:
>
>   > cat reference-bug.cpp
>   struct __attribute__((capability("mutex"))) Mutex {} mu;
>   int* p __attribute__((pt_guarded_by(mu)));
>   
>   int& f() {
>     return *p;
>   }
>   > clang-16 -fsyntax-only -Wthread-safety-analysis reference-bug.cpp
>   > clang-16-D153131 -fsyntax-only -Wthread-safety-analysis reference-bug.cpp
>   reference-bug.cpp:5:11: warning: writing the value pointed to by 'p' requires holding mutex 'mu' exclusively [-Wthread-safety-analysis]
>     return *p;
>             ^
>   1 warning generated.
>
> That we're warning here is correct, but the warning message is a bit off (we're not quite writing here), and it's under `-Wthread-safety-analysis` instead of `-Wthread-safety-reference`.

Right. I was relying on the fallback "imprecise" warning for this one. I added a `pt_garded` value just like for `pass_by_value` and added a test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153131/new/

https://reviews.llvm.org/D153131



More information about the cfe-commits mailing list