Skip to content
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

False clang warning from -Wthread-safety-analysis #393

Open
gperciva opened this issue Mar 28, 2021 · 0 comments
Open

False clang warning from -Wthread-safety-analysis #393

gperciva opened this issue Mar 28, 2021 · 0 comments
Labels
Not a problem False warnings from compilers or analysis tools

Comments

@gperciva
Copy link
Member

gperciva commented Mar 28, 2021

Notes mainly to myself.

Clang's thread safety analysis warns that it cannot handle "conditionally held locks" [1]. They give the example of:

bool b = needsToLock();
if (b) mu.Lock();
...  // Warning!  Mutex 'mu' is not held on every path through here.
if (b) mu.Unlock();

This is rather unfortunate, because phread_mutex_lock() is documented as being able to fail and set errno [2]. Well-written code will therefore not assume that the lock is successful, and will instead check the returned value and jump to error handling if necessary. In other words, well-written code will include "conditionally held locks".

[1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#conditional-locks
[2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_trylock.html

(BTW, we already have -Wno-pthread-safety-analys in spiped, for precisely this reason; the false warning arises from https://github.com/Tarsnap/spiped/blob/master/lib/dnsthread/dnsthread.c#L176)

@gperciva gperciva added the Not a problem False warnings from compilers or analysis tools label Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not a problem False warnings from compilers or analysis tools
Development

No branches or pull requests

1 participant