Based on the comment in https://reviews.llvm.org/D54290#4418958, these
attributes need to be on the top-level functions in order to work
properly. Also, add tests.
Fixes http://llvm.org/PR57035.
Paths
| Differential D154354
[libc++] Fix thread annotations on shared_mutex and shared_timed_mutex ClosedPublic Authored by ldionne on Jul 3 2023, 8:05 AM.
Details
Summary Based on the comment in https://reviews.llvm.org/D54290#4418958, these Fixes http://llvm.org/PR57035.
Diff Detail
Unit TestsFailed Event TimelineComment Actions Thanks for picking this up!
There are several existing tests, see libcxx/test/libcxx/thread/thread.mutex/thread_safety_*. What should work: std::shared_mutex m; int data __attribute__((guarded_by(m))); void read(int); ++foo; // warning, but probably no need to test this: libc++ has // nothing to do with it, it's due to the attribute above. m.lock(); ++foo; // ok. m.unlock(); if (m.try_lock()) ++foo; // ok. m.unlock(); m.lock_shared(); read(foo); // ok. ++foo; // warning. m.unlock_shared();
Comment Actions
Then I definitely want some tests for this.
This revision now requires changes to proceed.Jul 3 2023, 3:44 PM Comment Actions
That would generate a warning, better: if (m.try_lock()) { ++foo; // ok. m.unlock(); } And there is no point in testing for that warning, because we're doing this in Clang. We should essentially only test that we got the right attribute. Comment Actions Annotations and tests look good to me. Guess the tests require C++14/17, respectively, and need to guarded accordingly. This revision is now accepted and ready to land.Jul 5 2023, 8:21 AM Closed by commit rG5b666cf11e7a: [libc++] Fix thread annotations on shared_mutex and shared_timed_mutex (authored by ldionne). · Explain WhyJul 6 2023, 5:37 AM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 537132 libcxx/.clang-format
libcxx/include/shared_mutex
libcxx/test/libcxx/thread/thread.shared_mutex/thread_safety.verify.cpp
libcxx/test/libcxx/thread/thread.shared_timed_mutex/thread_safety.verify.cpp
|
You could also replace the underscore by a space, or go with just "mutex". This string is used as a "capability kind" in diagnostics.