From 0bd2dcc4de2425dacc3a7e636f359fb4c4ac5629 Mon Sep 17 00:00:00 2001 From: Christian Godenschwager <christian.godenschwager@fau.de> Date: Wed, 10 Jan 2018 18:50:48 +0000 Subject: [PATCH] Fix buffers for GCC 7 with -O3 --- src/core/mpi/RecvBuffer.h | 8 +++----- src/core/mpi/SendBuffer.h | 6 ++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/core/mpi/RecvBuffer.h b/src/core/mpi/RecvBuffer.h index cf8e32743..5015f9bf5 100644 --- a/src/core/mpi/RecvBuffer.h +++ b/src/core/mpi/RecvBuffer.h @@ -38,7 +38,7 @@ #include <boost/utility/enable_if.hpp> #include <algorithm> - +#include <cstring> namespace walberla { namespace mpi { @@ -389,7 +389,6 @@ inline bool GenericRecvBuffer<T>::isEmpty() const */ template< typename T > // Element type template< typename V > // Type of the built-in data value -ATTRIBUTE_NO_SANITIZE_UNDEFINED typename boost::enable_if< boost::mpl::or_< boost::is_arithmetic<V>, boost::is_enum<V> >, GenericRecvBuffer<T> & >::type GenericRecvBuffer<T>::get( V& value ) @@ -408,9 +407,8 @@ GenericRecvBuffer<T>::get( V& value ) WALBERLA_ASSERT_LESS_EQUAL( cur_ + (sizeof(V) / sizeof(T)), end_ ); // Extracting the data value - V* tmp = reinterpret_cast<V*>( cur_ ); - value = *tmp; - cur_ = reinterpret_cast<T*>( ++tmp ); + std::memcpy( &value, cur_, sizeof(V) ); + cur_ += sizeof(V) / sizeof(T); // Invariants check WALBERLA_ASSERT_LESS_EQUAL( cur_, end_); diff --git a/src/core/mpi/SendBuffer.h b/src/core/mpi/SendBuffer.h index 448c94af1..2b1e11c17 100644 --- a/src/core/mpi/SendBuffer.h +++ b/src/core/mpi/SendBuffer.h @@ -42,7 +42,7 @@ #include <algorithm> #include <typeinfo> - +#include <cstring> namespace walberla { namespace mpi { @@ -443,7 +443,6 @@ inline bool GenericSendBuffer<T,G>::isEmpty() const template< typename T // Element type , typename G > // Growth policy template< typename V > // Type of the built-in data value -ATTRIBUTE_NO_SANITIZE_UNDEFINED typename boost::enable_if< boost::mpl::or_< boost::is_arithmetic<V>, boost::is_enum<V> >, GenericSendBuffer<T,G>& >::type GenericSendBuffer<T,G>::put( V value ) @@ -464,8 +463,7 @@ GenericSendBuffer<T,G>::put( V value ) } // Adding the data value - V* const tmp( reinterpret_cast<V*>( cur_ ) ); - *tmp = value; + std::memcpy( cur_, &value, sizeof(V) ); cur_ += count; // Invariants check -- GitLab