While bootstrapping GCC on S/390 the following warning is raised:

gcc/fortran/matchexp.c: In function 'match match_level_5(gfc_expr**)':
gcc/fortran/matchexp.c:401:18: error: 'e' may be used uninitialized in this 
function [-Werror=maybe-uninitialized]
  401 |    gfc_free_expr (e);
      |    ~~~~~~~~~~~~~~^~~
/home/stefansf/devel/gcc/src/gcc/fortran/matchexp.c:353:19: note: 'e' was 
declared here
  353 |   gfc_expr *all, *e, *total;
      |                   ^

In function match_add_operand local variable e gets initialised via
function match_ext_mult_operand if it returns MATCH_YES.  In case of the
remaining two return values MATCH_NO and MATCH_ERROR the current
function call is terminated before e may be used.  Thus this
warning/error seems to be a false positive analogous to variable e in
function match_mult_operand.  Interestingly this warning may be silenced
by initialising variable e of either function match_level_5 or
match_add_operand.  Since both variables are unrelated and correspond to
different functions, this endorses the suspicion of a false positive.

Silenced the warning by initializing variable e of function
match_add_operand.

Bootstrapped and regtested on S/390.  Ok for master?

gcc/fortran/ChangeLog:

2020-05-04  Stefan Schulze Frielinghaus  <stefa...@linux.ibm.com>

        * matchexp.c (match_add_operand): Initialize local variable e.
---
 gcc/fortran/matchexp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/matchexp.c b/gcc/fortran/matchexp.c
index 6479582d75b..25e675f3d45 100644
--- a/gcc/fortran/matchexp.c
+++ b/gcc/fortran/matchexp.c
@@ -348,7 +348,9 @@ match_ext_mult_operand (gfc_expr **result)
 static match
 match_add_operand (gfc_expr **result)
 {
-  gfc_expr *all, *e, *total;
+  /* Workaround -Wmaybe-uninitialized false positive by initializing variable
+     e.  */
+  gfc_expr *all, *e = NULL, *total;
   locus where, old_loc;
   match m;
   gfc_intrinsic_op i;
-- 
2.25.3

  • [PATCH, FORTRAN] matchexp.c: F... Stefan Schulze Frielinghaus via Gcc-patches

Reply via email to