Bug 71085 - ICE with some intrinsic functions specifying array function result dimension
Summary: ICE with some intrinsic functions specifying array function result dimension
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 7.1.1
: P4 normal
Target Milestone: 6.5
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-12 11:29 UTC by Vladimir Fuka
Modified: 2018-03-04 05:13 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-05-12 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Fuka 2016-05-12 11:29:16 UTC
print *, f()
  
contains

  function f()
    integer :: f(iargc()*10)
  end

end


ICE's with gcc version 5.3.1 20160412


   print *, f()
 1
internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugs.opensuse.org/> for instructions.

Also ICE's with nint(rand()), irand(), nint(second()).

It does not crash with itime() and nint(secnd()).
Comment 1 Richard Biener 2016-05-12 12:31:28 UTC
Confirmed on trunk.

> ./f951 -quiet t.f90
t.f90:1:0:

 print *, f()
 
internal compiler error: Segmentation fault
0xf03530 crash_signal
        /space/rguenther/src/svn/trunk/gcc/toplev.c:333
0x8cd83c gfc_apply_interface_mapping_to_expr
        /space/rguenther/src/svn/trunk/gcc/fortran/trans-expr.c:4255
0x8cd7b6 gfc_apply_interface_mapping_to_expr
        /space/rguenther/src/svn/trunk/gcc/fortran/trans-expr.c:4245
0x8cd969 gfc_apply_interface_mapping(gfc_interface_mapping*, gfc_se*, gfc_expr*)
        /space/rguenther/src/svn/trunk/gcc/fortran/trans-expr.c:4291
0x887f92 gfc_set_loop_bounds_from_array_spec(gfc_interface_mapping*, gfc_se*, gfc_array_spec*)
...
Comment 2 Harald Anlauf 2018-03-01 22:13:56 UTC
The following obvious(?) patch appears to fix the ICE:

Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c    (revision 258112)
+++ gcc/fortran/trans-expr.c    (working copy)
@@ -4349,6 +4349,8 @@
 
       if (expr->value.function.esym == NULL
            && expr->value.function.isym != NULL
+           && expr->value.function.actual
+           && expr->value.function.actual->expr
            && expr->value.function.actual->expr->symtree
            && gfc_map_intrinsic_function (expr, mapping))
        break;
Comment 3 Harald Anlauf 2018-03-02 20:54:13 UTC
Patch submitted:

https://gcc.gnu.org/ml/fortran/2018-03/msg00009.html
Comment 4 kargls 2018-03-04 01:37:44 UTC
Author: kargl
Date: Sun Mar  4 01:37:13 2018
New Revision: 258228

URL: https://gcc.gnu.org/viewcvs?rev=258228&root=gcc&view=rev
Log:
2018-03-03  Harald Anlauf  <anlauf@gmx.de>

	PR fortran/71085
	* trans-expr.c (gfc_apply_interface_mapping_to_expr): Do not
	dereference NULL pointer.


2018-03-03  Harald Anlauf  <anlauf@gmx.de>

	PR fortran/71085
	* gfortran.dg/pr71085.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/pr71085.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 kargls 2018-03-04 01:52:56 UTC
Author: kargl
Date: Sun Mar  4 01:52:24 2018
New Revision: 258229

URL: https://gcc.gnu.org/viewcvs?rev=258229&root=gcc&view=rev
Log:
2018-03-03  Harald Anlauf  <anlauf@gmx.de>

	PR fortran/71085
	* trans-expr.c (gfc_apply_interface_mapping_to_expr): Do not
	dereference NULL pointer.


2018-03-03  Harald Anlauf  <anlauf@gmx.de>

	PR fortran/71085
	* gfortran.dg/pr71085.f90: New test.


Added:
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr71085.f90
Modified:
    branches/gcc-7-branch/gcc/fortran/ChangeLog
    branches/gcc-7-branch/gcc/fortran/trans-expr.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 6 kargls 2018-03-04 05:12:05 UTC
Author: kargl
Date: Sun Mar  4 05:11:31 2018
New Revision: 258230

URL: https://gcc.gnu.org/viewcvs?rev=258230&root=gcc&view=rev
Log:
2018-03-03  Harald Anlauf  <anlauf@gmx.de>

	PR fortran/71085
	* trans-expr.c (gfc_apply_interface_mapping_to_expr): Do not
	dereference NULL pointer.


2018-03-03  Harald Anlauf  <anlauf@gmx.de>

	PR fortran/71085
	* gfortran.dg/pr71085.f90: New test.

Added:
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/pr71085.f90
Modified:
    branches/gcc-6-branch/gcc/fortran/ChangeLog
    branches/gcc-6-branch/gcc/fortran/trans-expr.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 7 kargls 2018-03-04 05:13:27 UTC
Fixed on 6-branch, 7-branch, and trunk.
Thanks for bug report.