Skip to content

Commit 48716c0

Browse files
committed
fix crash
1 parent 8473c58 commit 48716c0

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

libdevice/sanitizer_utils.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ constexpr size_t AlignMask(size_t n) { return n - 1; }
672672
DEVICE_EXTERN_C_NOINLINE void __asan_##type##size( \
673673
uptr addr, uint32_t as, const char __SYCL_CONSTANT__ *file, \
674674
uint32_t line, const char __SYCL_CONSTANT__ *func) { \
675+
if (!__AsanLaunchInfo) { \
676+
return; \
677+
} \
675678
if (addr & AlignMask(size)) { \
676679
__asan_report_misalign_error(addr, as, size, is_write, addr, file, line, \
677680
func); \
@@ -684,6 +687,9 @@ constexpr size_t AlignMask(size_t n) { return n - 1; }
684687
DEVICE_EXTERN_C_NOINLINE void __asan_##type##size##_noabort( \
685688
uptr addr, uint32_t as, const char __SYCL_CONSTANT__ *file, \
686689
uint32_t line, const char __SYCL_CONSTANT__ *func) { \
690+
if (!__AsanLaunchInfo) { \
691+
return; \
692+
} \
687693
if (addr & AlignMask(size)) { \
688694
__asan_report_misalign_error(addr, as, size, is_write, addr, file, line, \
689695
func, true); \
@@ -709,6 +715,9 @@ ASAN_REPORT_ERROR(store, true, 16)
709715
DEVICE_EXTERN_C_NOINLINE void __asan_##type##N( \
710716
uptr addr, size_t size, uint32_t as, const char __SYCL_CONSTANT__ *file, \
711717
uint32_t line, const char __SYCL_CONSTANT__ *func) { \
718+
if (!__AsanLaunchInfo) { \
719+
return; \
720+
} \
712721
if (auto poisoned_addr = __asan_region_is_poisoned(addr, as, size)) { \
713722
__asan_report_access_error(addr, as, size, is_write, poisoned_addr, \
714723
file, line, func); \
@@ -717,6 +726,9 @@ ASAN_REPORT_ERROR(store, true, 16)
717726
DEVICE_EXTERN_C_NOINLINE void __asan_##type##N_noabort( \
718727
uptr addr, size_t size, uint32_t as, const char __SYCL_CONSTANT__ *file, \
719728
uint32_t line, const char __SYCL_CONSTANT__ *func) { \
729+
if (!__AsanLaunchInfo) { \
730+
return; \
731+
} \
720732
if (auto poisoned_addr = __asan_region_is_poisoned(addr, as, size)) { \
721733
__asan_report_access_error(addr, as, size, is_write, poisoned_addr, \
722734
file, line, func, true); \
@@ -731,6 +743,9 @@ ASAN_REPORT_ERROR_N(store, true)
731743
///
732744

733745
DEVICE_EXTERN_C_NOINLINE uptr __asan_mem_to_shadow(uptr ptr, uint32_t as) {
746+
if (!__AsanLaunchInfo) {
747+
return 0;
748+
}
734749
return MemToShadow(ptr, as);
735750
}
736751

@@ -744,6 +759,10 @@ static __SYCL_CONSTANT__ const char __mem_set_shadow_local[] =
744759
DEVICE_EXTERN_C_NOINLINE void
745760
__asan_set_shadow_static_local(uptr ptr, size_t size,
746761
size_t size_with_redzone) {
762+
if (!__AsanLaunchInfo) {
763+
return;
764+
}
765+
747766
// Since ptr is aligned to ASAN_SHADOW_GRANULARITY,
748767
// if size != aligned_size, then the buffer tail of ptr is not aligned
749768
uptr aligned_size = RoundUpTo(size, ASAN_SHADOW_GRANULARITY);
@@ -783,6 +802,10 @@ static __SYCL_CONSTANT__ const char __mem_unpoison_shadow_static_local_end[] =
783802
DEVICE_EXTERN_C_NOINLINE void
784803
__asan_unpoison_shadow_static_local(uptr ptr, size_t size,
785804
size_t size_with_redzone) {
805+
if (!__AsanLaunchInfo) {
806+
return;
807+
}
808+
786809
ASAN_DEBUG(__spirv_ocl_printf(__mem_unpoison_shadow_static_local_begin));
787810

788811
auto shadow_begin = MemToShadow(ptr + size, ADDRESS_SPACE_LOCAL);
@@ -816,6 +839,10 @@ static __SYCL_CONSTANT__ const char __mem_report_arg_count_incorrect[] =
816839

817840
DEVICE_EXTERN_C_NOINLINE void
818841
__asan_set_shadow_dynamic_local(uptr ptr, uint32_t num_args) {
842+
if (!__AsanLaunchInfo) {
843+
return;
844+
}
845+
819846
ASAN_DEBUG(__spirv_ocl_printf(__mem_set_shadow_dynamic_local_begin));
820847

821848
auto *launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo;
@@ -847,6 +874,10 @@ static __SYCL_CONSTANT__ const char __mem_unpoison_shadow_dynamic_local_end[] =
847874

848875
DEVICE_EXTERN_C_NOINLINE void
849876
__asan_unpoison_shadow_dynamic_local(uptr ptr, uint32_t num_args) {
877+
if (!__AsanLaunchInfo) {
878+
return;
879+
}
880+
850881
ASAN_DEBUG(__spirv_ocl_printf(__mem_unpoison_shadow_dynamic_local_begin));
851882

852883
auto *launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo;
@@ -883,6 +914,10 @@ static __SYCL_CONSTANT__ const char __mem_set_shadow_private[] =
883914

884915
DEVICE_EXTERN_C_NOINLINE void __asan_set_shadow_private(uptr begin, uptr size,
885916
char val) {
917+
if (!__AsanLaunchInfo) {
918+
return;
919+
}
920+
886921
ASAN_DEBUG(__spirv_ocl_printf(__mem_set_shadow_private_begin));
887922

888923
auto *launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo;

llvm/lib/SYCLLowerIR/ComputeModuleRuntimeInfo.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,7 @@ getSYCLESIMDSplitStatusFromMetadata(const Module &M) {
4646
} // namespace
4747

4848
bool isModuleUsingAsan(const Module &M) {
49-
for (const auto &F : M) {
50-
if (F.getCallingConv() != CallingConv::SPIR_KERNEL)
51-
continue;
52-
if (F.arg_size() == 0)
53-
continue;
54-
const auto *LastArg = F.getArg(F.arg_size() - 1);
55-
if (LastArg->getName() == "__asan_launch")
56-
return true;
57-
}
58-
return false;
49+
return M.getNamedGlobal("__AsanKernelMetadata");
5950
}
6051

6152
// This function traverses over reversed call graph by BFS algorithm.

0 commit comments

Comments
 (0)