File: fix-range-loop-construct.patch

package info (click to toggle)
onnxruntime 1.23.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 340,744 kB
  • sloc: cpp: 3,222,135; python: 188,267; ansic: 114,318; asm: 37,927; cs: 36,849; java: 10,962; javascript: 6,811; pascal: 4,126; sh: 2,996; xml: 705; objc: 281; makefile: 67
file content (62 lines) | stat: -rw-r--r-- 2,579 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
From 8ebd0bf1cf02414584d15d7244b07fa97d65ba02 Mon Sep 17 00:00:00 2001
From: Changming Sun <chasun@microsoft.com>
Date: Mon, 29 Sep 2025 21:19:29 -0700
Subject: [PATCH] Fix(build): Correct maybe-uninitialized and
 range-loop-construct warnings (#26201)
Forwarded: not-needed
Origin: https://github.com/microsoft/onnxruntime/pull/26201

This pull request addresses two build warnings that were treated as
errors:

1.  **`maybe-uninitialized` warning in `nchwc_transformer.cc`**:
A `maybe-uninitialized` warning was triggered when accessing
`nchwc_inputs[0]` without checking if `nchwc_inputs` was empty. This
could lead to a crash if a binary node had no inputs. The fix adds a
check to ensure the vector is not empty before accessing the first
element.

2.  **`range-loop-construct` warnings in `transformer_memcpy.cc`**:
The compiler warned about creating copies of objects in range-based for
loops. This was resolved by using references (`const auto&`) instead of
copies (`const auto`) for the loop variables, which is more efficient.

This fix was provided by an AI bot.
---
 onnxruntime/core/optimizer/nchwc_transformer.cc  | 4 ++++
 onnxruntime/core/optimizer/transformer_memcpy.cc | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

--- a/onnxruntime/core/optimizer/nchwc_transformer.cc
+++ b/onnxruntime/core/optimizer/nchwc_transformer.cc
@@ -609,6 +609,10 @@
     nchwc_inputs.push_back(nchwc_input);
   }
 
+  if (nchwc_inputs.empty()) {
+    return;
+  }
+
   auto* nchwc_input_0 = nchwc_inputs[0];
   const int64_t channels = nchwc_inputs[0]->channels_;
 
--- a/onnxruntime/core/optimizer/transformer_memcpy.cc
+++ b/onnxruntime/core/optimizer/transformer_memcpy.cc
@@ -16,7 +16,7 @@
 static ProviderTypeToProviderMap GetProvidersByType(
     const InlinedVector<gsl::not_null<const IExecutionProvider*>>& providers) {
   ProviderTypeToProviderMap providers_by_type{};
-  for (const auto provider : providers) {
+  for (const auto& provider : providers) {
     providers_by_type.emplace(provider->Type(), provider);
   }
   return providers_by_type;
@@ -100,7 +100,7 @@
 // and mainly provides the subgraph recursion functionality
 Status MemcpyTransformer::ApplyImpl(Graph& graph, bool& modified, int graph_level,
                                     const logging::Logger& logger) const {
-  for (const auto provider : providers_) {
+  for (const auto& provider : providers_) {
     const auto& provider_type = provider->Type();
     if (!utils::ProviderIsCpuBased(*provider)) {
       TransformerMemcpyImpl copy_impl(graph, *provider, providers_by_type_);