Skip to content

Commit f8e3a83

Browse files
haoxian2pcolberg
authored andcommitted
acl_usm: Fix coverity issue Type: AUTO_CAUSES_COPY
Error caused because auto in for-each loop copies the iterator object from the array/list. Adding & to reference the original element. Adding const so the code don't mistakenly modify the object.
1 parent cd2164e commit f8e3a83

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/acl_usm.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
8686
// lot, this guarantees that the alignment will work for all devices. If the
8787
// min alignment of one device is greater that the max alignment of another,
8888
// an error will be generated during allocation.
89-
for (const auto dev : devices) {
89+
for (const auto &dev : devices) {
9090
alignment = std::max<cl_uint>(alignment,
9191
(cl_uint)dev->def.min_host_mem_alignment);
9292
same_device &= dev->def.autodiscovery_def.name ==
@@ -119,7 +119,7 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
119119
properties += 2;
120120
}
121121

122-
for (const auto dev : devices) {
122+
for (const auto &dev : devices) {
123123
if (!acl_usm_has_access_capability(dev,
124124
CL_DEVICE_HOST_MEM_CAPABILITIES_INTEL)) {
125125
BAIL_INFO(
@@ -355,7 +355,7 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
355355
devices = std::vector<cl_device_id>(context->device,
356356
context->device + context->num_devices);
357357
}
358-
for (const auto dev : devices) {
358+
for (const auto &dev : devices) {
359359
if (!acl_usm_has_access_capability(
360360
dev, CL_DEVICE_SINGLE_DEVICE_SHARED_MEM_CAPABILITIES_INTEL)) {
361361
BAIL_INFO(
@@ -1202,7 +1202,7 @@ void l_cl_mem_blocking_free(cl_context context, void *ptr) {
12021202
for (int i = 0; i < num_command_queues; i++) {
12031203
cl_command_queue current_cq = context->command_queue[i];
12041204
// check events in commands
1205-
for (auto event : current_cq->commands) {
1205+
for (const auto &event : current_cq->commands) {
12061206
if (event->execution_status != CL_COMPLETE) {
12071207
// check if ptr is used by kernels when we submit to queue
12081208
if (event->ptr_hashtable.find(ptr) != event->ptr_hashtable.end()) {
@@ -1223,7 +1223,7 @@ void l_cl_mem_blocking_free(cl_context context, void *ptr) {
12231223
}
12241224
}
12251225
// check events in inorder commands
1226-
for (auto event : current_cq->inorder_commands) {
1226+
for (const auto &event : current_cq->inorder_commands) {
12271227
if (event->execution_status != CL_COMPLETE) {
12281228
// check if ptr is used by kernels when we submit to queue
12291229
if (event->ptr_hashtable.find(ptr) != event->ptr_hashtable.end()) {

0 commit comments

Comments
 (0)