This is an archive of the discontinued LLVM Phabricator instance.

sanitizer_common: disable thread safety annotations for googletest
ClosedPublic

Authored by dim on Aug 4 2021, 11:36 AM.

Details

Summary

Recently in 0da172b1766e 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.

Diff Detail

Event Timeline

dim created this revision.Aug 4 2021, 11:36 AM
dim requested review of this revision.Aug 4 2021, 11:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2021, 11:36 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
dvyukov added inline comments.Aug 5 2021, 3:17 AM
compiler-rt/CMakeLists.txt
548

Please do this only for FreeBSD with a comment explaining why they are turned off.

dim updated this revision to Diff 364553.Aug 5 2021, 11:02 AM

Only disable thread safety warnings on FreeBSD, and add an explanatory comment.

dim updated this revision to Diff 364554.Aug 5 2021, 11:04 AM

Fix typo.

dvyukov accepted this revision.Aug 5 2021, 11:06 AM

Thanks!

This revision is now accepted and ready to land.Aug 5 2021, 11:06 AM
This revision was landed with ongoing or failed builds.Aug 5 2021, 11:07 AM
This revision was automatically updated to reflect the committed changes.