compat/atomics: store pointers through the exchange on MSVC for ARM before 19.44

The alias analysis of MSVC for ARM and ARM64 before 19.44 does not track
a pointer that is converted to an integer for the __iso_volatile_store
and __stlr intrinsics, so the stores initializing the pointed-to object
are eliminated as dead. Storing the address of an automatic array into
an atomic pointer and reading through it afterwards then reads
uninitialized stack. The stdatomic.h of /experimental:c11atomics
generates the same code, 19.44 is the first version without the bug.
The interlocked exchange is not affected, and with its result unused it
compiles to the same store as a plain store would without the bug.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
This commit is contained in:
Kacper Michajłow committed 2026-09-14 04:35:12 +02:00
1 parent b2854aadce
commit 8a1feb3c70
1 file changed
+10
+10
View File
@@ -154,7 +154,17 @@ static av_always_inline void ff_atomic_store_ptr(volatile void *object,
const volatile void *desired,
memory_order order)
{
/* The alias analysis of MSVC for ARM before 19.44 does not track a pointer
* converted to an integer for the store intrinsics, so the stores initializing
* the pointed-to object are eliminated as dead. The interlocked exchange is not
* affected, and with its result unused it compiles to the same store as a plain
* store would without the bug. */
#if defined(_MSC_VER) && !defined(__clang__) && _MSC_VER < 1944 && \
(defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC))
FF_ATOMIC_SIZE(exchange, sizeof(void *))(object, (uintptr_t)desired, order);
#else
FF_ATOMIC_SIZE(store, sizeof(void *))(object, (uintptr_t)desired, order);
#endif
}
static av_always_inline uintptr_t