Skip to content

Commit fa0b0bd

Browse files
ianaylAlexeySachkov
authored andcommitted
[SYCL] Fix uninitialized fields Coverity hits (intel#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 92b9951 commit fa0b0bd

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
@@ -300,7 +300,9 @@ class queue_impl {
300300
MIsInorder(has_property<property::queue::in_order>()),
301301
MDiscardEvents(
302302
has_property<ext::oneapi::property::queue::discard_events>()),
303-
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()) {
303+
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
304+
MQueueID{
305+
MNextAvailableQueueID.fetch_add(1, std::memory_order_relaxed)} {
304306
queue_impl_interop(UrQueue);
305307
}
306308

sycl/source/detail/scheduler/commands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,9 +998,9 @@ const char *Command::getBlockReason() const {
998998
return "A Buffer is locked by the host accessor";
999999
case BlockReason::HostTask:
10001000
return "Blocked by host task";
1001+
default:
1002+
return "Unknown block reason";
10011003
}
1002-
1003-
return "Unknown block reason";
10041004
}
10051005

10061006
void Command::copySubmissionCodeLocation() {

sycl/source/detail/scheduler/commands.hpp

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

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

338338
// Only have reasonable value while MIsBlockable is true
339-
BlockReason MBlockReason;
339+
BlockReason MBlockReason = BlockReason::Unset;
340340

341341
/// Describes the status of the command.
342342
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
@@ -350,7 +350,7 @@ class SYCLMemObjT : public SYCLMemObjI {
350350
// Indicates if memory object should write memory to the host on destruction.
351351
bool MNeedWriteBack;
352352
// Size of memory.
353-
size_t MSizeInBytes;
353+
size_t MSizeInBytes = 0;
354354
// User's pointer passed to constructor.
355355
void *MUserPtr;
356356
// Copy of memory passed by user to constructor.

0 commit comments

Comments
 (0)