From 03111e5e7a8690300966a39f0aa2e4f2b4ec919a Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Mon, 21 Sep 2020 13:42:54 -0400 Subject: [PATCH] [OpenMP] Protect unrecogonized CUDA error code If an error code can not be recognized by cuGetErrorString, errStr remains null and causes crashing at DP() printing. Protect this case. Reviewed By: jhuber6, tianshilei1992 Differential Revision: https://reviews.llvm.org/D87980 --- openmp/libomptarget/plugins/cuda/src/rtl.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/openmp/libomptarget/plugins/cuda/src/rtl.cpp b/openmp/libomptarget/plugins/cuda/src/rtl.cpp index 1a0bffb..0422bfb 100644 --- a/openmp/libomptarget/plugins/cuda/src/rtl.cpp +++ b/openmp/libomptarget/plugins/cuda/src/rtl.cpp @@ -30,9 +30,17 @@ #define CUDA_ERR_STRING(err) \ do { \ if (getDebugLevel() > 0) { \ - const char *errStr; \ - cuGetErrorString(err, &errStr); \ - DP("CUDA error is: %s\n", errStr); \ + const char *errStr = nullptr; \ + CUresult errStr_status = cuGetErrorString(err, &errStr); \ + if (errStr_status == CUDA_ERROR_INVALID_VALUE) \ + DP("Unrecognized CUDA error code: %d\n", err); \ + else if (errStr_status == CUDA_SUCCESS) \ + DP("CUDA error is: %s\n", errStr); \ + else { \ + DP("Unresolved CUDA error code: %d\n", err); \ + DP("Unsuccessful cuGetErrorString return status: %d\n", \ + errStr_status); \ + } \ } \ } while (false) #else // OMPTARGET_DEBUG -- 2.7.4