Skip to content

Commit aa9f58c

Browse files
committed
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.
1 parent 2df37d5 commit aa9f58c

File tree

1 file changed

+3
-4
lines changed
  • llvm/utils/unittest/googletest/src

1 file changed

+3
-4
lines changed

llvm/utils/unittest/googletest/src/gtest.cc

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

0 commit comments

Comments
 (0)