Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor placement-new to avoid gcc-9.4 __builtin_memset bug #335

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ArrayOfArraysView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,9 @@ class ArrayOfArraysView
* @param defaultArrayCapacity the default capacity for each new array.
*/
void resize( INDEX_TYPE const newSize, INDEX_TYPE const defaultArrayCapacity=0 )
{ return resizeImpl( newSize, defaultArrayCapacity ); }
{
return resizeImpl( newSize, defaultArrayCapacity );
}

/**
* @brief Reserve space for the given number of arrays.
Expand Down
2 changes: 1 addition & 1 deletion src/Macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"***** Block: [%u, %u, %u]\n" \
"***** Thread: [%u, %u, %u]\n" \
"***** Controlling expression (should be false): " STRINGIZE( EXP ) "\n" \
"***** MSG: " STRINGIZE( MSG ) "\n\n"; \
"***** MSG: " STRINGIZE( MSG ) "\n\n"; \
printf( formatString, blockIdx.x, blockIdx.y, blockIdx.z, threadIdx.x, threadIdx.y, threadIdx.z ); \
asm ( "trap;" ); \
} \
Expand Down
27 changes: 9 additions & 18 deletions src/arrayManipulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,29 +292,20 @@ void resize( T * const LVARRAY_RESTRICT ptr,
// Delete things between newSize and size.
destroy( ptr + newSize, size - newSize );

// Initialize things between size and newSize.
if( sizeof ... ( ARGS ) == 0 && std::is_trivially_default_constructible< T >::value )
if( newSize - size > 0 )
{
if( newSize - size > 0 )
// Initialize things between size and newSize.
if constexpr ( sizeof ... ( ARGS ) == 0 && std::is_trivially_default_constructible< T >::value )
{
std::size_t const sizeDiff = integerConversion< std::size_t >( newSize - size );
#if !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#pragma GCC diagnostic ignored "-Wstringop-overflow="
#endif
memset( reinterpret_cast< void * >( ptr + size ), 0, ( sizeDiff ) * sizeof( T ) );
#if !defined(__clang__)
#pragma GCC diagnostic pop
#endif
std::memset( reinterpret_cast< void * >( ptr + size ), 0, ( sizeDiff ) * sizeof( T ) );
}
}
else
{
// Use std::size_t so that when GCC optimizes this it doesn't produce sign warnings.
for( std::size_t i = size; i < std::size_t( newSize ); ++i )
else
{
new ( ptr + i ) T( std::forward< ARGS >( args )... );
Copy link
Contributor Author

@wrtobin wrtobin Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ptr + i seems to be what was triggering it, switching to instead using a ptr of type T as the loop variable seems to avoid the bug

Copy link
Contributor Author

@wrtobin wrtobin Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if in some circumstance with the constructor arguments known as compile-time constants, it was doing enough optimizations to do some calculations down here constexpr (effectively), but something used in the calculation was uninitialized. After looking around, nothing used in the calculation isn't initialized in the boolean constructor chain, soooo idunno.

for( T * iptr = ptr + size; iptr < ptr + newSize; ++iptr )
{
new ( iptr ) T( std::forward< ARGS >( args )... );
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/umpireInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void memset( void * const dstPointer, int const val, std::size_t const size )
return rm.memset( dstPointer, val, size );
}
#endif

std::memset( dstPointer, val, size );
}

Expand Down