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.
Differential D154354
[libc++] Fix thread annotations on shared_mutex and shared_timed_mutex ldionne on Jul 3 2023, 8:05 AM. Authored by
Details
Based on the comment in https://reviews.llvm.org/D54290#4418958, these Fixes http://llvm.org/PR57035.
Diff Detail
Unit Tests 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.
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. |
You could also replace the underscore by a space, or go with just "mutex". This string is used as a "capability kind" in diagnostics.