Disable spurious thread-safety analysis warnings The WaitListEvent::WaitAny method conditionally locks event mutexes. Clangs static analysis doesn't understand the pattern, and generates spurious warnings, which trigger errors. Bug: 435680470 Change-Id: Ia8c00656829cc2b650073ea1ac671583e9342179 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/257415 Commit-Queue: David Neto <dneto@google.com> Reviewed-by: Loko Kung <lokokung@google.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn/common/Compiler.h b/src/dawn/common/Compiler.h index d08ba4d..edb2340 100644 --- a/src/dawn/common/Compiler.h +++ b/src/dawn/common/Compiler.h
@@ -187,4 +187,21 @@ #define DAWN_UNLOCK_FUNCTION #endif +// DAWN_NO_THREAD_SAFETY_ANALYSIS +// +// Used when a function is too complicated for the thread safety static +// analysis, and the compiler generates spurious warnings. Use this sparingly. +// For example, Clang does not know how to analyze conditionally-held locks, and +// may generate spurious warnings. +// +// Place this macro just before the opening brace of the function *definition*. +// Do not put it at the declaration. +// +// https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#no-thread-safety-analysis +#if DAWN_HAS_ATTRIBUTE(no_thread_safety_analysis) +#define DAWN_NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis)) +#else +#define DAWN_NO_THREAD_SAFETY_ANALYSIS +#endif + #endif // SRC_DAWN_COMMON_COMPILER_H_
diff --git a/src/dawn/native/WaitListEvent.h b/src/dawn/native/WaitListEvent.h index 756d68c..a710b4a 100644 --- a/src/dawn/native/WaitListEvent.h +++ b/src/dawn/native/WaitListEvent.h
@@ -73,7 +73,11 @@ template <typename It> bool WaitListEvent::WaitAny(It eventAndReadyStateBegin, It eventAndReadyStateEnd, - Nanoseconds timeout) { + Nanoseconds timeout) + // This method conditionally locks a set of events, and then unlocks them. + // The thread-safety analysis does not handle conditional locking, so + // we turn off the analysis to avoid spurious warnings. + DAWN_NO_THREAD_SAFETY_ANALYSIS { static_assert(std::is_base_of_v<std::random_access_iterator_tag, typename std::iterator_traits<It>::iterator_category>); static_assert(std::is_same_v<typename std::iterator_traits<It>::value_type,