Skip to content

Commit ad809b4

Browse files
committed
fix crash
1 parent 91f7390 commit ad809b4

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,10 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
691691
SanitizeVal = "address";
692692
break;
693693
}
694+
if (Arg.find("-fsanitize=memory") != std::string::npos) {
695+
SanitizeVal = "memory";
696+
break;
697+
}
694698
}
695699
}
696700

libdevice/sanitizer/msan_rtl.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ void __msan_internal_report_save(const uint32_t size,
6868
const int Expected = MSAN_REPORT_NONE;
6969
int Desired = MSAN_REPORT_START;
7070

71-
if (UNLIKELY(!__MsanLaunchInfo)) {
72-
__spirv_ocl_printf(__msan_print_warning_nolaunchinfo);
73-
return;
74-
}
75-
7671
auto &SanitizerReport =
7772
((__SYCL_GLOBAL__ MsanLaunchInfo *)__MsanLaunchInfo.get())->Report;
7873

@@ -116,8 +111,6 @@ void __msan_internal_report_save(const uint32_t size,
116111

117112
// Show we've done copying
118113
atomicStore(&SanitizerReport.Flag, MSAN_REPORT_FINISH);
119-
120-
MSAN_DEBUG(__spirv_ocl_printf(__msan_print_report, size, func));
121114
}
122115
}
123116

@@ -162,18 +155,18 @@ MSAN_MAYBE_WARNING(u32, 4)
162155
MSAN_MAYBE_WARNING(u64, 8)
163156

164157
DEVICE_EXTERN_C_NOINLINE uptr __msan_get_shadow(uptr addr, uint32_t as) {
158+
// Return clean shadow (0s) by default
159+
uptr shadow_ptr = (uptr)CleanShadow;
160+
165161
if (UNLIKELY(!__MsanLaunchInfo)) {
166162
__spirv_ocl_printf(__msan_print_warning_nolaunchinfo);
167-
return 0;
163+
return shadow_ptr;
168164
}
169165

170166
auto launch_info = (__SYCL_GLOBAL__ MsanLaunchInfo *)__MsanLaunchInfo.get();
171167
MSAN_DEBUG(__spirv_ocl_printf(__msan_print_launchinfo, (void *)launch_info,
172168
launch_info->GlobalShadowOffset));
173169

174-
// Return clean shadow (0s) by default
175-
uptr shadow_ptr = (uptr)CleanShadow;
176-
177170
if (LIKELY(launch_info->DeviceTy == DeviceType::CPU)) {
178171
shadow_ptr = __msan_get_shadow_cpu(addr);
179172
} else if (launch_info->DeviceTy == DeviceType::GPU_PVC) {

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
#include "llvm/Analysis/GlobalsModRef.h"
162162
#include "llvm/Analysis/TargetLibraryInfo.h"
163163
#include "llvm/Analysis/ValueTracking.h"
164+
#include "llvm/Demangle/Demangle.h"
164165
#include "llvm/IR/Argument.h"
165166
#include "llvm/IR/AttributeMask.h"
166167
#include "llvm/IR/Attributes.h"
@@ -196,6 +197,7 @@
196197
#include "llvm/Support/DebugCounter.h"
197198
#include "llvm/Support/ErrorHandling.h"
198199
#include "llvm/Support/MathExtras.h"
200+
#include "llvm/Support/Path.h"
199201
#include "llvm/Support/raw_ostream.h"
200202
#include "llvm/TargetParser/Triple.h"
201203
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -528,6 +530,19 @@ static const PlatformMemoryMapParams NetBSD_X86_MemoryMapParams = {
528530
&NetBSD_X86_64_MemoryMapParams,
529531
};
530532

533+
// SPIR Linux
534+
static const MemoryMapParams Intel_SPIR_MemoryMapParams = {
535+
0, // AndMask
536+
0, // XorMask (not used)
537+
0, // ShadowBase (not used)
538+
0, // OriginBase
539+
};
540+
541+
static const PlatformMemoryMapParams Intel_GFX_MemoryMapParams = {
542+
nullptr,
543+
&Intel_SPIR_MemoryMapParams,
544+
};
545+
531546
// Spir memory address space
532547
static constexpr unsigned kSpirOffloadPrivateAS = 0;
533548
static constexpr unsigned kSpirOffloadGlobalAS = 1;
@@ -1069,6 +1084,7 @@ void MemorySanitizer::initializeModule(Module &M) {
10691084
// NOTE: Support SPIR or SPIRV only, without MapParams
10701085
if (!TargetTriple.isSPIROrSPIRV())
10711086
report_fatal_error("unsupported architecture");
1087+
MapParams = Intel_GFX_MemoryMapParams.bits64;
10721088
break;
10731089
default:
10741090
report_fatal_error("unsupported operating system");

sycl/test-e2e/MemorySanitizer/check_call.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@ __attribute__((noinline)) long long foo(int data1, long long data2) {
1313

1414
int main() {
1515
sycl::queue Q;
16-
auto *array1 = sycl::malloc_device<int>(2, Q);
17-
auto *array2 = sycl::malloc_device<long long>(2, Q);
16+
auto *array = sycl::malloc_device<int>(2, Q);
1817

1918
Q.submit([&](sycl::handler &h) {
2019
h.single_task<class MyKernel>(
21-
[=]() { array2[0] = foo(array1[0], array2[1]); });
20+
[=]() { array[0] = foo(array[0], array[1]); });
2221
});
2322
Q.wait();
2423
// CHECK: use-of-uninitialized-value
2524
// CHECK: kernel <{{.*MyKernel}}>
2625
// CHECK: #0 {{.*}} {{.*check_call.cpp}}:[[@LINE-5]]
2726

28-
sycl::free(array1, Q);
29-
sycl::free(array2, Q);
27+
sycl::free(array, Q);
3028
return 0;
3129
}

0 commit comments

Comments
 (0)