@@ -665,11 +665,16 @@ constexpr size_t AlignMask(size_t n) { return n - 1; }
665665// /
666666// / ASAN Load/Store Report Built-ins
667667// /
668+ // / NOTE:
669+ // / if __AsanLaunchInfo equals 0, the sanitizer is disabled for this launch
670+ // /
668671
669672#define ASAN_REPORT_ERROR_BASE (type, is_write, size, as ) \
670673 DEVICE_EXTERN_C_NOINLINE void __asan_##type##size##_as##as( \
671674 uptr addr, const char __SYCL_CONSTANT__ *file, uint32_t line, \
672675 const char __SYCL_CONSTANT__ *func) { \
676+ if (!__AsanLaunchInfo) \
677+ return ; \
673678 if (addr & AlignMask (size)) { \
674679 __asan_report_misalign_error (addr, as, size, is_write, addr, file, line, \
675680 func); \
@@ -682,6 +687,8 @@ constexpr size_t AlignMask(size_t n) { return n - 1; }
682687 DEVICE_EXTERN_C_NOINLINE void __asan_##type##size##_as##as##_noabort( \
683688 uptr addr, const char __SYCL_CONSTANT__ *file, uint32_t line, \
684689 const char __SYCL_CONSTANT__ *func) { \
690+ if (!__AsanLaunchInfo) \
691+ return ; \
685692 if (addr & AlignMask (size)) { \
686693 __asan_report_misalign_error (addr, as, size, is_write, addr, file, line, \
687694 func, true ); \
@@ -714,6 +721,8 @@ ASAN_REPORT_ERROR(store, true, 16)
714721 DEVICE_EXTERN_C_NOINLINE void __asan_##type##N_as##as( \
715722 uptr addr, size_t size, const char __SYCL_CONSTANT__ *file, \
716723 uint32_t line, const char __SYCL_CONSTANT__ *func) { \
724+ if (!__AsanLaunchInfo) \
725+ return ; \
717726 if (auto poisoned_addr = __asan_region_is_poisoned (addr, as, size)) { \
718727 __asan_report_access_error (addr, as, size, is_write, poisoned_addr, \
719728 file, line, func); \
@@ -722,6 +731,8 @@ ASAN_REPORT_ERROR(store, true, 16)
722731 DEVICE_EXTERN_C_NOINLINE void __asan_##type##N_as##as##_noabort( \
723732 uptr addr, size_t size, const char __SYCL_CONSTANT__ *file, \
724733 uint32_t line, const char __SYCL_CONSTANT__ *func) { \
734+ if (!__AsanLaunchInfo) \
735+ return ; \
725736 if (auto poisoned_addr = __asan_region_is_poisoned (addr, as, size)) { \
726737 __asan_report_access_error (addr, as, size, is_write, poisoned_addr, \
727738 file, line, func, true ); \
@@ -743,6 +754,9 @@ ASAN_REPORT_ERROR_N(store, true)
743754// /
744755
745756DEVICE_EXTERN_C_NOINLINE uptr __asan_mem_to_shadow(uptr ptr, uint32_t as) {
757+ if (!__AsanLaunchInfo)
758+ return 0 ;
759+
746760 return MemToShadow (ptr, as);
747761}
748762
@@ -756,6 +770,9 @@ static __SYCL_CONSTANT__ const char __mem_set_shadow_local[] =
756770DEVICE_EXTERN_C_NOINLINE void
757771__asan_set_shadow_static_local (uptr ptr, size_t size,
758772 size_t size_with_redzone) {
773+ if (!__AsanLaunchInfo)
774+ return ;
775+
759776 // Since ptr is aligned to ASAN_SHADOW_GRANULARITY,
760777 // if size != aligned_size, then the buffer tail of ptr is not aligned
761778 uptr aligned_size = RoundUpTo (size, ASAN_SHADOW_GRANULARITY);
@@ -795,6 +812,9 @@ static __SYCL_CONSTANT__ const char __mem_unpoison_shadow_static_local_end[] =
795812DEVICE_EXTERN_C_NOINLINE void
796813__asan_unpoison_shadow_static_local (uptr ptr, size_t size,
797814 size_t size_with_redzone) {
815+ if (!__AsanLaunchInfo)
816+ return ;
817+
798818 ASAN_DEBUG (__spirv_ocl_printf (__mem_unpoison_shadow_static_local_begin));
799819
800820 auto shadow_begin = MemToShadow (ptr + size, ADDRESS_SPACE_LOCAL);
@@ -828,6 +848,9 @@ static __SYCL_CONSTANT__ const char __mem_report_arg_count_incorrect[] =
828848
829849DEVICE_EXTERN_C_NOINLINE void
830850__asan_set_shadow_dynamic_local (uptr ptr, uint32_t num_args) {
851+ if (!__AsanLaunchInfo)
852+ return ;
853+
831854 ASAN_DEBUG (__spirv_ocl_printf (__mem_set_shadow_dynamic_local_begin));
832855
833856 auto *launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo;
@@ -859,6 +882,9 @@ static __SYCL_CONSTANT__ const char __mem_unpoison_shadow_dynamic_local_end[] =
859882
860883DEVICE_EXTERN_C_NOINLINE void
861884__asan_unpoison_shadow_dynamic_local (uptr ptr, uint32_t num_args) {
885+ if (!__AsanLaunchInfo)
886+ return ;
887+
862888 ASAN_DEBUG (__spirv_ocl_printf (__mem_unpoison_shadow_dynamic_local_begin));
863889
864890 auto *launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo;
@@ -895,6 +921,9 @@ static __SYCL_CONSTANT__ const char __mem_set_shadow_private[] =
895921
896922DEVICE_EXTERN_C_NOINLINE void __asan_set_shadow_private (uptr begin, uptr size,
897923 char val) {
924+ if (!__AsanLaunchInfo)
925+ return ;
926+
898927 ASAN_DEBUG (__spirv_ocl_printf (__mem_set_shadow_private_begin));
899928
900929 auto *launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo;
0 commit comments