Bug 1369183 - gfortran compiler crash
Summary: gfortran compiler crash
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: gcc
Version: 7.2
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Jakub Jelinek
QA Contact: Michael Petlan
URL:
Whiteboard:
Depends On:
Blocks: 1298243 1390370
TreeView+ depends on / blocked
 
Reported: 2016-08-22 15:28 UTC by Paulo Andrade
Modified: 2020-09-10 09:44 UTC (History)
7 users (show)

Fixed In Version: gcc-4.8.5-12.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-08-01 22:35:59 UTC
Target Upstream Version:


Attachments (Terms of Use)
reproducer.tar (10.00 KB, application/x-tar)
2016-08-22 15:28 UTC, Paulo Andrade
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2017:2094 0 normal SHIPPED_LIVE gcc bug fix update 2017-08-01 19:36:07 UTC

Description Paulo Andrade 2016-08-22 15:28:36 UTC
Created attachment 1192960 [details]
reproducer.tar

This is a simple crash on apparently valid code. The
crash happens due to no fields declared to a sequence
type; adding a field or removing the sequence attribute
prevents the crash.

  A simple patch could be to add:

          if (dt1 == dt2)
            return 1;
          if (!dt1 || !dt2)
            return 0;

to gfc_compare_derived_types before the for loop:

389	int
390	gfc_compare_derived_types (gfc_symbol *derived1, gfc_symbol *derived2)
[...]
421	  dt1 = derived1->components;
422	  dt2 = derived2->components;
423	
424	  /* Since subtypes of SEQUENCE types must be SEQUENCE types as well, a
425	     simple test can speed things up.  Otherwise, lots of things have to
426	     match.  */
427	  for (;;)
428	    {
429	      if (strcmp (dt1->name, dt2->name) != 0)
430		return 0;
431	
432	      if (dt1->attr.access != dt2->attr.access)
433		return 0;

or a slightly less readable variant:

          if (!dt1 || !dt2)
              return dt1 == dt2;

  Simple reproducer derived from user issue attached.

Comment 1 Marek Polacek 2016-08-22 15:57:13 UTC
The ICE was fixed in <https://gcc.gnu.org/r235999>.  But since that revision I get:

$ ./f951 -quiet t.f90
t.f90:6:12:

    call sub(tst)
            1
Error: Type mismatch in argument ‘test’ at (1); passed TYPE(test_t) to TYPE(test_t)

You said "apparently valid code", but did you really mean "valid"?  I don't know Fortran to gauge whether this is or isn't valid.

In any case, the revision is pretty recent and doesn't seem to be backportable.

Comment 2 Paulo Andrade 2016-08-22 16:15:51 UTC
  I said apparently valid code because the specification
appears to not tell about empty types:

TYPE [[ , access specification ] :: ] type name
  [ PRIVATE ]
  [ SEQUENCE ]
  [ type specification [[ , POINTER ] :: ] component specification list ]
  ...
END TYPE [ type name ]

  The type mismatch error is expected. The user just
believes that the ICE should not happen.

Comment 3 Marek Polacek 2016-08-22 16:22:15 UTC
Sure, the ICE is definitely a bug, but if the type mismatch error is expected, then this would be ICE-on-invalid, and such bugs have a rather low priority.

Comment 4 Paulo Andrade 2016-08-22 17:05:31 UTC
  I just tested on rawhide, with this minor change,
to make the types compatible:

mod.f90:
-    integer(4) type
+!   integer(4) type

and test.sh (to avoid link failure):

- gfortran t.f90
+ gfortran -c t.f90

and it compiles and generates .o files.

Comment 10 Michael Petlan 2017-05-31 14:09:46 UTC
The related test passes on all architectures with gcc-4.8.5-14.el7.
VERIFIED.

Comment 11 errata-xmlrpc 2017-08-01 22:35:59 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:2094


Note You need to log in before you can comment on or make changes to this bug.