[clang] [clang][ThreadSafety] Warn when constructor is trylock (PR #95290)
Dan McArdle via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 17 13:59:38 PDT 2024
dmcardle wrote:
Thanks, @AaronBallman!
I tried strictly enforcing a `bool` return type, but I ran into some interesting test failures.
* A handful of functions in the parsing tests return `void` and yet are annotated as trylock functions. I don't believe this is a valid use case. What does `EXCLUSIVE_TRYLOCK_FUNCTION` mean when it's impossible to return a value? I think the solution is to just change `void` to `bool` for trylock functions in tests. https://github.com/llvm/llvm-project/blob/06aa078d68380bc775f0a903204fe330d50f4f1f/clang/test/SemaCXX/warn-thread-safety-parsing.cpp#L725
* This next failure is tricker... I was really surprised to see a trylock method that returns a pointer! Confusingly, the "success" parameter to the attribute is `1`. I think the semantics work out so that returning a non-`nullptr` value indicates successful mutex acquisition.
I'm not quite sure what to do here. Maybe we should be lenient and only enforce that the return type is boolean, integer, or pointer?
https://github.com/llvm/llvm-project/blob/06aa078d68380bc775f0a903204fe330d50f4f1f/clang/test/SemaCXX/warn-thread-safety-analysis.cpp#L3661
https://github.com/llvm/llvm-project/pull/95290
More information about the cfe-commits
mailing list