Skip to content

Commit 049c7b3

Browse files
committed
Merge remote-tracking branch 'upstream/main' into fix-donotoptimize-const-members
2 parents d4e183a + 82a8950 commit 049c7b3

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎src/mutex.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88

99
// Enable thread safety attributes only with clang.
1010
// The attributes can be safely erased when compiling with other compilers.
11+
//
12+
// Whether the annotations below are needed is a property of the compiler, not
13+
// of the build: whoever compiles this may pass -Wthread-safety without saying
14+
// so (Bazel's default toolchain adds it whenever the compiler accepts it), and
15+
// the wrappers then get analyzed with their own annotations erased -- so
16+
// Mutex::lock() is seen acquiring mut_ and never releasing it, which is an
17+
// error wherever the standard library annotates std::mutex itself (libc++).
18+
// Setting the macro from a build file cannot fix that in general, because the
19+
// same build file also has to serve compilers that reject the attributes.
20+
// Deciding it here keeps the two in step. A definition from the outside still
21+
// wins.
22+
#if !defined(HAVE_THREAD_SAFETY_ATTRIBUTES) && defined(__clang__)
23+
#define HAVE_THREAD_SAFETY_ATTRIBUTES
24+
#endif
25+
1126
#if defined(HAVE_THREAD_SAFETY_ATTRIBUTES)
1227
#define THREAD_ANNOTATION_ATTRIBUTE_(x) __attribute__((x))
1328
#else

0 commit comments

Comments
 (0)