https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124976

            Bug ID: 124976
           Summary: trans-array.cc:8664: read/write order problem ?
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

Source code is

      /* Tell the scalarizer to make a temporary.  */
      loop.temp_ss = gfc_get_temp_ss (gfc_typenode_for_spec (&expr->ts),
                                      ((expr->ts.type == BT_CHARACTER)
                                       ? expr->ts.u.cl->backend_decl
                                       : NULL),
                                      loop.dimen);

Coverity says:

 CID 1599261: (#1 of 1): Evaluation order violation (EVALUATION_ORDER)
read_write_order: In argument #1 of
gfc_get_temp_ss(gfc_typenode_for_spec(&expr->ts, 0), ((expr->ts.type ==
BT_CHARACTER) ? expr->ts.u.cl->backend_decl : NULL), loop.dimen), a call is
made to gfc_typenode_for_spec(&expr->ts, 0). In argument #1 of this function,
the object expr->ts.type is modified. This object is also used in
(expr->ts.type == BT_CHARACTER) ? expr->ts.u.cl->backend_decl : NULL, the
argument #2 of the outer function call. The order in which these arguments are
evaluated is not specified, and will vary between platforms.

I think a probable fix for this is to put the result
of gfc_typenode_for_spec (&expr->ts) into a local variable first,
then use that in the call to gfc_get_temp_ss.

git blame says:

1ae4f435fc5 gcc/fortran/trans-array.c  (Mikael Morin               2011-09-08
17:18:20 +0200  8663)       /* Tell the scalarizer to make a temporary.  */
a1ae4f435fc5 gcc/fortran/trans-array.c  (Mikael Morin               2011-09-08
17:18:20 +0200  8664)       loop.temp_ss = gfc_get_temp_ss
(gfc_typenode_for_spec (&expr->ts),
a1ae4f435fc5 gcc/fortran/trans-array.c  (Mikael Morin               2011-09-08
17:18:20 +0200  8665)                      ((expr->ts.type == BT_CHARACTER)
a1ae4f435fc5 gcc/fortran/trans-array.c  (Mikael Morin               2011-09-08
17:18:20 +0200  8666)                       ? expr->ts.u.cl->backend_decl
a1ae4f435fc5 gcc/fortran/trans-array.c  (Mikael Morin               2011-09-08
17:18:20 +0200  8667)                       : NULL),
a1ae4f435fc5 gcc/fortran/trans-array.c  (Mikael Morin               2011-09-08
17:18:20 +0200  8668)                      loop.dimen);

Reply via email to