Skip to content

Commit 7884caf

Browse files
dsharletgxnnpack-bot
authored andcommitted
Disable inlining of functions that attempt to disable sanitizers
PiperOrigin-RevId: 839978104
1 parent c18f402 commit 7884caf

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/xnnpack/common.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,32 +264,46 @@
264264
#define XNN_UNPREDICTABLE(condition) (!!(condition))
265265
#endif
266266

267+
#if defined(__clang__)
268+
// Clang ignores sanitizer attributes on functions that get inlined. Also:
269+
// - GCC does not allow this attribute to be specified after a function
270+
// - It takes precedence over always_inline, so we can specify both.
271+
#define XNN_NO_INLINE_SANITIZER __attribute__((__noinline__))
272+
#else
273+
#define XNN_NO_INLINE_SANITIZER
274+
#endif
275+
267276
#if XNN_COMPILER_HAS_FEATURE(thread_sanitizer)
268-
#define XNN_DISABLE_TSAN __attribute__((__no_sanitize__("thread")))
277+
#define XNN_DISABLE_TSAN \
278+
__attribute__((__no_sanitize__("thread"))) XNN_NO_INLINE_SANITIZER
269279
#else
270280
#define XNN_DISABLE_TSAN
271281
#endif
272282

273283
#if XNN_COMPILER_HAS_FEATURE(memory_sanitizer)
274-
#define XNN_DISABLE_MSAN __attribute__((__no_sanitize__("memory")))
284+
#define XNN_DISABLE_MSAN \
285+
__attribute__((__no_sanitize__("memory"))) XNN_NO_INLINE_SANITIZER
275286
#else
276287
#define XNN_DISABLE_MSAN
277288
#endif
278289

279290
#if XNN_COMPILER_HAS_FEATURE(hwaddress_sanitizer)
280-
#define XNN_DISABLE_HWASAN __attribute__((__no_sanitize__("hwaddress")))
291+
#define XNN_DISABLE_HWASAN \
292+
__attribute__((__no_sanitize__("hwaddress"))) XNN_NO_INLINE_SANITIZER
281293
#else
282294
#define XNN_DISABLE_HWASAN
283295
#endif
284296

285297
#if XNN_COMPILER_HAS_FEATURE(address_sanitizer)
286-
#define XNN_DISABLE_ASAN __attribute__((__no_sanitize__("address")))
298+
#define XNN_DISABLE_ASAN \
299+
__attribute__((__no_sanitize__("address"))) XNN_NO_INLINE_SANITIZER
287300
#else
288301
#define XNN_DISABLE_ASAN
289302
#endif
290303

291304
#if XNN_COMPILER_HAS_FEATURE(undefined_behavior_sanitizer)
292-
#define XNN_DISABLE_UBSAN __attribute__((__no_sanitize__("undefined")))
305+
#define XNN_DISABLE_UBSAN \
306+
__attribute__((__no_sanitize__("undefined"))) XNN_NO_INLINE_SANITIZER
293307
#else
294308
#define XNN_DISABLE_UBSAN
295309
#endif

0 commit comments

Comments
 (0)