Skip to content

Commit

Permalink
sanitizer_common: disable thread safety annotations for googletest
Browse files Browse the repository at this point in the history
Recently in 0da172b 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.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D107491
  • Loading branch information
DimitryAndric committed Aug 5, 2021
1 parent f8b6e1f commit b260f3f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler-rt/CMakeLists.txt
Expand Up @@ -546,6 +546,14 @@ set(COMPILER_RT_GTEST_CFLAGS
-I${COMPILER_RT_GTEST_PATH}/include
-I${COMPILER_RT_GTEST_PATH}
)
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
# FreeBSD has its pthread functions marked with thread safety annotations, but
# googletest is not compatible with such annotations. Disable the thread
# safety warnings-as-errors until googletest has been fixed.
list(APPEND NO_THREAD_SAFETY_FLAGS ${THREAD_SAFETY_FLAGS})
list(TRANSFORM NO_THREAD_SAFETY_FLAGS REPLACE "error=" "no-")
list(APPEND COMPILER_RT_GTEST_CFLAGS ${NO_THREAD_SAFETY_FLAGS})
endif()

# Mocking support.
set(COMPILER_RT_GMOCK_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock)
Expand Down

0 comments on commit b260f3f

Please sign in to comment.