From 0977b2b7fe00eca719e6bc4d1f9f081fd8f0200d Mon Sep 17 00:00:00 2001 From: dthoennes <dominik.thoennes@fau.de> Date: Wed, 8 Nov 2017 12:11:01 +0100 Subject: [PATCH] Added Sanitizer.h to suppress undefined behaviours --- src/core/Sanitizer.h | 37 +++++++++++++++++++++++++++++++++++++ src/core/mpi/RecvBuffer.h | 16 +++++++++------- src/core/mpi/SendBuffer.h | 16 +++++++++------- 3 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 src/core/Sanitizer.h diff --git a/src/core/Sanitizer.h b/src/core/Sanitizer.h new file mode 100644 index 000000000..8ccb5f7b8 --- /dev/null +++ b/src/core/Sanitizer.h @@ -0,0 +1,37 @@ +//====================================================================================================================== +// +// This file is part of waLBerla. waLBerla is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// waLBerla is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file Sanitizer.h +//! \ingroup core +//! \author Dominik Thoennes <dominik.thoennes@fau.de> +// +//====================================================================================================================== + +#pragma once + +#if (( defined WALBERLA_CXX_COMPILER_IS_CLANG ) && ( __clang_major__ >=4 ) ) \ + || (( defined WALBERLA_CXX_COMPILER_IS_GNU ) && ( __GNUC__ >= 5 ) ) +# define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) +#else +# define ATTRIBUTE_NO_SANITIZE_ADDRESS +#endif + +#if ( ( defined WALBERLA_CXX_COMPILER_IS_GNU ) && ( __GNUC__ >= 5 ) ) +# define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize_undefined)) +#elif (( defined WALBERLA_CXX_COMPILER_IS_CLANG ) && ( __clang_major__ >= 4 ) ) +# define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined"))) +#else +# define ATTRIBUTE_NO_SANITIZE_UNDEFINED +#endif \ No newline at end of file diff --git a/src/core/mpi/RecvBuffer.h b/src/core/mpi/RecvBuffer.h index e1af9c264..cf8e32743 100644 --- a/src/core/mpi/RecvBuffer.h +++ b/src/core/mpi/RecvBuffer.h @@ -1,15 +1,15 @@ //====================================================================================================================== // -// This file is part of waLBerla. waLBerla is free software: you can +// This file is part of waLBerla. waLBerla is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// waLBerla is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -30,6 +30,7 @@ #include "SendBuffer.h" #include "core/debug/Debug.h" +#include "core/Sanitizer.h" #include <boost/mpl/logical.hpp> #include <boost/type_traits/is_enum.hpp> @@ -388,6 +389,7 @@ 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 ) diff --git a/src/core/mpi/SendBuffer.h b/src/core/mpi/SendBuffer.h index 57d097a21..448c94af1 100644 --- a/src/core/mpi/SendBuffer.h +++ b/src/core/mpi/SendBuffer.h @@ -1,15 +1,15 @@ //====================================================================================================================== // -// This file is part of waLBerla. waLBerla is free software: you can +// This file is part of waLBerla. waLBerla is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// waLBerla is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,6 +32,7 @@ #include "growPolicies/OptimalGrowth.h" #include "core/debug/Debug.h" +#include "core/Sanitizer.h" #include <boost/mpl/logical.hpp> #include <boost/type_traits/is_enum.hpp> @@ -442,6 +443,7 @@ 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 ) -- GitLab