From b4833bc39a2742e0ad2453e71fc22a9e6a6fa1a6 Mon Sep 17 00:00:00 2001 From: Sophie Mao Date: Fri, 16 Aug 2024 13:52:50 -0700 Subject: [PATCH 1/6] Fix Coverity `COPY_INSTEAD_OF_MOVE` errors Fixes: ``` lib/pkg_editor/test/pkg_editor_test.cpp:468:29: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:405:32: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:430:7: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:437:7: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:438:7: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:439:7: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:493:5: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:498:30: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:886:7: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:896:7: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:900:7: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:901:7: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_auto_configure.cpp:903:7: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_hal_mmd.cpp:2945:40: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_program.cpp:1375:5: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) src/acl_usm.cpp:170:9: Type: Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE) ``` --- include/acl_hal.h | 2 +- lib/pkg_editor/test/pkg_editor_test.cpp | 3 +- src/acl_auto_configure.cpp | 39 ++++++++++++------------- src/acl_hal_mmd.cpp | 4 +-- src/acl_program.cpp | 4 ++- test/acl_hal_test.cpp | 4 +-- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/acl_hal.h b/include/acl_hal.h index f929e92d..38d69edb 100644 --- a/include/acl_hal.h +++ b/include/acl_hal.h @@ -231,7 +231,7 @@ typedef struct { int (*close_devices)(cl_uint num_devices, const cl_device_id *devices); /// Allocates USM host memory - void *(*host_alloc)(const std::vector devices, size_t size, + void *(*host_alloc)(const std::vector &devices, size_t size, size_t alignment, mem_properties_t *properties, int *error); diff --git a/lib/pkg_editor/test/pkg_editor_test.cpp b/lib/pkg_editor/test/pkg_editor_test.cpp index 165f904d..c704e80e 100644 --- a/lib/pkg_editor/test/pkg_editor_test.cpp +++ b/lib/pkg_editor/test/pkg_editor_test.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "pkg_editor/pkg_editor.h" #include @@ -465,7 +466,7 @@ static bool is_same_tmpdir(const std::vector &files, const fs::path &unpack_dir) { return std::all_of(files.begin(), files.end(), [&](const fs::path &path) { fs::path unpacked_file_path = unpack_dir / path; - return files_same(path, unpacked_file_path); + return files_same(path, std::move(unpacked_file_path)); }); } diff --git a/src/acl_auto_configure.cpp b/src/acl_auto_configure.cpp index ec9da39d..be7c4ada 100644 --- a/src/acl_auto_configure.cpp +++ b/src/acl_auto_configure.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include // Internal headers. @@ -402,7 +403,7 @@ read_global_mem_defs(const std::string &config_str, counters.back() > 0) { std::string temp; result = read_string_counters(config_str, curr_pos, temp, counters); - can_access.push_back(temp); + can_access.push_back(std::move(temp)); } } @@ -427,16 +428,16 @@ read_global_mem_defs(const std::string &config_str, global_mem_defs[i].num_global_banks = num_dimms; global_mem_defs[i].config_addr = static_cast(configuration_address); - global_mem_defs[i].name = gmem_name; + global_mem_defs[i].name = std::move(gmem_name); global_mem_defs[i].range.begin = reinterpret_cast(gmem_start); global_mem_defs[i].range.next = reinterpret_cast(gmem_end); global_mem_defs[i].type = static_cast(gmem_type); global_mem_defs[i].burst_interleaved = burst_interleaved; global_mem_defs[i].allocation_type = allocation_type; - global_mem_defs[i].primary_interface = primary_interface; - global_mem_defs[i].can_access_list = can_access; - global_mem_defs[i].id = gmem_id; + global_mem_defs[i].primary_interface = std::move(primary_interface); + global_mem_defs[i].can_access_list = std::move(can_access); + global_mem_defs[i].id = std::move(gmem_id); } // forward compatibility: bypassing remaining fields at the end of global @@ -474,28 +475,24 @@ read_hostpipe_infos(const std::string &config_str, counters.emplace_back(total_fields_hostpipes); std::string name; - auto hostpipe_is_host_to_dev = 0U; - auto hostpipe_is_dev_to_host = 0U; + bool hostpipe_is_host_to_dev = false; + bool hostpipe_is_dev_to_host = false; auto hostpipe_width = 0U; auto hostpipe_max_buffer_depth = 0U; result = result && read_string_counters(config_str, curr_pos, name, counters) && - read_uint_counters(config_str, curr_pos, hostpipe_is_host_to_dev, + read_bool_counters(config_str, curr_pos, hostpipe_is_host_to_dev, counters) && - read_uint_counters(config_str, curr_pos, hostpipe_is_dev_to_host, + read_bool_counters(config_str, curr_pos, hostpipe_is_dev_to_host, counters) && read_uint_counters(config_str, curr_pos, hostpipe_width, counters) && read_uint_counters(config_str, curr_pos, hostpipe_max_buffer_depth, counters); // is_host_to_dev and is_dev_to_host are exclusive because of the enum // Type - acl_hostpipe_info_t acl_hostpipe_info; - acl_hostpipe_info.name = name; - acl_hostpipe_info.is_host_to_dev = hostpipe_is_host_to_dev; - acl_hostpipe_info.is_dev_to_host = hostpipe_is_dev_to_host; - acl_hostpipe_info.data_width = hostpipe_width; - acl_hostpipe_info.max_buffer_depth = hostpipe_max_buffer_depth; - hostpipe_infos.push_back(acl_hostpipe_info); + hostpipe_infos.push_back(acl_hostpipe_info_t{ + std::move(name), hostpipe_is_host_to_dev, hostpipe_is_dev_to_host, + hostpipe_width, hostpipe_max_buffer_depth}); /***************************************************************** Since the introduction of autodiscovery forwards-compatibility, @@ -883,7 +880,7 @@ static bool read_kernel_args(const std::string &config_str, ****************************************************************/ if (result) { - args[j].name = name; + args[j].name = std::move(name); args[j].addr_space = static_cast(addr_space_type); args[j].access_qualifier = @@ -893,14 +890,14 @@ static bool read_kernel_args(const std::string &config_str, args[j].alignment = alignment; args[j].aspace_number = aspace_id; args[j].lmem_size_bytes = lmem_size_bytes; - args[j].type_name = type_name; + args[j].type_name = std::move(type_name); args[j].type_qualifier = static_cast(type_qualifier); args[j].host_accessible = host_accessible; - args[j].pipe_channel_id = pipe_channel_id; - args[j].buffer_location = buffer_location; + args[j].pipe_channel_id = std::move(pipe_channel_id); + args[j].buffer_location = std::move(buffer_location); args[j].streaming_arg_info_available = streaming_arg_info_available; - args[j].streaming_arg_info = streaming_arg_info; + args[j].streaming_arg_info = std::move(streaming_arg_info); } // forward compatibility: bypassing remaining fields at the end of // arguments section diff --git a/src/acl_hal_mmd.cpp b/src/acl_hal_mmd.cpp index a96bffd2..039ba2af 100644 --- a/src/acl_hal_mmd.cpp +++ b/src/acl_hal_mmd.cpp @@ -63,7 +63,7 @@ void *acl_hal_mmd_shared_alloc(cl_device_id device, size_t size, size_t alignment, mem_properties_t *properties, int *error); -void *acl_hal_mmd_host_alloc(const std::vector devices, +void *acl_hal_mmd_host_alloc(const std::vector &devices, size_t size, size_t alignment, mem_properties_t *properties, int *error); int acl_hal_mmd_free(cl_context context, void *mem); @@ -3054,7 +3054,7 @@ void *acl_hal_mmd_shared_alloc(cl_device_id device, size_t size, return result; } -void *acl_hal_mmd_host_alloc(const std::vector devices, +void *acl_hal_mmd_host_alloc(const std::vector &devices, size_t size, size_t alignment, mem_properties_t *properties, int *error) { // Note we do not support devices in the same context with different MMDs diff --git a/src/acl_program.cpp b/src/acl_program.cpp index 11fbcf99..407ebd71 100644 --- a/src/acl_program.cpp +++ b/src/acl_program.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include // External library headers. @@ -1372,7 +1373,8 @@ l_register_hostpipes_to_program(acl_device_program_info_t *dev_prog, host_pipe_info.m_binded_kernel = NULL; host_pipe_info.size_buffered = 0; - dev_prog->program_hostpipe_map[hostpipe.logical_name] = host_pipe_info; + dev_prog->program_hostpipe_map[hostpipe.logical_name] = + std::move(host_pipe_info); } // Start from 2024.1, Runtime receives sideband signals information diff --git a/test/acl_hal_test.cpp b/test/acl_hal_test.cpp index ff922711..db0e7509 100644 --- a/test/acl_hal_test.cpp +++ b/test/acl_hal_test.cpp @@ -94,7 +94,7 @@ int acl_test_hal_close_devices(cl_uint num_devices, void *acl_test_hal_shared_alloc(cl_device_id device, size_t size, size_t alignment, mem_properties_t *properties, int *error); -void *acl_test_hal_host_alloc(const std::vector devices, +void *acl_test_hal_host_alloc(const std::vector &devices, size_t size, size_t alignment, mem_properties_t *properties, int *error); int acl_test_hal_free(cl_context context, void *ptr); @@ -652,7 +652,7 @@ void *acl_test_hal_shared_alloc(cl_device_id device, size_t size, return (void *)0xdeadbeefdeadbeef; } -void *acl_test_hal_host_alloc(const std::vector, size_t, size_t, +void *acl_test_hal_host_alloc(const std::vector &, size_t, size_t, mem_properties_t *, int *) { return (void *)0xdeadbeefdeadbeef; } From 82434958c5726cad66f7a412bc31b9d9a14df2a4 Mon Sep 17 00:00:00 2001 From: Sophie Mao Date: Tue, 20 Aug 2024 11:12:13 -0700 Subject: [PATCH 2/6] Fix Coverity `INVALIDATE_ITERATOR` errors Fixes: ``` test/acl_auto_configure_test.cpp:285:3: Type: Using invalid iterator (INVALIDATE_ITERATOR) test/acl_auto_configure_test.cpp:285:3: 124. deref_iterator: Dereferencing iterator "kernel15_dev_global" though it is already past the end of its container. test/acl_auto_configure_test.cpp:292:3: Type: Using invalid iterator (INVALIDATE_ITERATOR) test/acl_auto_configure_test.cpp:292:3: 136. deref_iterator: Dereferencing iterator "kernel15_dev_global2" though it is already past the end of its container. ``` --- .../test/acl_auto_configure_fuzz_test.cpp | 44 +++++++++++-------- test/acl_auto_configure_test.cpp | 44 +++++++++++-------- 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/fuzz_testing/test/acl_auto_configure_fuzz_test.cpp b/fuzz_testing/test/acl_auto_configure_fuzz_test.cpp index fe20a95f..a4aa5003 100644 --- a/fuzz_testing/test/acl_auto_configure_fuzz_test.cpp +++ b/fuzz_testing/test/acl_auto_configure_fuzz_test.cpp @@ -294,24 +294,32 @@ TEST(auto_configure, simple) { const auto kernel15_dev_global2 = m_device_def.autodiscovery_def.device_global_mem_defs.find( "kernel15_dev_global2"); - CHECK(kernel15_dev_global != - m_device_def.autodiscovery_def.device_global_mem_defs.end()); - CHECK(kernel15_dev_global2 != - m_device_def.autodiscovery_def.device_global_mem_defs.end()); - CHECK_EQUAL(4096, kernel15_dev_global->second.address); - CHECK_EQUAL(2048, kernel15_dev_global->second.size); - CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_NONE, - kernel15_dev_global->second.host_access); - CHECK_EQUAL(false, kernel15_dev_global->second.can_skip_programming); - CHECK_EQUAL(false, kernel15_dev_global->second.implement_in_csr); - CHECK_EQUAL(false, kernel15_dev_global->second.reset_on_reuse); - CHECK_EQUAL(2048, kernel15_dev_global2->second.address); - CHECK_EQUAL(1024, kernel15_dev_global2->second.size); - CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_WRITE_ONLY, - kernel15_dev_global2->second.host_access); - CHECK_EQUAL(false, kernel15_dev_global2->second.can_skip_programming); - CHECK_EQUAL(true, kernel15_dev_global2->second.implement_in_csr); - CHECK_EQUAL(false, kernel15_dev_global2->second.reset_on_reuse); + bool kernel15_dev_global_found = + kernel15_dev_global != + m_device_def.autodiscovery_def.device_global_mem_defs.end(); + bool kernel15_dev_global2_found = + kernel15_dev_global2 != + m_device_def.autodiscovery_def.device_global_mem_defs.end(); + CHECK(kernel15_dev_global_found); + CHECK(kernel15_dev_global2_found); + if (kernel15_dev_global_found) { + CHECK_EQUAL(4096, kernel15_dev_global->second.address); + CHECK_EQUAL(2048, kernel15_dev_global->second.size); + CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_NONE, + kernel15_dev_global->second.host_access); + CHECK_EQUAL(false, kernel15_dev_global->second.can_skip_programming); + CHECK_EQUAL(false, kernel15_dev_global->second.implement_in_csr); + CHECK_EQUAL(false, kernel15_dev_global->second.reset_on_reuse); + } + if (kernel15_dev_global2_found) { + CHECK_EQUAL(2048, kernel15_dev_global2->second.address); + CHECK_EQUAL(1024, kernel15_dev_global2->second.size); + CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_WRITE_ONLY, + kernel15_dev_global2->second.host_access); + CHECK_EQUAL(false, kernel15_dev_global2->second.can_skip_programming); + CHECK_EQUAL(true, kernel15_dev_global2->second.implement_in_csr); + CHECK_EQUAL(false, kernel15_dev_global2->second.reset_on_reuse); + } // Check a second parsing. // It should allocate a new string for the name. diff --git a/test/acl_auto_configure_test.cpp b/test/acl_auto_configure_test.cpp index ed826981..6579f5b2 100644 --- a/test/acl_auto_configure_test.cpp +++ b/test/acl_auto_configure_test.cpp @@ -278,24 +278,32 @@ TEST(auto_configure, simple) { const auto kernel15_dev_global2 = m_device_def.autodiscovery_def.device_global_mem_defs.find( "kernel15_dev_global2"); - CHECK(kernel15_dev_global != - m_device_def.autodiscovery_def.device_global_mem_defs.end()); - CHECK(kernel15_dev_global2 != - m_device_def.autodiscovery_def.device_global_mem_defs.end()); - CHECK_EQUAL(4096, kernel15_dev_global->second.address); - CHECK_EQUAL(2048, kernel15_dev_global->second.size); - CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_NONE, - kernel15_dev_global->second.host_access); - CHECK_EQUAL(false, kernel15_dev_global->second.can_skip_programming); - CHECK_EQUAL(false, kernel15_dev_global->second.implement_in_csr); - CHECK_EQUAL(false, kernel15_dev_global->second.reset_on_reuse); - CHECK_EQUAL(2048, kernel15_dev_global2->second.address); - CHECK_EQUAL(1024, kernel15_dev_global2->second.size); - CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_WRITE_ONLY, - kernel15_dev_global2->second.host_access); - CHECK_EQUAL(false, kernel15_dev_global2->second.can_skip_programming); - CHECK_EQUAL(true, kernel15_dev_global2->second.implement_in_csr); - CHECK_EQUAL(false, kernel15_dev_global2->second.reset_on_reuse); + bool kernel15_dev_global_found = + kernel15_dev_global != + m_device_def.autodiscovery_def.device_global_mem_defs.end(); + bool kernel15_dev_global2_found = + kernel15_dev_global2 != + m_device_def.autodiscovery_def.device_global_mem_defs.end(); + CHECK(kernel15_dev_global_found); + CHECK(kernel15_dev_global2_found); + if (kernel15_dev_global_found) { + CHECK_EQUAL(4096, kernel15_dev_global->second.address); + CHECK_EQUAL(2048, kernel15_dev_global->second.size); + CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_NONE, + kernel15_dev_global->second.host_access); + CHECK_EQUAL(false, kernel15_dev_global->second.can_skip_programming); + CHECK_EQUAL(false, kernel15_dev_global->second.implement_in_csr); + CHECK_EQUAL(false, kernel15_dev_global->second.reset_on_reuse); + } + if (kernel15_dev_global2_found) { + CHECK_EQUAL(2048, kernel15_dev_global2->second.address); + CHECK_EQUAL(1024, kernel15_dev_global2->second.size); + CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_WRITE_ONLY, + kernel15_dev_global2->second.host_access); + CHECK_EQUAL(false, kernel15_dev_global2->second.can_skip_programming); + CHECK_EQUAL(true, kernel15_dev_global2->second.implement_in_csr); + CHECK_EQUAL(false, kernel15_dev_global2->second.reset_on_reuse); + } // Check a second parsing. // It should allocate a new string for the name. From d0b1826e138a84ce60ac7da3a7398556135db67e Mon Sep 17 00:00:00 2001 From: Sophie Mao Date: Tue, 20 Aug 2024 11:15:28 -0700 Subject: [PATCH 3/6] Fix Coverity `RESOURCE_LEAK` error Fixes: ``` lib/pkg_editor/src/pkg_editor.c:1486:5: Type: Resource leak (RESOURCE_LEAK) lib/pkg_editor/src/pkg_editor.c:1468:3: 1. path: Condition "of == NULL", taking false branch. lib/pkg_editor/src/pkg_editor.c:1480:3: 2. alloc_arg: "deflateInit_" allocates memory that is stored into "z_info.strm.state". lib/pkg_editor/src/pkg_editor.c:1482:3: 3. path: Condition "ret != 0", taking true branch. lib/pkg_editor/src/pkg_editor.c:1486:5: 4. leaked_storage: Variable "z_info" going out of scope leaks the storage "z_info.strm.state" points to. ``` --- lib/pkg_editor/src/pkg_editor.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pkg_editor/src/pkg_editor.c b/lib/pkg_editor/src/pkg_editor.c index 8c7402cd..f3a9bbf9 100644 --- a/lib/pkg_editor/src/pkg_editor.c +++ b/lib/pkg_editor/src/pkg_editor.c @@ -1483,6 +1483,7 @@ int acl_pkg_pack(const char *out_file, const char **input_files_dirs) { fprintf(stderr, "acl_pkg_pack: Unable to initialize zlib for writing %s\n", out_file); fclose(of); + deflateEnd(&z_info.strm); return 0; } From 3849a09cb8385525d793ccd6d65425d06dbd7a77 Mon Sep 17 00:00:00 2001 From: Sophie Mao Date: Tue, 20 Aug 2024 11:16:55 -0700 Subject: [PATCH 4/6] Fix Coverity `LOCK_EVASION` error Fixes: ``` lib/acl_threadsupport/test/acl_threadsupport_test.cpp:111:5: Type: Check of thread-shared field evades lock acquisition (LOCK_EVASION) lib/acl_threadsupport/test/acl_threadsupport_test.cpp:106:9: 1. thread1_checks_field: Thread1 uses the value read from static field "threadtest_state" in the condition "threadtest_state == 2". It sees that the condition is false. Control is switched to Thread2. lib/acl_threadsupport/test/acl_threadsupport_test.cpp:106:9: 2. thread2_checks_field: Thread2 uses the value read from static field "threadtest_state" in the condition "threadtest_state == 2". It sees that the condition is false. lib/acl_threadsupport/test/acl_threadsupport_test.cpp:110:5: 3. thread2_acquires_lock: Thread2 acquires lock "mymutex". lib/acl_threadsupport/src/acl_threadsupport.c:100:42: 3.1. lock: "pthread_mutex_lock" locks "mutex". lib/acl_threadsupport/test/acl_threadsupport_test.cpp:111:5: 4. thread2_modifies_field: Thread2 sets "threadtest_state" to a new value. Note that this write can be reordered at runtime to occur before instructions that do not access this field within this locked region. After Thread2 leaves the critical section, control is switched back to Thread1. lib/acl_threadsupport/test/acl_threadsupport_test.cpp:110:5: 5. thread1_acquires_lock: Thread1 acquires lock "mymutex". lib/acl_threadsupport/src/acl_threadsupport.c:100:42: 5.1. lock: "pthread_mutex_lock" locks "mutex". lib/acl_threadsupport/test/acl_threadsupport_test.cpp:111:5: 6. thread1_overwrites_value_in_field: Thread1 sets "threadtest_state" to a new value. Now the two threads have an inconsistent view of "threadtest_state" and updates to fields correlated with "threadtest_state" may be lost. lib/acl_threadsupport/test/acl_threadsupport_test.cpp:106:9: 7. use_same_locks_for_read_and_modify: Guard the modification of "threadtest_state" and the read used to decide whether to modify "threadtest_state" with the same set of locks. ``` --- lib/acl_threadsupport/test/acl_threadsupport_test.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/acl_threadsupport/test/acl_threadsupport_test.cpp b/lib/acl_threadsupport/test/acl_threadsupport_test.cpp index 04fc75b7..01f5d6a8 100644 --- a/lib/acl_threadsupport/test/acl_threadsupport_test.cpp +++ b/lib/acl_threadsupport/test/acl_threadsupport_test.cpp @@ -103,7 +103,10 @@ void *test_thread(void *) { break; acl_thread_yield(); } - if (threadtest_state == END_STATE) { + acl_mutex_lock(&mymutex); + const bool is_end_state = (threadtest_state == END_STATE); + acl_mutex_unlock(&mymutex); + if (is_end_state) { return 0; } // CLIENT_STATE From f21119b56c56ab5edf8eac19950286026cdc8b22 Mon Sep 17 00:00:00 2001 From: Sophie Mao Date: Tue, 20 Aug 2024 14:08:49 -0700 Subject: [PATCH 5/6] Fix Coverity `RULE_OF_ZERO_THREE_FIVE` errors Fixes: ``` include/acl_thread.h:121:7: Type: Rule of three (RULE_OF_ZERO_THREE_FIVE) include/acl_thread.h:121:7: rule_of_three_violation: Class "acl_suspend_lock_guard" has a user definition for at least one special function (copy constructor, copy assignment, destructor) but not all. If one of these functions requires a user definition then the others likely do as well. include/acl_thread.h:121:7: remediation: Add user-definition for a copy constructor. include/acl_thread.h:121:7: remediation: Add user-definition for a copy assignment operator. include/acl_thread.h:126:3: destructor: User-defined destructor. include/acl_types.h:362:7: Type: Rule of three (RULE_OF_ZERO_THREE_FIVE) include/acl_types.h:362:7: rule_of_three_violation: Class "acl_device_program_info_t" has a user definition for at least one special function (copy constructor, copy assignment, destructor) but not all. If one of these functions requires a user definition then the others likely do as well. include/acl_types.h:362:7: remediation: Add user-definition for a copy constructor. include/acl_types.h:362:7: remediation: Add user-definition for a copy assignment operator. src/acl_device_program_info.cpp:29:28: destructor: User-defined destructor. ``` --- include/acl_thread.h | 4 ++++ include/acl_types.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/include/acl_thread.h b/include/acl_thread.h index 5abc47a2..ac068a36 100644 --- a/include/acl_thread.h +++ b/include/acl_thread.h @@ -125,6 +125,10 @@ class acl_suspend_lock_guard { }; ~acl_suspend_lock_guard() { mutex.resume_lock(lock_count); } + // Delete copy constructor and copy assignment + acl_suspend_lock_guard(const acl_suspend_lock_guard &) = delete; + acl_suspend_lock_guard &operator=(const acl_suspend_lock_guard &) = delete; + private: int lock_count; acl_mutex_wrapper_t &mutex; diff --git a/include/acl_types.h b/include/acl_types.h index 66a0d826..494027cc 100644 --- a/include/acl_types.h +++ b/include/acl_types.h @@ -365,6 +365,11 @@ class acl_device_program_info_t { ~acl_device_program_info_t(); + // Delete copy constructor and copy assignment + acl_device_program_info_t(const acl_device_program_info_t &) = delete; + acl_device_program_info_t & + operator=(const acl_device_program_info_t &) = delete; + cl_program program = nullptr; // Back pointer. cl_device_id device = nullptr; // For what device? Shortcut only. From 69ec4147542c0a9fa29880133dd4c782aeb8a367 Mon Sep 17 00:00:00 2001 From: Sophie Mao Date: Tue, 20 Aug 2024 14:23:19 -0700 Subject: [PATCH 6/6] Fix Coverity `RULE_OF_ZERO_THREE_FIVE` issue This also aligns with CppUTest change https://github.com/cpputest/cpputest/commit/37735ccb7e19a3ffb6d4bbb98ed4d0de36b059f2 Fixes: ``` lib/CppUTest/include/CppUTest/Failure.h:72:7: Type: Rule of three (RULE_OF_ZERO_THREE_FIVE) lib/CppUTest/include/CppUTest/Failure.h:72:7: rule_of_three_violation: Class "EqualsFailure" has a user definition for at least one special function (copy constructor, copy assignment, destructor) but not all. If one of these functions requires a user definition then the others likely do as well. lib/CppUTest/include/CppUTest/Failure.h:80:2: copy_ctor: User-defined copy constructor. lib/CppUTest/include/CppUTest/Failure.h:81:17: copy_assign: User-defined copy assignment operator. lib/CppUTest/include/CppUTest/Failure.h:72:7: remediation: Add user-definition for a destructor. ``` --- lib/CppUTest/include/CppUTest/Failure.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/CppUTest/include/CppUTest/Failure.h b/lib/CppUTest/include/CppUTest/Failure.h index 759a4342..e23cff45 100644 --- a/lib/CppUTest/include/CppUTest/Failure.h +++ b/lib/CppUTest/include/CppUTest/Failure.h @@ -75,10 +75,6 @@ class EqualsFailure: public Failure EqualsFailure(Utest*, const char* fileName, long lineNumber, const SimpleString& expected, const SimpleString& actual); - -private: - EqualsFailure(const EqualsFailure&); - EqualsFailure& operator=(const EqualsFailure&); }; class ContainsFailure: public Failure @@ -87,10 +83,6 @@ class ContainsFailure: public Failure ContainsFailure(Utest*, const char* fileName, long lineNumber, const SimpleString& expected, const SimpleString& actual); - -private: - ContainsFailure(const ContainsFailure&); - ContainsFailure& operator=(const ContainsFailure&); }; #endif