Skip to content

Commit 795ff77

Browse files
[libcxxabi] Fix NO_THREADS version of test_exception_storage.pass.cpp
`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. Reviewed By: ldionne, #libc_abi Differential Revision: https://reviews.llvm.org/D113048
1 parent ce7ac9e commit 795ff77

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

libcxxabi/test/test_exception_storage.pass.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,15 @@ size_t thread_globals [ NUMTHREADS ] = { 0 };
4444
std::__libcpp_thread_t threads [ NUMTHREADS ];
4545
#endif
4646

47-
int main () {
48-
int retVal = 0;
49-
47+
int main() {
5048
#ifndef _LIBCXXABI_HAS_NO_THREADS
5149
// Make the threads, let them run, and wait for them to finish
5250
for ( int i = 0; i < NUMTHREADS; ++i )
5351
std::__libcpp_thread_create ( threads + i, thread_code, (void *) (thread_globals + i));
5452
for ( int i = 0; i < NUMTHREADS; ++i )
5553
std::__libcpp_thread_join ( &threads [ i ] );
5654

55+
int retVal = 0;
5756
for ( int i = 0; i < NUMTHREADS; ++i ) {
5857
if ( 0 == thread_globals [ i ] ) {
5958
std::printf("Thread #%d had a zero global\n", i);
@@ -68,12 +67,11 @@ int main () {
6867
retVal = 2;
6968
}
7069
}
70+
return retVal;
7171
#else // _LIBCXXABI_HAS_NO_THREADS
7272
size_t thread_globals;
73+
thread_code(&thread_globals);
7374
// Check that __cxa_get_globals() is not NULL.
74-
if (thread_code(&thread_globals) == 0) {
75-
retVal = 1;
76-
}
75+
return (thread_globals == 0) ? 1 : 0;
7776
#endif // !_LIBCXXABI_HAS_NO_THREADS
78-
return retVal;
7977
}

0 commit comments

Comments
 (0)