[libcxx-commits] [PATCH] D113048: [libcxx] Tidy up test_exception_storage.pass.cpp, and fix the NO_THREADS version

Daniel McIntosh via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 2 13:44:44 PDT 2021


DanielMcIntosh-IBM created this revision.
DanielMcIntosh-IBM added reviewers: mclow.lists, jroelofs, kledzik, ldionne.
DanielMcIntosh-IBM requested review of this revision.
Herald added a project: libc++abi.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++abi.

`thread_code` returns param, which for NO_THREADS is going to be
`&thread_globals`. Thus, the return value will never be null. The test
was probably meant to check if `*thread_code(&thread_globals) == 0`.
However, to avoid the extra cast, and to bring the NO_THREADS version
more in line with the regular version of the test, this changes it to
check if thread_globals == 0 directly.

In addition, we switch to using early returns, and reduce the size of
the includes a bit by using <cstddef> instead of <cstdlib>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113048

Files:
  libcxxabi/test/test_exception_storage.pass.cpp


Index: libcxxabi/test/test_exception_storage.pass.cpp
===================================================================
--- libcxxabi/test/test_exception_storage.pass.cpp
+++ libcxxabi/test/test_exception_storage.pass.cpp
@@ -8,7 +8,7 @@
 
 #include <algorithm>
 #include <cstdio>
-#include <cstdlib>
+#include <cstddef>
 #include <__threading_support>
 #include <unistd.h>
 
@@ -41,9 +41,7 @@
 std::__libcpp_thread_t   threads        [ NUMTHREADS ];
 #endif
 
-int main () {
-    int retVal = 0;
-
+int main() {
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 //  Make the threads, let them run, and wait for them to finish
     for ( int i = 0; i < NUMTHREADS; ++i )
@@ -51,6 +49,7 @@
     for ( int i = 0; i < NUMTHREADS; ++i )
         std::__libcpp_thread_join ( &threads [ i ] );
 
+    int retVal = 0;
     for ( int i = 0; i < NUMTHREADS; ++i ) {
         if ( 0 == thread_globals [ i ] ) {
             std::printf("Thread #%d had a zero global\n", i);
@@ -65,12 +64,11 @@
             retVal = 2;
         }
     }
+    return retVal;
 #else // _LIBCXXABI_HAS_NO_THREADS
     size_t thread_globals;
+    thread_code(&thread_globals);
     // Check that __cxa_get_globals() is not NULL.
-    if (thread_code(&thread_globals) == 0) {
-        retVal = 1;
-    }
+    return (thread_globals == 0) ? 1 : 0;
 #endif // !_LIBCXXABI_HAS_NO_THREADS
-    return retVal;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113048.384214.patch
Type: text/x-patch
Size: 1364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211102/7e300699/attachment.bin>


More information about the libcxx-commits mailing list