Skip to content

Commit b21917d

Browse files
committed
Work around clmul msan bug in clang < 11
1 parent 1261e9e commit b21917d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/fields/clmul_common_impl.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,20 @@
1515

1616
namespace {
1717

18-
template<typename I, int BITS, I MOD> I MulWithClMulReduce(I a, I b)
18+
// The memory sanitizer in clang < 11 cannot reason through _mm_clmulepi64_si128 calls.
19+
// Disable memory sanitization in the functions using them for those compilers.
20+
#if defined(__clang__) && (__clang_major__ < 11)
21+
# if defined(__has_feature)
22+
# if __has_feature(memory_sanitizer)
23+
# define NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))
24+
# endif
25+
# endif
26+
#endif
27+
#ifndef NO_SANITIZE_MEMORY
28+
# define NO_SANITIZE_MEMORY
29+
#endif
30+
31+
template<typename I, int BITS, I MOD> NO_SANITIZE_MEMORY I MulWithClMulReduce(I a, I b)
1932
{
2033
static constexpr I MASK = Mask<BITS, I>();
2134

@@ -52,7 +65,7 @@ template<typename I, int BITS, I MOD> I MulWithClMulReduce(I a, I b)
5265
}
5366
}
5467

55-
template<typename I, int BITS, int POS> I MulTrinomial(I a, I b)
68+
template<typename I, int BITS, int POS> NO_SANITIZE_MEMORY I MulTrinomial(I a, I b)
5669
{
5770
static constexpr I MASK = Mask<BITS, I>();
5871

0 commit comments

Comments
 (0)