Skip to content

Commit 503494f

Browse files
authored
[DeviceAddressSanitizer] Add warning for unaligned __asan_mem_to_shadow call (#18879)
And skip some test affected by OpenCL CPU subgroup buffer alignment issue. This PR addresses #18743.
1 parent 57bdbe3 commit 503494f

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

libdevice/sanitizer/asan_rtl.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,24 @@ ASAN_REPORT_ERROR_N(store, true)
707707

708708
///
709709
/// ASAN convert memory address to shadow memory address
710+
/// This function is used only for getting shadow address of private memory so
711+
/// that we can poison them later. And the current implmentation require the ptr
712+
/// to be aligned with ASAN_SHADOW_GRANULARITY. If not aligned, the subsequent
713+
/// poisoning will not work correctly.
710714
///
715+
static __SYCL_CONSTANT__ const char __asan_mem_to_shadow_unaligned_msg[] =
716+
"[kernel] __asan_mem_to_shadow() unaligned address: %p\n";
711717

712718
DEVICE_EXTERN_C_NOINLINE uptr __asan_mem_to_shadow(uptr ptr, uint32_t as) {
713719
if (!__AsanLaunchInfo)
714720
return 0;
715721

722+
// If ptr is not aligned, then it should be considered as implementation
723+
// error. Print a warning for it.
724+
if (ptr & AlignMask(ASAN_SHADOW_GRANULARITY)) {
725+
__spirv_ocl_printf(__asan_mem_to_shadow_unaligned_msg, (void *)ptr);
726+
}
727+
716728
return MemToShadow(ptr, as);
717729
}
718730

sycl/test-e2e/AddressSanitizer/out-of-bounds/buffer/buffer_3d.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// REQUIRES: linux, cpu || (gpu && level_zero)
22
// RUN: %{build} %device_asan_flags -O0 -g -o %t1.out
3-
// RUN: %{run} not %t1.out 2>&1 | FileCheck %s
3+
// OCL CPU has subgroup alignment issue with -O0, skip it for
4+
// now.(CMPLRLLVM-61493)
5+
// RUN: %{run} %if !cpu %{ not %t1.out 2>&1 | FileCheck %s %}
46
// RUN: %{build} %device_asan_flags -O1 -g -o %t2.out
57
// RUN: %{run} not %t2.out 2>&1 | FileCheck %s
8+
// RUN: %{build} %device_asan_flags -O2 -g -o %t3.out
9+
// RUN: %{run} not %t3.out 2>&1 | FileCheck %s
610

711
#include <sycl/detail/core.hpp>
812

sycl/test-e2e/AddressSanitizer/out-of-bounds/local/group_local_memory.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// REQUIRES: linux, cpu || (gpu && level_zero)
22
// RUN: %{build} %device_asan_flags -g -O0 -o %t1.out
3-
// RUN: %{run} not %t1.out 2>&1 | FileCheck %s
3+
// OCL CPU has subgroup alignment issue with -O0, skip it for
4+
// now.(CMPLRLLVM-61493)
5+
// RUN: %{run} %if !cpu %{ not %t1.out 2>&1 | FileCheck %s %}
46
// RUN: %{build} %device_asan_flags -g -O1 -o %t2.out
57
// RUN: %{run} not %t2.out 2>&1 | FileCheck %s
68
// RUN: %{build} %device_asan_flags -g -O2 -o %t3.out

sycl/test-e2e/AddressSanitizer/out-of-bounds/local/group_local_memory_func.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// REQUIRES: linux, cpu || (gpu && level_zero)
2+
// OCL CPU has subgroup alignment issue with -O0, skip it for
3+
// now.(CMPLRLLVM-61493)
24
// RUN: %{build} %device_asan_flags -g -O0 -o %t1.out
3-
// RUN: %{run} not %t1.out 2>&1 | FileCheck %s
5+
// RUN: %{run} %if !cpu %{ not %t1.out 2>&1 | FileCheck %s %}
46
// RUN: %{build} %device_asan_flags -g -O1 -o %t2.out
57
// RUN: %{run} not %t2.out 2>&1 | FileCheck %s
68
// RUN: %{build} %device_asan_flags -g -O2 -o %t3.out

0 commit comments

Comments
 (0)