[PATCH] D107491: sanitizer_common: disable thread safety annotations for googletest

Dimitry Andric via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 4 11:36:50 PDT 2021


dim created this revision.
dim added reviewers: dvyukov, emaste, melver, vitalybuka.
Herald added subscribers: krytarowski, arichardson, mgorny.
dim requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

Recently in 0da172b1766e <https://reviews.llvm.org/rG0da172b1766e1559ef677aa836dce4f1995dfef3> thread safety warnings-as-errors were enabled.
However, googletest is currently not compatible with thread safety
annotations. On FreeBSD, which has the pthread functions marked with
such annotations, this results in errors when building the compiler-rt
tests:

  In file included from compiler-rt/lib/interception/tests/interception_test_main.cpp:15:
  In file included from llvm/utils/unittest/googletest/include/gtest/gtest.h:62:
  In file included from llvm/utils/unittest/googletest/include/gtest/internal/gtest-internal.h:40:
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1636:3: error: mutex 'mutex_' is still held at the end of function [-Werror,-Wthread-safety-analysis]
    }
    ^
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1633:32: note: mutex acquired here
      GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
                                 ^
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1645:32: error: releasing mutex 'mutex_' that was not held [-Werror,-Wthread-safety-analysis]
      GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
                                 ^
  2 errors generated.

At some point googletest will hopefully be made compatible with thread
safety annotations, but for now add corresponding `-Wno-thread-*` flags
to `COMPILER_RT_GTEST_CFLAGS` to silence these warnings-as-errors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107491

Files:
  compiler-rt/CMakeLists.txt


Index: compiler-rt/CMakeLists.txt
===================================================================
--- compiler-rt/CMakeLists.txt
+++ compiler-rt/CMakeLists.txt
@@ -368,6 +368,8 @@
   list(APPEND SANITIZER_COMMON_CFLAGS ${THREAD_SAFETY_FLAGS})
   string(REPLACE ";" " " thread_safety_flags_space_sep "${THREAD_SAFETY_FLAGS}")
   string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " ${thread_safety_flags_space_sep}")
+  list(APPEND NO_THREAD_SAFETY_FLAGS ${THREAD_SAFETY_FLAGS})
+  list(TRANSFORM NO_THREAD_SAFETY_FLAGS REPLACE "error=" "no-")
 endif()
 
 # If we're using MSVC,
@@ -536,6 +538,7 @@
   -DGTEST_HAS_RTTI=0
   -I${COMPILER_RT_GTEST_PATH}/include
   -I${COMPILER_RT_GTEST_PATH}
+  ${NO_THREAD_SAFETY_FLAGS}
 )
 
 # Mocking support.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107491.364203.patch
Type: text/x-patch
Size: 744 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210804/ea99afc6/attachment.bin>


More information about the llvm-commits mailing list