[04/40] cpu/cris: Initialize some variables on CRIS CPU

Message ID 65223c79fdfd7faf132275415cd9da9852c5bec3.1666257885.git.research_trasio@irq.a4lg.com
State Accepted
Headers
Series sim+gdb: Suppress warnings if built with Clang (big batch 1) |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Tsukasa OI Oct. 20, 2022, 9:25 a.m. UTC
  GCC / Clang generate a warning if a variable may be used uninitialized on
some cases (Clang: "-Wsometimes-uninitialized").  When the program is being
built by Clang with the default configuration, it causes a build failure
(unless "--disable-werror" is specified).

Those error occur on sim/cris/semcrisv{10,32}f-switch.c but they are
CGEN-generated files.  The real cause of this problem is in cpu/cris.cpu
which does not initialize certain variables.

This commit ensures such variables are initialized to zero by default.
Note that this commit itself does not regenerate CRIS CPU related files
with CGEN because it still has several issues preventing regeneration.
They are to be fixed in the later commits.

cpu/ChangeLog:

	* cris.cpu: Initialize condres, newval and tmpres variables.
---
 cpu/cris.cpu | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Hans-Peter Nilsson Oct. 22, 2022, 1:59 a.m. UTC | #1
On Thu, 20 Oct 2022, Tsukasa OI via Binutils wrote:

> GCC / Clang generate a warning if a variable may be used uninitialized on
> some cases (Clang: "-Wsometimes-uninitialized").  When the program is being
> built by Clang with the default configuration, it causes a build failure
> (unless "--disable-werror" is specified).
> 
> Those error occur on sim/cris/semcrisv{10,32}f-switch.c but they are
> CGEN-generated files.  The real cause of this problem is in cpu/cris.cpu
> which does not initialize certain variables.

I'd say the problem is an artefact of CGEN code generation, as 
the conditions are exhaustive.  In the generated code it's far 
from obvious though...

> This commit ensures such variables are initialized to zero by default.
> Note that this commit itself does not regenerate CRIS CPU related files
> with CGEN because it still has several issues preventing regeneration.
> They are to be fixed in the later commits.
> 
> cpu/ChangeLog:
> 
> 	* cris.cpu: Initialize condres, newval and tmpres variables.

Ok with a comment saying something to the effect of "It's not 
obvious in generated code that all cases are covered in the 
conditional settings below, so initialize this to avoid compiler 
warnings" (and referring to the previous comment for all but the 
first).

Thanks!
brgds, H-P
  

Patch

diff --git a/cpu/cris.cpu b/cpu/cris.cpu
index 97b44581e78..cd85f4e94e2 100644
--- a/cpu/cris.cpu
+++ b/cpu/cris.cpu
@@ -541,6 +541,7 @@ 
   (sequence
     BI
     ((SI tmpcond) (BI condres))
+    (set condres 0)
     (set tmpcond condno)
      (.splice
       cond
@@ -2655,6 +2656,7 @@ 
      (sequence
        ((SI rno) (SI newval))
        (set rno (regno Pd))
+       (set newval 0)
        (.splice
 	cond
 	; No sanity check for constant special register here, since the
@@ -3698,6 +3700,7 @@ 
   (sequence
     SI
     ((SI tmpcode) (SI tmpval) (SI tmpres))
+    (set tmpres 0)
     (set tmpcode swapcode)
     (set tmpval val)
     (.splice