Skip to content

Commit 0546dc1

Browse files
authored
[SYCL] Fix uninitialized fields Coverity hits (#15237)
This PR fixes Coverity hits regarding uninitialized class fields in the runtime. I'd like to bring attention to `sycl_mem_obj_t.hpp` however: There, I have initialized `MSizeInBytes` of the `SYCLMemObjT` class to 0: This should not cause any problems (at least not more), as currently all subclasses of `SYCLMemObjT` that actually use the `MSizeInBytes` have it defined (`buffer_impl`, `image_impl`) when their respective constructors are called. However, this does mean programmers must remember to initialize `MSizeInBytes` when using `image_impl`. To avoid this, I could rewrite some of the constructors in e.g. `image_impl` and `SYCLMemObjT`, but I'd like to not overcomplicate the problem here. So I was hoping for some other opinions: Is initializing as 0 sufficient, or should I go ahead and make the changes to the constructors anyway to be safe? Thanks in advance!
1 parent 0a2e5e3 commit 0546dc1

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

sycl/source/detail/event_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class event_impl {
390390
// If this event represents a submission to a
391391
// ur_exp_command_buffer_sync_point_t the sync point for that submission is
392392
// stored here.
393-
ur_exp_command_buffer_sync_point_t MSyncPoint;
393+
ur_exp_command_buffer_sync_point_t MSyncPoint = 0;
394394

395395
// If this event represents a submission to a
396396
// ur_exp_command_buffer_command_handle_t the command-buffer command

sycl/source/detail/queue_impl.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ class queue_impl {
239239
MIsInorder(has_property<property::queue::in_order>()),
240240
MDiscardEvents(
241241
has_property<ext::oneapi::property::queue::discard_events>()),
242-
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()) {
242+
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
243+
MQueueID{
244+
MNextAvailableQueueID.fetch_add(1, std::memory_order_relaxed)} {
243245
queue_impl_interop(UrQueue);
244246
}
245247

sycl/source/detail/scheduler/commands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,9 @@ const char *Command::getBlockReason() const {
994994
return "A Buffer is locked by the host accessor";
995995
case BlockReason::HostTask:
996996
return "Blocked by host task";
997+
default:
998+
return "Unknown block reason";
997999
}
998-
999-
return "Unknown block reason";
10001000
}
10011001

10021002
void Command::copySubmissionCodeLocation() {

sycl/source/detail/scheduler/commands.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ class Command {
321321
/// Used for marking the node during graph traversal.
322322
Marks MMarks;
323323

324-
enum class BlockReason : int { HostAccessor = 0, HostTask };
324+
enum class BlockReason : int { Unset = -1, HostAccessor = 0, HostTask };
325325

326326
// Only have reasonable value while MIsBlockable is true
327-
BlockReason MBlockReason;
327+
BlockReason MBlockReason = BlockReason::Unset;
328328

329329
/// Describes the status of the command.
330330
std::atomic<EnqueueResultT::ResultT> MEnqueueStatus;

sycl/source/detail/sycl_mem_obj_t.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class SYCLMemObjT : public SYCLMemObjI {
353353
// Indicates if memory object should write memory to the host on destruction.
354354
bool MNeedWriteBack;
355355
// Size of memory.
356-
size_t MSizeInBytes;
356+
size_t MSizeInBytes = 0;
357357
// User's pointer passed to constructor.
358358
void *MUserPtr;
359359
// Copy of memory passed by user to constructor.

0 commit comments

Comments
 (0)