1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

Speculatively adjust gtest's UnitTest::AddTestPartResult() to not rely on volatile store to null trapping

This fallback path is used at least on PPC.
If this doesn't work on some compilers that take this path,
then this will have to be changed to either abort,
or partitioned to do different things based on the compiler.

Please refer to https://reviews.llvm.org/D105338.
This commit is contained in:
Roman Lebedev 2021-07-09 13:30:17 +03:00
parent d999ecbb7a
commit a95e1221a9

View File

@ -4813,10 +4813,9 @@ void UnitTest::AddTestPartResult(
// with clang/gcc we can achieve the same effect on x86 by invoking int3
asm("int3");
#else
// Dereference nullptr through a volatile pointer to prevent the compiler
// from removing. We use this rather than abort() or __builtin_trap() for
// portability: some debuggers don't correctly trap abort().
*static_cast<volatile int*>(nullptr) = 1;
// While some debuggers don't correctly trap abort(), we can't perform
// volatile store to null since it will be removed by clang and not trap.
__builtin_trap();
#endif // GTEST_OS_WINDOWS
} else if (GTEST_FLAG(throw_on_failure)) {
#if GTEST_HAS_EXCEPTIONS