* [PATCH] Mode-Switching: Fix local array maybe uninitialized warning
@ 2023-05-19 23:56 pan2.li
2023-05-20 4:23 ` Jeff Law
0 siblings, 1 reply; 3+ messages in thread
From: pan2.li @ 2023-05-19 23:56 UTC (permalink / raw)
To: gcc-patches; +Cc: juzhe.zhong, kito.cheng, pan2.li, yanzhang.wang, jeffreyalaw
From: Pan Li <pan2.li@intel.com>
There are 2 local array in function optimize_mode_switching. It will be
initialized conditionally at the beginning but then always consumed in
another loop. It may trigger the warning maybe-uninitialized, and may
result in build failure when enable werror, aka warning as error.
This patch will initialize the local array to zero explictly when
declaration.
Signed-off-by: Pan Li <pan2.li@intel.com>
gcc/ChangeLog:
* mode-switching.cc (entity_map): Initialize the array to zero.
(bb_info): Ditto.
---
gcc/mode-switching.cc | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/gcc/mode-switching.cc b/gcc/mode-switching.cc
index 2d2818f5674..64ae2bc29c3 100644
--- a/gcc/mode-switching.cc
+++ b/gcc/mode-switching.cc
@@ -499,8 +499,8 @@ optimize_mode_switching (void)
bool need_commit = false;
static const int num_modes[] = NUM_MODES_FOR_MODE_SWITCHING;
#define N_ENTITIES ARRAY_SIZE (num_modes)
- int entity_map[N_ENTITIES];
- struct bb_info *bb_info[N_ENTITIES];
+ int entity_map[N_ENTITIES] = {};
+ struct bb_info *bb_info[N_ENTITIES] = {};
int i, j;
int n_entities = 0;
int max_num_modes = 0;
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Mode-Switching: Fix local array maybe uninitialized warning
2023-05-19 23:56 [PATCH] Mode-Switching: Fix local array maybe uninitialized warning pan2.li
@ 2023-05-20 4:23 ` Jeff Law
2023-05-20 9:59 ` Li, Pan2
0 siblings, 1 reply; 3+ messages in thread
From: Jeff Law @ 2023-05-20 4:23 UTC (permalink / raw)
To: pan2.li, gcc-patches; +Cc: juzhe.zhong, kito.cheng, yanzhang.wang
On 5/19/23 17:56, pan2.li@intel.com wrote:
> From: Pan Li <pan2.li@intel.com>
>
> There are 2 local array in function optimize_mode_switching. It will be
> initialized conditionally at the beginning but then always consumed in
> another loop. It may trigger the warning maybe-uninitialized, and may
> result in build failure when enable werror, aka warning as error.
>
> This patch will initialize the local array to zero explictly when
> declaration.
>
> Signed-off-by: Pan Li <pan2.li@intel.com>
>
> gcc/ChangeLog:
>
> * mode-switching.cc (entity_map): Initialize the array to zero.
> (bb_info): Ditto.
OK.
jeff
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] Mode-Switching: Fix local array maybe uninitialized warning
2023-05-20 4:23 ` Jeff Law
@ 2023-05-20 9:59 ` Li, Pan2
0 siblings, 0 replies; 3+ messages in thread
From: Li, Pan2 @ 2023-05-20 9:59 UTC (permalink / raw)
To: Jeff Law, gcc-patches; +Cc: juzhe.zhong, kito.cheng, Wang, Yanzhang
Committed, thanks Jeff.
Pan
-----Original Message-----
From: Jeff Law <jeffreyalaw@gmail.com>
Sent: Saturday, May 20, 2023 12:24 PM
To: Li, Pan2 <pan2.li@intel.com>; gcc-patches@gcc.gnu.org
Cc: juzhe.zhong@rivai.ai; kito.cheng@sifive.com; Wang, Yanzhang <yanzhang.wang@intel.com>
Subject: Re: [PATCH] Mode-Switching: Fix local array maybe uninitialized warning
On 5/19/23 17:56, pan2.li@intel.com wrote:
> From: Pan Li <pan2.li@intel.com>
>
> There are 2 local array in function optimize_mode_switching. It will
> be initialized conditionally at the beginning but then always consumed
> in another loop. It may trigger the warning maybe-uninitialized, and
> may result in build failure when enable werror, aka warning as error.
>
> This patch will initialize the local array to zero explictly when
> declaration.
>
> Signed-off-by: Pan Li <pan2.li@intel.com>
>
> gcc/ChangeLog:
>
> * mode-switching.cc (entity_map): Initialize the array to zero.
> (bb_info): Ditto.
OK.
jeff
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-20 9:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-19 23:56 [PATCH] Mode-Switching: Fix local array maybe uninitialized warning pan2.li
2023-05-20 4:23 ` Jeff Law
2023-05-20 9:59 ` Li, Pan2
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).