From 178a42c57398257ce0c3189ee24d4954785b6dc6 Mon Sep 17 00:00:00 2001 From: Ian Li Date: Tue, 10 Sep 2024 03:30:28 -0400 Subject: [PATCH] [SYCL] Initialize uninitialized handler_impl fields (#15323) In the same vein as https://github.com/intel/llvm/pull/15237, this PR fixes additional uninitialized values recently discovered by Coverity. Similar to the resolution discussed in #15237, I have default-initialized integer values that are defined later on to 0 instead of another more complex solution. Additionally, since I had set `MExternalSempahore` in `handler_impl` to `nullptr`, I added null checks where `MExternalSemaphore` is ultimately returned to ensure `nullptr` doesn't actually get passed into the UR. This is not necessarily necessary, but without this check Coverity would probably generate another hit because of it. --- sycl/source/detail/cg.hpp | 6 ++++++ sycl/source/detail/handler_impl.hpp | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sycl/source/detail/cg.hpp b/sycl/source/detail/cg.hpp index 42bd088427dd9..c4ae7d87f4403 100644 --- a/sycl/source/detail/cg.hpp +++ b/sycl/source/detail/cg.hpp @@ -624,6 +624,8 @@ class CGSemaphoreWait : public CG { MExternalSemaphore(ExternalSemaphore), MWaitValue(WaitValue) {} ur_exp_external_semaphore_handle_t getExternalSemaphore() const { + assert(MExternalSemaphore != nullptr && + "MExternalSemaphore has not been defined yet."); return MExternalSemaphore; } std::optional getWaitValue() const { return MWaitValue; } @@ -643,6 +645,10 @@ class CGSemaphoreSignal : public CG { MExternalSemaphore(ExternalSemaphore), MSignalValue(SignalValue) {} ur_exp_external_semaphore_handle_t getExternalSemaphore() const { + if (MExternalSemaphore == nullptr) + throw exception(make_error_code(errc::runtime), + "getExternalSemaphore(): MExternalSemaphore has not been " + "defined yet."); return MExternalSemaphore; } std::optional getSignalValue() const { return MSignalValue; } diff --git a/sycl/source/detail/handler_impl.hpp b/sycl/source/detail/handler_impl.hpp index a306d3c69b498..37a697a57bc2b 100644 --- a/sycl/source/detail/handler_impl.hpp +++ b/sycl/source/detail/handler_impl.hpp @@ -90,13 +90,13 @@ class handler_impl { std::shared_ptr MKernelBundle; - ur_usm_advice_flags_t MAdvice; + ur_usm_advice_flags_t MAdvice = 0; // 2D memory operation information. - size_t MSrcPitch; - size_t MDstPitch; - size_t MWidth; - size_t MHeight; + size_t MSrcPitch = 0; + size_t MDstPitch = 0; + size_t MWidth = 0; + size_t MHeight = 0; /// Offset into a device_global for copy operations. size_t MOffset = 0; @@ -134,7 +134,7 @@ class handler_impl { ur_rect_region_t MCopyExtent = {}; // Extra information for semaphore interoperability - ur_exp_external_semaphore_handle_t MExternalSemaphore; + ur_exp_external_semaphore_handle_t MExternalSemaphore = nullptr; std::optional MWaitValue; std::optional MSignalValue;