Skip to content

Commit 167ddf9

Browse files
authored
Merge pull request #1747 from AllanZyne/review/yang/misalign_access
[DeviceSanitizer] Support detecting misaligned access error
2 parents 76c6bf9 + 0cd10f6 commit 167ddf9

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

source/loader/layers/sanitizer/asan_interceptor.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,17 @@ ur_result_t SanitizerInterceptor::postLaunchKernel(ur_kernel_handle_t Kernel,
358358
if (!AH.Flag) {
359359
continue;
360360
}
361-
if (AH.ErrorType == DeviceSanitizerErrorType::USE_AFTER_FREE) {
361+
switch (AH.ErrorType) {
362+
case DeviceSanitizerErrorType::USE_AFTER_FREE:
362363
ReportUseAfterFree(AH, Kernel, GetContext(Queue));
363-
} else if (AH.ErrorType ==
364-
DeviceSanitizerErrorType::OUT_OF_BOUNDS ||
365-
AH.ErrorType == DeviceSanitizerErrorType::MISALIGNED ||
366-
AH.ErrorType == DeviceSanitizerErrorType::NULL_POINTER) {
367-
ReportOutOfBoundsError(AH, Kernel);
368-
} else {
369-
ReportGenericError(AH);
364+
break;
365+
case DeviceSanitizerErrorType::OUT_OF_BOUNDS:
366+
case DeviceSanitizerErrorType::MISALIGNED:
367+
case DeviceSanitizerErrorType::NULL_POINTER:
368+
ReportGenericError(AH, Kernel);
369+
break;
370+
default:
371+
ReportFatalError(AH);
370372
}
371373
if (!AH.IsRecover) {
372374
exit(1);

source/loader/layers/sanitizer/asan_report.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ void ReportDoubleFree(uptr Addr, const StackTrace &Stack,
7676
AI->AllocStack.print();
7777
}
7878

79-
void ReportGenericError(const DeviceSanitizerReport &Report) {
79+
void ReportFatalError(const DeviceSanitizerReport &Report) {
8080
context.logger.always("\n====ERROR: DeviceSanitizer: {}",
8181
ToString(Report.ErrorType));
8282
}
8383

84-
void ReportOutOfBoundsError(const DeviceSanitizerReport &Report,
85-
ur_kernel_handle_t Kernel) {
84+
void ReportGenericError(const DeviceSanitizerReport &Report,
85+
ur_kernel_handle_t Kernel) {
8686
const char *File = Report.File[0] ? Report.File : "<unknown file>";
8787
const char *Func = Report.Func[0] ? Report.Func : "<unknown func>";
8888
auto KernelName = GetKernelName(Kernel);

source/loader/layers/sanitizer/asan_report.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ void ReportBadContext(uptr Addr, const StackTrace &stack,
3131
void ReportDoubleFree(uptr Addr, const StackTrace &Stack,
3232
const std::shared_ptr<AllocInfo> &AllocInfo);
3333

34-
void ReportGenericError(const DeviceSanitizerReport &Report);
34+
// This type of error is usually unexpected mistake and doesn't have enough debug information
35+
void ReportFatalError(const DeviceSanitizerReport &Report);
3536

36-
void ReportOutOfBoundsError(const DeviceSanitizerReport &Report,
37-
ur_kernel_handle_t Kernel);
37+
void ReportGenericError(const DeviceSanitizerReport &Report,
38+
ur_kernel_handle_t Kernel);
3839

3940
void ReportUseAfterFree(const DeviceSanitizerReport &Report,
4041
ur_kernel_handle_t Kernel, ur_context_handle_t Context);

0 commit comments

Comments
 (0)