Skip to content

Commit c310aed

Browse files
authored
[DeviceSanitizer] Add assertion to possible nullptr and die when trying to create shadow with unsupported device (#19129)
Addresses #18333.
1 parent bf21b9d commit c310aed

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

unified-runtime/source/loader/layers/sanitizer/asan/asan_interceptor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ KernelInfo &AsanInterceptor::getOrCreateKernelInfo(ur_kernel_handle_t Kernel) {
671671
// Create new KernelInfo
672672
auto Program = GetProgram(Kernel);
673673
auto PI = getProgramInfo(Program);
674+
assert(PI != nullptr && "unregistered program!");
674675
bool IsInstrumented = PI->isKernelInstrumented(Kernel);
675676

676677
std::scoped_lock<ur_shared_mutex> Guard(m_KernelMapMutex);

unified-runtime/source/loader/layers/sanitizer/msan/msan_interceptor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ ur_result_t MsanInterceptor::registerSpirKernels(ur_program_handle_t Program) {
229229
}
230230

231231
auto PI = getProgramInfo(Program);
232+
assert(PI != nullptr && "unregistered program!");
232233
for (const auto &SKI : SKInfo) {
233234
if (SKI.Size == 0) {
234235
continue;
@@ -404,6 +405,7 @@ KernelInfo &MsanInterceptor::getOrCreateKernelInfo(ur_kernel_handle_t Kernel) {
404405

405406
// Create new KernelInfo
406407
auto PI = getProgramInfo(GetProgram(Kernel));
408+
assert(PI != nullptr && "unregistered program!");
407409
auto KI = std::make_unique<KernelInfo>(Kernel);
408410

409411
KI->IsInstrumented = PI->isKernelInstrumented(Kernel);

unified-runtime/source/loader/layers/sanitizer/msan/msan_shadow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ GetMsanShadowMemory(ur_context_handle_t Context, ur_device_handle_t Device,
7575
static std::shared_ptr<MsanShadowMemory> ShadowDG2 =
7676
std::make_shared<MsanShadowMemoryDG2>(Context, Device);
7777
return ShadowDG2;
78-
} else {
79-
UR_LOG_L(getContext()->logger, ERR, "Unsupport device type");
80-
return nullptr;
8178
}
79+
80+
die("GetMsanShadowMemory: Unsupport device type");
81+
return nullptr;
8282
}
8383

8484
ur_result_t MsanShadowMemoryCPU::Setup() {

unified-runtime/source/loader/layers/sanitizer/tsan/tsan_shadow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ std::shared_ptr<ShadowMemory> GetShadowMemory(ur_context_handle_t Context,
2929
return ShadowCPU;
3030
} else if (Type == DeviceType::GPU_PVC) {
3131
return std::make_shared<ShadowMemoryPVC>(Context, Device);
32-
} else {
33-
UR_LOG_L(getContext()->logger, ERR, "Unsupport device type");
34-
return nullptr;
3532
}
33+
34+
die("GetShadowMemory: Unsupport device type");
35+
return nullptr;
3636
}
3737

3838
ur_result_t ShadowMemoryCPU::Setup() {

0 commit comments

Comments
 (0)