-
Notifications
You must be signed in to change notification settings - Fork 41
Fix clang thread-safety-pointer warnings #54
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
Fix clang thread-safety-pointer warnings #54
Conversation
Clang's -Wthread-safety-pointer warnings will become part of -Wthread-safety in some future release. Add missing annotations for functions that pass the address of guarded members. No functional change. Fixes the following warnings: util/cache.cc:220:17: warning: passing pointer to variable 'in_use_' requires holding mutex 'mutex_' [-Wthread-safety-pointer] 220 | LRU_Append(&in_use_, e); | ^ util/cache.cc:235:17: warning: passing pointer to variable 'lru_' requires holding mutex 'mutex_' [-Wthread-safety-pointer] 235 | LRU_Append(&lru_, e);
Tested and review ACK 7daf4ed
Lines 185 to 193 in 113db49
and are accessed by Lines 217 to 237 in 113db49
The annotations added here are correct. Attempting to build with $ clang --version
clang version 21.0.0git (git@github.com:llvm/llvm-project.git 1f1c725b68b9d72b5cd3fc95c57ce4244bc85c8e)
$ CC=clang CXX=clang++ cmake -B build -DCMAKE_CXX_FLAGS=-Wthread-safety-pointer
/leveldb-subtree/util/cache.cc:220:17: error: passing pointer to variable 'in_use_' requires holding mutex 'mutex_' [-Werror,-Wthread-safety-pointer]
220 | LRU_Append(&in_use_, e);
| ^
/leveldb-subtree/util/cache.cc:235:17: error: passing pointer to variable 'lru_' requires holding mutex 'mutex_' [-Werror,-Wthread-safety-pointer]
235 | LRU_Append(&lru_, e);
| And this branch fixes those thread safety warnings. |
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.
ACK 7daf4ed
Clang's -Wthread-safety-pointer warnings will become part of -Wthread-safety in some future release.
For anyone else wondering, Wthread-safety-pointer
is first appearing in Clang 21.x.
aba469ad6a Merge bitcoin-core/leveldb-subtree#54: Fix clang thread-safety-pointer warnings 7daf4ed575 Fix clang thread-safety-pointer warnings git-subtree-dir: src/leveldb git-subtree-split: aba469ad6a808da8381edf83a99e5ece18958b31
83bfe14 build: add -Wthread-safety-pointer (fanquake) 240a4fb Squashed 'src/leveldb/' changes from 113db4962b..aba469ad6a (fanquake) Pull request description: This will become available in Clang 21: > ThreadSafetyAnalysis now supports -Wthread-safety-pointer, which > enables warning on passing or returning pointers to guarded variables > as function arguments or return value respectively. Note that > ThreadSafetyAnalysis still does not perform alias analysis. The > feature will be default-enabled with -Wthread-safety in a future release. See https://github.com/llvm/llvm-project/blob/main/clang/docs/ReleaseNotes.rst. Also updates the leveldb subtree to pull: bitcoin-core/leveldb-subtree#54. ACKs for top commit: davidgumberg: Tested ACK 83bfe14 maflcko: lgtm ACK 83bfe14 theuni: utACK 83bfe14 Tree-SHA512: 9bc80bd04a9cebed8aca20bc23a17e52a6a89a1fb042993322f43dbf7bd93de509c091ebb69255063833b098ab11a64285eccf61e17b9f94f974c734a20ad8da
This prevents a warning in an upcoming version of clang which will turn this on for us.
Submitted upstream: google#1270
Clang's
-Wthread-safety-pointer
warnings will become part of-Wthread-safety
in some future release. Add missing annotations for functions that pass the address of guarded members. No functional change. Fixes the following warnings: