Commit b678c18c9e for openssl.org

commit b678c18c9e86cd2d906dde65b69c7750fdd35d52
Author: Frederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
Date:   Wed Feb 25 20:06:07 2026 +0100

    Fallback implementation of tsan_add now returns value before addition to be consistent with other definitions

    Fixes #28410

    Reviewed-by: Neil Horman <nhorman@openssl.org>
    Reviewed-by: Paul Dale <paul.dale@oracle.com>
    MergeDate: Sat Feb 28 14:10:25 2026
    (Merged from https://github.com/openssl/openssl/pull/30180)

diff --git a/include/internal/tsan_assist.h b/include/internal/tsan_assist.h
index 998c45170e..42953371cc 100644
--- a/include/internal/tsan_assist.h
+++ b/include/internal/tsan_assist.h
@@ -137,7 +137,25 @@

 #define tsan_load(ptr) (*(ptr))
 #define tsan_store(ptr, val) (*(ptr) = (val))
-#define tsan_add(ptr, n) (*(ptr) += (n))
+
+static ossl_inline ossl_unused int64_t tsan_add_fallback64(int64_t *ptr, int64_t n)
+{
+    int64_t old = *ptr;
+    *ptr = old + n;
+    return old;
+}
+
+static ossl_inline ossl_unused int32_t tsan_add_fallback32(int32_t *ptr, int32_t n)
+{
+    int32_t old = *ptr;
+    *ptr = old + n;
+    return old;
+}
+
+#define tsan_add(ptr, n)                                              \
+    (sizeof(*(ptr)) == 8 ? tsan_add_fallback64((int64_t *)(ptr), (n)) \
+                         : tsan_add_fallback32((int32_t *)(ptr), (n)))
+
 /*
  * Lack of tsan_ld_acq and tsan_ld_rel means that compiler support is not
  * sophisticated enough to support them. Code that relies on them should be