Skip to content

Commit ee05fbf

Browse files
authored
[DeviceSanitizer] Fix wrong test for nullptr detection (#15467)
The content of "global_nullptr.cpp" was same with "private_nullptr.cpp". This patch fix this.
1 parent b9112cb commit ee05fbf

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

libdevice/sanitizer_utils.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,20 @@ __SYCL_PRIVATE__ void *ToPrivate(void *ptr) {
120120
return __spirv_GenericCastToPtrExplicit_ToPrivate(ptr, 7);
121121
}
122122

123-
inline bool ConvertGenericPointer(uptr &addr, uint32_t &as) {
123+
inline void ConvertGenericPointer(uptr &addr, uint32_t &as) {
124124
auto old = addr;
125125
if ((addr = (uptr)ToPrivate((void *)old))) {
126126
as = ADDRESS_SPACE_PRIVATE;
127127
} else if ((addr = (uptr)ToLocal((void *)old))) {
128128
as = ADDRESS_SPACE_LOCAL;
129-
} else if ((addr = (uptr)ToGlobal((void *)old))) {
130-
as = ADDRESS_SPACE_GLOBAL;
131129
} else {
132-
if (__AsanDebug)
133-
__spirv_ocl_printf(__generic_to_fail, old);
134-
return false;
130+
// FIXME: I'm not sure if we need to check ADDRESS_SPACE_CONSTANT,
131+
// but this can really simplify the generic pointer conversion logic
132+
as = ADDRESS_SPACE_GLOBAL;
133+
addr = old;
135134
}
136135
if (__AsanDebug)
137136
__spirv_ocl_printf(__generic_to, old, addr, as);
138-
return true;
139137
}
140138

141139
inline uptr MemToShadow_CPU(uptr addr) {
@@ -144,9 +142,7 @@ inline uptr MemToShadow_CPU(uptr addr) {
144142

145143
inline uptr MemToShadow_DG2(uptr addr, uint32_t as) {
146144
if (as == ADDRESS_SPACE_GENERIC) {
147-
if (!ConvertGenericPointer(addr, as)) {
148-
return 0;
149-
}
145+
ConvertGenericPointer(addr, as);
150146
}
151147

152148
if (as == ADDRESS_SPACE_GLOBAL) { // global
@@ -233,9 +229,7 @@ inline uptr MemToShadow_DG2(uptr addr, uint32_t as) {
233229

234230
inline uptr MemToShadow_PVC(uptr addr, uint32_t as) {
235231
if (as == ADDRESS_SPACE_GENERIC) {
236-
if (!ConvertGenericPointer(addr, as)) {
237-
return 0;
238-
}
232+
ConvertGenericPointer(addr, as);
239233
}
240234

241235
if (as == ADDRESS_SPACE_GLOBAL) { // global

sycl/test-e2e/AddressSanitizer/nullpointer/global_nullptr.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,14 @@
1111

1212
#include <sycl/detail/core.hpp>
1313

14-
#include <sycl/ext/oneapi/experimental/address_cast.hpp>
15-
1614
int main() {
1715
sycl::queue Q;
1816
constexpr std::size_t N = 4;
1917
int *array = nullptr;
2018

2119
Q.submit([&](sycl::handler &h) {
2220
h.parallel_for<class MyKernel>(
23-
sycl::nd_range<1>(N, 1), [=](sycl::nd_item<1> item) {
24-
auto private_array =
25-
sycl::ext::oneapi::experimental::static_address_cast<
26-
sycl::access::address_space::private_space>(array);
27-
private_array[0] = 0;
28-
});
21+
sycl::nd_range<1>(N, 1), [=](sycl::nd_item<1> item) { array[0] = 0; });
2922
Q.wait();
3023
});
3124
// CHECK: ERROR: DeviceSanitizer: null-pointer-access on Unknown Memory

0 commit comments

Comments
 (0)