Skip to content

Commit c816a2e

Browse files
authored
[Snippets][Coverity] Fixed 139702 and 140933 (#25230)
### Details: - *Fixed coverity issues: `Null pointer dereferences` and `Performance inefficiencies`* ### Tickets: - *140933* - *139702*
1 parent ac2f7ef commit c816a2e

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/common/snippets/include/snippets/lowered/loop_manager.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class LoopManager {
102102
bool set_default_handlers = true,
103103
bool is_work_amount_const = false) {
104104
const auto normalized_increment = utils::is_dynamic_value(work_amount) || work_amount == 0 ? increment : std::min(increment, work_amount);
105-
const auto handlers = set_default_handlers
105+
const auto& handlers = set_default_handlers
106106
? SpecificIterationHandlers(work_amount, normalized_increment)
107107
: SpecificIterationHandlers();
108108
const auto loop_info = std::make_shared<UnifiedLoopInfo>(work_amount, normalized_increment, entries, exits, handlers, is_work_amount_const);

src/common/snippets/src/lowered/loop_manager.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ std::pair<LinearIR::constExprIt, LinearIR::constExprIt> LoopManager::get_loop_bo
123123
}
124124

125125
LoopPort LoopManager::get_loop_port_by_expr_port(const ExpressionPort& expr_port, const size_t loop_id) {
126-
auto get_loop_port = [&](const std::vector<LoopPort>& ports) {
126+
auto get_loop_port = [&](const std::vector<LoopPort>& ports) -> const LoopPort& {
127127
auto it = std::find_if(ports.cbegin(), ports.cend(), [&](const LoopPort& p) { return *p.expr_port == expr_port; });
128128
if (it == ports.cend())
129129
OPENVINO_THROW("Expression has not been found among loop ports. Loop id: " + std::to_string(loop_id));
@@ -272,7 +272,7 @@ void LoopManager::fuse_loops(LinearIR::constExprIt loop_begin_target, LinearIR::
272272
auto input_ports_upper = loop_info_upper->get_input_ports();
273273
auto output_ports_upper = loop_info_upper->get_output_ports();
274274
auto input_ports_lower = loop_info_lower->get_input_ports();
275-
auto output_ports_lower = loop_info_lower->get_output_ports();
275+
const auto& output_ports_lower = loop_info_lower->get_output_ports();
276276
fuse_loop_ports(output_ports_upper, input_ports_lower, loop_id_upper);
277277

278278
const auto& from = fuse_into_upper ? loop_id_lower : loop_id_upper;
@@ -285,9 +285,9 @@ void LoopManager::fuse_loops(LinearIR::constExprIt loop_begin_target, LinearIR::
285285
const auto handlers = SpecificIterationHandlers::merge_handlers(loop_info_upper->get_handlers(), loop_info_lower->get_handlers());
286286
const auto is_work_amount_const = loop_info_upper->is_work_amount_const() || loop_info_lower->is_work_amount_const();
287287

288-
auto new_entries = input_ports_upper;
288+
auto new_entries = std::move(input_ports_upper);
289289
new_entries.insert(new_entries.end(), input_ports_lower.begin(), input_ports_lower.end());
290-
auto new_exits = output_ports_upper;
290+
auto new_exits = std::move(output_ports_upper);
291291
new_exits.insert(new_exits.end(), output_ports_lower.begin(), output_ports_lower.end());
292292

293293
m_map[to] = std::make_shared<UnifiedLoopInfo>(work_amount, increment, new_entries, new_exits, handlers, is_work_amount_const);

src/common/snippets/src/lowered/pass/validate_expanded_loops.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ void ValidateExpandedLoops::validate_loop_information(const LinearIR& linear_ir)
5252
const auto& expanded_loop_info = ov::as_type_ptr<ExpandedLoopInfo>(p.second);
5353
INFORMATIVE_ASSERT(expanded_loop_info, "expects only ExpandedLoopInfo in LoopManager");
5454

55-
if (expanded_loop_info->get_unified_loop_info() != current_unified_loop_info) {
55+
const auto& unified_loop_info = expanded_loop_info->get_unified_loop_info();
56+
INFORMATIVE_ASSERT(unified_loop_info, "expects non nullptr UnifiedLoopInfo in ExpandedLoopInfo");
57+
58+
if (unified_loop_info != current_unified_loop_info) {
5659
// If there is `current_unified_loop_info` - the previos loop is finished and need to validate total information
5760
if (current_unified_loop_info) {
5861
INFORMATIVE_ASSERT(current_work_amount == current_unified_loop_info->get_work_amount(),
@@ -61,7 +64,7 @@ void ValidateExpandedLoops::validate_loop_information(const LinearIR& linear_ir)
6164
"total finalization offsets are not equal to finalization offsets of undefined loop");
6265
}
6366

64-
current_unified_loop_info = expanded_loop_info->get_unified_loop_info();
67+
current_unified_loop_info = unified_loop_info;
6568

6669
INFORMATIVE_ASSERT(current_unified_loop_info->get_input_count() == expanded_loop_info->get_input_count() &&
6770
current_unified_loop_info->get_output_count() == expanded_loop_info->get_output_count(),
@@ -74,6 +77,7 @@ void ValidateExpandedLoops::validate_loop_information(const LinearIR& linear_ir)
7477
}
7578

7679
current_work_amount = utils::dynamic_safe_add(current_work_amount, expanded_loop_info->get_work_amount());
80+
INFORMATIVE_ASSERT(current_unified_loop_info, "expects non nullptr current UnifiedLoopInfo");
7781
INFORMATIVE_ASSERT(current_unified_loop_info->get_ptr_increments() == expanded_loop_info->get_ptr_increments(),
7882
"incompatible pointer increments with UnifiedLoopInfo");
7983

0 commit comments

Comments
 (0)