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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org
           Keywords|                            |ice-on-valid-code,
                   |                            |wrong-code

--- Comment #21 from anlauf at gcc dot gnu.org ---
There's also valid code that ICEs, and invalid code that is silently accepted.

Invalid code:

program p
  implicit none
  integer, parameter :: b = 1
  data b / 2 /
  print *, b
end

Instead of being rejected, this prints:
           1

One could catch this one in gfc_assign_data_value, but I haven't found out
yet how to get this right with derived type components, so there's possibly
a better place.

And after fixing an obvious NULL pointer dereference,

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 37a0c85fa30..783a0bbddcc 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -5520,7 +5520,7 @@ check_constant_initializer (gfc_expr *expr, gfc_typespec
*ts, bool array,
        return false;
       cm = expr->ts.u.derived->components;
       for (c = gfc_constructor_first (expr->value.constructor);
-          c; c = gfc_constructor_next (c), cm = cm->next)
+          c && cm; c = gfc_constructor_next (c), cm = cm->next)
        {
          if (!c->expr || cm->attr.allocatable)
            continue;

we arrive at wrong code on valid input:

program p
  implicit none
  type t
     real :: a
  end type t
  type(t) :: z = t(4.0)
  data z%a /3.0/
  print *, z%a
end

This now prints
   4.00000000

Reply via email to