[llvm] aa9f58c - Speculatively adjust gtest's UnitTest::AddTestPartResult() to not rely on volatile store to null trapping

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 9 03:32:42 PDT 2021


Author: Roman Lebedev
Date: 2021-07-09T13:32:18+03:00
New Revision: aa9f58cc2c48ca6cfc853a2467cd775dc7622746

URL: https://github.com/llvm/llvm-project/commit/aa9f58cc2c48ca6cfc853a2467cd775dc7622746
DIFF: https://github.com/llvm/llvm-project/commit/aa9f58cc2c48ca6cfc853a2467cd775dc7622746.diff

LOG: 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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/utils/unittest/googletest/src/gtest.cc b/llvm/utils/unittest/googletest/src/gtest.cc
index a5b4e5ac78ca..5c584048c789 100644
--- a/llvm/utils/unittest/googletest/src/gtest.cc
+++ b/llvm/utils/unittest/googletest/src/gtest.cc
@@ -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


        


More information about the llvm-commits mailing list