Skip to content

Commit 178a42c

Browse files
authored
[SYCL] Initialize uninitialized handler_impl fields (#15323)
In the same vein as #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.
1 parent fbb1fb0 commit 178a42c

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

sycl/source/detail/cg.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ class CGSemaphoreWait : public CG {
624624
MExternalSemaphore(ExternalSemaphore), MWaitValue(WaitValue) {}
625625

626626
ur_exp_external_semaphore_handle_t getExternalSemaphore() const {
627+
assert(MExternalSemaphore != nullptr &&
628+
"MExternalSemaphore has not been defined yet.");
627629
return MExternalSemaphore;
628630
}
629631
std::optional<uint64_t> getWaitValue() const { return MWaitValue; }
@@ -643,6 +645,10 @@ class CGSemaphoreSignal : public CG {
643645
MExternalSemaphore(ExternalSemaphore), MSignalValue(SignalValue) {}
644646

645647
ur_exp_external_semaphore_handle_t getExternalSemaphore() const {
648+
if (MExternalSemaphore == nullptr)
649+
throw exception(make_error_code(errc::runtime),
650+
"getExternalSemaphore(): MExternalSemaphore has not been "
651+
"defined yet.");
646652
return MExternalSemaphore;
647653
}
648654
std::optional<uint64_t> getSignalValue() const { return MSignalValue; }

sycl/source/detail/handler_impl.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ class handler_impl {
9090

9191
std::shared_ptr<detail::kernel_bundle_impl> MKernelBundle;
9292

93-
ur_usm_advice_flags_t MAdvice;
93+
ur_usm_advice_flags_t MAdvice = 0;
9494

9595
// 2D memory operation information.
96-
size_t MSrcPitch;
97-
size_t MDstPitch;
98-
size_t MWidth;
99-
size_t MHeight;
96+
size_t MSrcPitch = 0;
97+
size_t MDstPitch = 0;
98+
size_t MWidth = 0;
99+
size_t MHeight = 0;
100100

101101
/// Offset into a device_global for copy operations.
102102
size_t MOffset = 0;
@@ -134,7 +134,7 @@ class handler_impl {
134134
ur_rect_region_t MCopyExtent = {};
135135

136136
// Extra information for semaphore interoperability
137-
ur_exp_external_semaphore_handle_t MExternalSemaphore;
137+
ur_exp_external_semaphore_handle_t MExternalSemaphore = nullptr;
138138
std::optional<uint64_t> MWaitValue;
139139
std::optional<uint64_t> MSignalValue;
140140

0 commit comments

Comments
 (0)