Prevent UBSAN from generating unsigned overflow diagnostics in the hashing internals

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@294391 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2017-02-08 00:10:10 +00:00
parent fecf057940
commit 25f28d0c9e
3 changed files with 76 additions and 10 deletions

View File

@@ -182,6 +182,18 @@ struct is_same<T, T> { enum {value = 1}; };
#endif
#endif
#if defined(__GNUC__) || defined(__clang__)
template <class Tp>
inline void DoNotOptimize(Tp const& value) {
asm volatile("" : : "g"(value) : "memory");
}
#else
template <class Tp>
inline void DoNotOptimize(Tp const&) {
// FIXME: Do something here...
}
#endif
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif