From 55f27e0304473acfdb09249b6b09d88ac8b6fcea Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Thu, 28 Sep 2023 04:55:29 +0200 Subject: [PATCH] Workaround wrong codegen with ASAN+std::simd This is a workaround for GCC > 11 generating an aligned store to an unaligned address when calling placement new on std::simd, when ASAN is enabled. Fixes: #777 --- include/llama/View.hpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/include/llama/View.hpp b/include/llama/View.hpp index 8f0661acf8..ba036a104f 100644 --- a/include/llama/View.hpp +++ b/include/llama/View.hpp @@ -13,6 +13,9 @@ #include "mapping/One.hpp" #include +#if __has_include() +# include +#endif namespace llama { @@ -87,6 +90,24 @@ namespace llama LeafRecordCoords, mp_bind_front::template fn>::value; + namespace internal + { + template + void valueInit(T* p) + { + new(p) T{}; + } + +#if defined(__GNUG__) && __GNUC__ > 11 && defined(__SANITIZE_ADDRESS__) && defined(__AVX512F__) + // ASAN messes with placement new and GCC generates an aligned store to an unaligned address with AVX512 + template + void valueInit(std::experimental::native_simd* p) + { + std::memset(p, 0, sizeof(T)); + } +#endif + } // namespace internal + template LLAMA_FN_HOST_ACC_INLINE void constructField( View& view, @@ -106,7 +127,7 @@ namespace llama else if constexpr( std::is_lvalue_reference_v && !std::is_const_v>) { - new(&view(ai)) FieldType{}; + internal::valueInit(&view(ai)); } } else @@ -119,7 +140,7 @@ namespace llama else if constexpr( std::is_lvalue_reference_v && !std::is_const_v>) { - new(&view(ai)(rc)) FieldType{}; + internal::valueInit(&view(ai)(rc)); } } }