-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Clang Thread Safety Annotations #212
base: main
Are you sure you want to change the base?
Add Clang Thread Safety Annotations #212
Conversation
decisions/lock checing.md
Outdated
## Consequences | ||
|
||
Header file defining the annotations needs to be included. | ||
There are multiple possibilities, either the Clang one(mutex.h), or the Zircon one (thread_annotations.h). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is licensed under Apache, https://github.com/google/google-input-tools/blob/master/client/base/thread_annotations.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of the idea, but would like others to weigh in since it will require all contributors to be aware of these constructs while working on lock-related code.
I'm going to request reviews from some of the proton devs as well since we've involved them in the past regarding how best to interact with the proactor threading model.
a78e8f0
to
bcc5425
Compare
Issues I discovered so far suppressing the warning for a single lineHere is one way. The main problem is that GCC will not accept #ifdef __clang__
#define TA_SUPPRESS _Pragma("clang diagnostic ignored \"-Wthread-safety-analysis\"")
#else
#define TA_SUPPRESS
#endif usage is // initialize the Q2 flag. Note that we do not need to hold the content
// lock when we make this call since no other threads are able to access
// the new message until this function returns.
#pragma GCC diagnostic push
TA_SUPPRESS;
if (_Q2_holdoff_should_block_LH(content))
content->q2_input_holdoff = true;
#pragma GCC diagnostic pop (Suppressing for entire function is easy, just annotate with annotating a function which does not have its lock in the scope is impossibleIn the following, there are two functions which must be protected by
In case of Lines 2724 to 2758 in cfb31ce
limitationsthere are limitations described here and at the clang doc site; one example is that calls through function pointers are not checked alternatives
|
Found the coverity usage, it is in that page, I knew I saw it there before, I just did not realize the second time #ifdef __COVERITY__
extern void __coverity_recursive_lock_acquire__(void*);
extern void __coverity_recursive_lock_release__(void*);
extern void __coverity_assert_locked__(void*);
#endif
// ...
sal_Bool SAL_CALL osl_releaseMutex(oslMutex pMutex)
{
#ifdef __COVERITY__
__coverity_assert_locked__(pMutex);
#endif Example from https://dev-builds.libreoffice.org/cppcheck_reports/master/3633.html |
bcc5425
to
e37a107
Compare
e517873
to
cfb09ee
Compare
cfb09ee
to
c06143d
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #212 +/- ##
=====================================
Coverage 77.7% 77.7%
=====================================
Files 247 247
Lines 64011 64010 -1
Branches 5896 5896
=====================================
+ Hits 49751 49771 +20
+ Misses 11565 11551 -14
+ Partials 2695 2688 -7
Flags with carried forward coverage won't be shown. Click here to find out more.
|
1ee0a07
to
6deb583
Compare
5137543
to
2393cbd
Compare
2393cbd
to
a57a466
Compare
Follows up on
It can supplement
Proposal, aiming to partially provide the features of apache/qpid-dispatch#805, at compile time.
Uses https://clang.llvm.org/docs/ThreadSafetyAnalysis.html (with all the limitations that stem from it, namely, works only in clang or IDE based on clangd, and the GUARDED_BY annotation cannot be used in C structs, llvm/llvm-project#20777)
This is really a draft, but I'd nevertheless appreciate somebody looking at it and giving a preliminary review
Calling a
_LH
function without holding the lockUnlocking something that is not locked
Returning without unlocking
TODO
This could be applied to annotate
_CT
functions. Docs does not say exactly how to do this. I have a guess...