Fix MSVC ASan compilation by avoiding GCC/Clang specific stack instrumentation

PiperOrigin-RevId: 951656966
Change-Id: I51294e6a95c39f4037e8feb2aee45e69cb51beb0
This commit is contained in:
Yuval Tassa
2026-07-21 13:08:39 -07:00
committed by Copybara-Service
parent 8ccd2b6db5
commit 259e6c4dc6
12 changed files with 41 additions and 29 deletions
+10 -3
View File
@@ -26,8 +26,15 @@
#endif
#endif
// Define mjUSEASAN if ADDRESS_SANITIZER is active and we are not on MSVC.
// MSVC asan (/fsanitize=address defines ADDRESS_SANITIZER via EnableASAN) cannot use the GCC/clang
// attribute+asm instrumentation below, so we exclude it.
#if defined(ADDRESS_SANITIZER) && !defined(_MSC_VER)
#define mjUSEASAN
#endif
// Include asan interface header, or provide stubs for poison/unpoison macros when not using asan.
#ifdef ADDRESS_SANITIZER
#ifdef mjUSEASAN
#include <sanitizer/asan_interface.h>
#elif defined(_MSC_VER)
#define ASAN_POISON_MEMORY_REGION(addr, size)
@@ -42,7 +49,7 @@
// into mark/free into the same function, this instrumentation requires that the compiler retains
// separate mark/free calls for each original callee. The memory-clobbered asm blocks act as a
// barrier to prevent mark/free calls from being combined under optimization.
#ifdef ADDRESS_SANITIZER
#ifdef mjUSEASAN
#ifdef __cplusplus
extern "C" {
#endif
@@ -64,6 +71,6 @@ static inline void mj_freeStack(mjData* d) __attribute__((always_inline)) {
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // ADDRESS_SANITIZER
#endif // mjUSEASAN
#endif // MUJOCO_INCLUDE_MJSAN_H_
+1 -1
View File
@@ -267,7 +267,7 @@ MJAPI void mj_resetDataDebug(const mjModel* m, mjData* d, unsigned char debug_va
// Reset data. If 0 <= key < nkey, set fields from specified keyframe.
MJAPI void mj_resetDataKeyframe(const mjModel* m, mjData* d, int key);
#ifndef ADDRESS_SANITIZER // Stack management functions declared in mjsan.h if ASAN is active.
#ifndef mjUSEASAN // Stack management functions declared in mjsan.h if ASAN is active.
// Mark a new frame on the mjData stack.
MJAPI void mj_markStack(mjData* d);