From 420d45ceb42d015e02759fc92ac0153459d06a3f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 22 Aug 2025 14:33:24 +0000 Subject: [PATCH] BLI_noise: suppress signed int overflow warnings for hash_pcg2d_* Ref !144986 --- source/blender/blenlib/intern/noise.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc index 2ae89d6c966..b37d733e4dc 100644 --- a/source/blender/blenlib/intern/noise.cc +++ b/source/blender/blenlib/intern/noise.cc @@ -21,6 +21,19 @@ #include "BLI_noise.hh" #include "BLI_utildefines.h" +/* Some noise functions integer overflow as part of expected operation. */ +#ifdef __SANITIZE_ADDRESS__ +/* CLANG also supports GNU extensions. */ +# if defined(__GNUC__) || defined(__clang__) +# define ATTR_NO_SIGNED_INT_OVERFLOW [[gnu::no_sanitize("signed-integer-overflow")]] +# else +/* TODO: MSVC, others as needed. */ +# define ATTR_NO_SIGNED_INT_OVERFLOW +# endif +#else +# define ATTR_NO_SIGNED_INT_OVERFLOW +#endif + namespace blender::noise { /* -------------------------------------------------------------------- */ @@ -143,6 +156,7 @@ BLI_INLINE uint32_t float_as_uint(float f) * Slightly modified to only use signed integers, * so that they can also be implemented in OSL. */ +ATTR_NO_SIGNED_INT_OVERFLOW static inline int2 hash_pcg2d_i(int2 v) { v = v * int2(1664525) + int2(1013904223); @@ -154,6 +168,7 @@ static inline int2 hash_pcg2d_i(int2 v) return v; } +ATTR_NO_SIGNED_INT_OVERFLOW static inline int3 hash_pcg3d_i(int3 v) { v = v * int3(1664525) + int3(1013904223); @@ -167,6 +182,7 @@ static inline int3 hash_pcg3d_i(int3 v) return v; } +ATTR_NO_SIGNED_INT_OVERFLOW static inline int4 hash_pcg4d_i(int4 v) { v = v * int4(1664525) + int4(1013904223);