Bug 32129 - ICE: Procedure call with array-section-actual to scalar dummy
Summary: ICE: Procedure call with array-section-actual to scalar dummy
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Paul Thomas
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-05-28 17:07 UTC by Tobias Burnus
Modified: 2007-12-09 09:19 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-11-21 13:51:56


Attachments
Fix for the PR (1.27 KB, patch)
2007-12-07 11:48 UTC, Paul Thomas
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-05-28 17:07:08 UTC
This is kind of a split up of PR31564, which is unrelated.

The program is invalid as we pass an array as actual argument to the scalar dummy argument; somehow gfortran does not detect this.

Interestingly, compare_actual_formal is never called if the actual argument is an array section with non-expr-constant bounds. If it is a single element, or the whole array or has e.g. bounds "1:1" or "1:2" everything is caught and goes through compare_actual_formal, except for ":which", "1:which" etc.

The ICE is:
x.f90: In function 'cdf_beta':
x.f90:16: internal compiler error: in gfc_trans_call, at fortran/trans-stmt.c:321


Testcase, from PR 31564 modified to produce invalid code.

    MODULE cdf_aux_mod
      TYPE :: the_distribution
        INTEGER :: parameters(1)
      END TYPE the_distribution
      TYPE (the_distribution), PARAMETER :: the_beta = the_distribution((/0/))
    CONTAINS
      SUBROUTINE set_bound(arg_name)
        INTEGER, INTENT (IN) :: arg_name
      END SUBROUTINE set_bound
    END MODULE cdf_aux_mod
    MODULE cdf_beta_mod
    CONTAINS
      SUBROUTINE cdf_beta()
        USE cdf_aux_mod
        INTEGER :: which
          which = 1
          CALL set_bound(the_beta%parameters(1:which))
      END SUBROUTINE cdf_beta
    END MODULE cdf_beta_mod
Comment 1 Tobias Burnus 2007-05-28 18:13:42 UTC
Some debugging shows:

resolve_call calls resolve_actual_arglist, which fails. 
resolve_call propagates the failure to resolve_where, which does not check for errors.

In resolve_actual_arglist it fails here:

      if (e->ts.type != BT_PROCEDURE)
        {
          if (gfc_resolve_expr (e) != SUCCESS)
            return FAILURE;
Comment 2 Mikael Morin 2007-06-02 00:06:34 UTC
Here is an other test case. 

      program testCode
      implicit none 
      type vec
              real, dimension(3) :: coords
      end type
      integer, parameter :: n = 5
      integer :: i
      real, dimension(3, n), parameter :: vy =
     &  reshape( (/ (1.d0, i=1,3*n) /), shape = (/ 3, n /))

      i = 1
      call Sub(vec(vy(:,i)))

      contains

      subroutine Sub(xin)
      type(vec)       :: xin
      intent(in)  xin

      print*, xin

      end subroutine
      end program


This program produce an ICE (in gfc_trans_call, at fortran/trans-stmt.c:321)

But if vy is a normal variable (not a parameter), it works.
And it works also if we use vy(:,1) instead of vy(:,i). 

Hoping it helps... 
Comment 3 Jerry DeLisle 2007-10-21 03:29:18 UTC
The original test case here no longer gives an ICE.

The case on Comment #2 does ICE

pr32129-a.f90: In function ‘MAIN__’:
pr32129-a.f90:11: internal compiler error: in gfc_trans_call, at fortran/trans-stmt.c:320
Comment 4 Francois-Xavier Coudert 2007-11-21 13:51:56 UTC
I think this is valid code. The reduced testcase is:

$ cat y.f90
program testCode
  implicit none
  type vec
    real, dimension(1) :: coords
  end type
  integer :: i
  real, dimension(1,1), parameter :: vy = 1.

  i = 1
  call Sub(vec(vy(:,i)))

contains

  subroutine Sub(xin)
    type(vec) :: xin
    intent(in)  xin

    print*, xin
  end subroutine
end program
$ gfortran y.f90
y.f90: In function ‘testcode’:
y.f90:9: internal compiler error: in gfc_trans_call, at fortran/trans-stmt.c:321


But it also happens with external functions:
$ cat y2.f90
  implicit none
  type vec
    integer, dimension(1) :: coords
  end type
  integer :: i
  integer, dimension(1,1), parameter :: vy = 0

  i = 1
  call shape(vec(vy(:,i)))
end program
$ gfortran y2.f90
y2.f90: In function ‘MAIN__’:
y2.f90:8: internal compiler error: in gfc_trans_call, at fortran/trans-stmt.c:321


And it's actually a nice area for bugs to creep in:

$ cat y3.f90
  integer, parameter :: vy(1,1) = 0
  type vec
    integer :: coords(1)
  end type
  integer :: i

  i = 1
  print *, shape(vec(vy(:,i)))
end program
$ gfortran y3.f90
y3.f90: In function ‘MAIN__’:
y3.f90:7: internal compiler error: Bad IO basetype (1)



$ cat y4.f90
  implicit none
  type vec
    integer, dimension(1) :: coords
  end type
  integer :: i
  integer, dimension(1,1), parameter :: vy = 0

  i = 1
  print *, shape(vec(vy(:,i)))
end program
$ gfortran y4.f90
y2.f90: In function ‘MAIN__’:
y2.f90:8: internal compiler error: in gfc_typenode_for_spec, at fortran/trans-types.c:841
Comment 5 Paul Thomas 2007-12-07 11:48:45 UTC
Created attachment 14707 [details]
Fix for the PR

This is just regtesting but I think that it will be OK.

Note that this expression type was getting mangled in simplification.

Paul
Comment 6 Paul Thomas 2007-12-07 13:46:15 UTC
(In reply to comment #5)

> This is just regtesting but I think that it will be OK.

Famous last words! It regresses in elemental_subroutine_2.f90.  It should all be fixable witout much effort, though.

Paul
Comment 7 Dominique d'Humieres 2007-12-08 20:45:40 UTC
Now works as advertized without regression on i686-apple-darwin9.

Comment 8 Paul Thomas 2007-12-09 09:17:37 UTC
Subject: Bug 32129

Author: pault
Date: Sun Dec  9 09:17:24 2007
New Revision: 130719

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130719
Log:
2007-12-09  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/32129
	* dump-parse-tree.c (gfc_show_expr_n): New function for
	debugging.
	* gfortran.h : Add prototype for gfc_show_expr_n.
	* expr.c (simplify_constructor): Copy the constructor
	expression and try to simplify that.  If success, replace the
	original.  Otherwise discard the copy, keep going through
	the structure and return success.

	PR fortran/31487
	* decl.c (build_struct): Pad out default initializers with
	spaces to the component character length.

2007-12-09  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/32129
	* gfortran.dg/derived_comp_array_ref_6.f90: New test.
	* gfortran.dg/derived_comp_array_ref_7.f90: New test.

	PR fortran/31487
	* gfortran.dg/char_component_initializer_1.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/char_component_initializer_1.f90
    trunk/gcc/testsuite/gfortran.dg/derived_comp_array_ref_6.f90
    trunk/gcc/testsuite/gfortran.dg/derived_comp_array_ref_7.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/dump-parse-tree.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/testsuite/ChangeLog

Comment 9 Paul Thomas 2007-12-09 09:19:56 UTC
Fixed on trunk

Paul