Bug 34556 - Rejects valid with bogus error message: parameter initalization
Rejects valid with bogus error message: parameter initalization
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.3.0
: P3 normal
: ---
Assigned To: Jerry DeLisle
: ice-on-valid-code, rejects-valid
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-12-22 19:08 UTC by Tobias Burnus
Modified: 2008-01-18 04:05 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-01-13 01:24:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-12-22 19:08:59 UTC
! Rejects-valid. Fails with gfortran 4.1, 4.2 and 4.3
! For 4.3 the error message is:
!
!                (/ linem, nplam /) )
!                 1
!Error: Invalid character in name at (1)
!
! Found using the Fortran Company Fortran 90 Test Suite (Lite),
! Version 1.4
module splitprms
      integer, parameter  :: nplam = 3 ! # of plans to expand TABs
      integer, parameter  :: linem = 132 ! max. line length
      integer, parameter  :: ncntm = 39 ! max. # cont. lines
      integer, parameter, dimension (linem, nplam) :: nxttab =  &
      reshape (                                                 &
               (/ max( (/ (6+3*((i-6+3)/3), i= 1,linem),        &
                          (6+2*((i-6+2)/2), i= 1,linem) /),     &
                       (/ (6, i= 1, 2*linem) /)            ),   &
                  (/                      (i, i= 1,linem) /) /),&
                (/ linem, nplam /) )
end module splitprms
Comment 1 Daniel Franke 2007-12-22 21:25:55 UTC
Confirmed.

Simplified testcase:

  integer :: a(2,2) = reshape( (/ max((/ 1,2 /), (/ 3,4 /)), (/4,5/) /), (/2,2/))
end

It seems that the array-valued MAX is crucial here. If removed or replaced by a scalar-valued MAX, it works as expected. OTOH, removing RESHAPE works as well.
Comment 2 Daniel Franke 2007-12-23 18:32:15 UTC
$> cat pr34556.f90
integer :: a(2,2)
a = reshape( (/ max((/ 1,2 /), (/ 3,4 /)), (/4,5/) /), (/2,2/))
end

$> gfortran-svn pr34556.f90
pr34556.f90: In function 'MAIN__':
pr34556.f90:1: internal compiler error: Intrinsic function (164) not recognized
Please submit a full bug report,


(gdb) bt
#0  gfc_conv_intrinsic_lib_function (se=0xbff44e60, expr=0x89b8ad0) at ../../../gcc/gcc/fortran/trans-intrinsic.c:714
#1  0x080fc443 in gfc_conv_intrinsic_function (se=0xbff44e60, expr=0x89b8ad0) at ../../../gcc/gcc/fortran/trans-intrinsic.c:4140
#2  0x080eed87 in gfc_conv_function_expr (se=0xbff44e60, expr=0xa4) at ../../../gcc/gcc/fortran/trans-expr.c:3033
#3  0x080ef491 in gfc_conv_expr (se=0xbff44e60, expr=0x89b8ad0) at ../../../gcc/gcc/fortran/trans-expr.c:3537
#4  0x080d8acf in gfc_add_loop_ss_code (loop=0xbff44fa4, ss=0x89b9820, subscript=0 '\0') at ../../../gcc/gcc/fortran/trans-array.c:1828
#5  0x080d9874 in gfc_conv_loop_setup (loop=0xbff44fa4) at ../../../gcc/gcc/fortran/trans-array.c:3385
#6  0x080f019e in gfc_trans_assignment_1 (expr1=0x89b8458, expr2=0x89b8ad0, init_flag=0 '\0') at ../../../gcc/gcc/fortran/trans-expr.c:4258
#7  0x080f075c in gfc_trans_assignment (expr1=0x89b8458, expr2=0x89b8ad0, init_flag=32 ' ') at ../../../gcc/gcc/fortran/trans-expr.c:4434
#8  0x080f12f1 in gfc_trans_assign (code=0x89b96f8) at ../../../gcc/gcc/fortran/trans-expr.c:4446
#9  0x080cfbc0 in gfc_trans_code (code=0x89b96f8) at ../../../gcc/gcc/fortran/trans.c:994
#10 0x080e78c2 in gfc_generate_function_code (ns=0x89b7b20) at ../../../gcc/gcc/fortran/trans-decl.c:3263
#11 0x0809ee35 in gfc_parse_file () at ../../../gcc/gcc/fortran/parse.c:3396
#12 0x080c86b5 in gfc_be_parse_file (set_yydebug=0) at ../../../gcc/gcc/fortran/f95-lang.c:260
#13 0x0836c0f4 in toplev_main (argc=2, argv=0xbff454e4) at ../../../gcc/gcc/toplev.c:1042
#14 0x0811462f in main (argc=0, argv=0x89b8ad0) at ../../../gcc/gcc/main.c:35

(gdb) print id
$7 = GFC_ISYM_RESHAPE

(gdb) print *m
$8 = {id = GFC_ISYM_NONE, code_r4 = END_BUILTINS, code_r8 = END_BUILTINS, code_r10 = END_BUILTINS, code_r16 = END_BUILTINS, code_c4 = END_BUILTINS,
  code_c8 = END_BUILTINS, code_c10 = END_BUILTINS, code_c16 = END_BUILTINS, libm_name = 0 '\0', complex_available = 0 '\0', is_constant = 1 '\001',
  name = 0x0, real4_decl = 0x0, real8_decl = 0x0, real10_decl = 0x0, real16_decl = 0x0, complex4_decl = 0x0, complex8_decl = 0x0, complex10_decl = 0x0,
  complex16_decl = 0x0}
Comment 3 Paul Thomas 2008-01-11 10:13:42 UTC
I have had a brief attempt to resolve this one and have driven my head against a brick wall!

Starting with this development of the original testcase:

! Rejects-valid. Fails with gfortran 4.1, 4.2 and 4.3
! For 4.3 the error message is:
!
!                (/ linem, nplam /) )
!                 1
!Error: Invalid character in name at (1)
!
! Found using the Fortran Company Fortran 90 Test Suite (Lite),
! Version 1.4
module splitprms
      integer, parameter  :: nplam = 3 ! # of plans to expand TABs
      integer, parameter  :: linem = 3 ! max. line length
      integer, parameter  :: ncntm = 39 ! max. # cont. lines
      integer, parameter, dimension (linem*nplam) :: check1 =   &
      [ max ([(i, i= 1,linem), (10*i, i= 1,linem)],             &
      [(6, i= 1, 2*linem) ]), [(i, i= 1,linem)]]

      integer, parameter, dimension (linem, nplam) :: check2 =  &
      reshape (check1, [linem, nplam ])

      integer, parameter, dimension (2) :: check3 =  [linem, nplam ]

! This is OK!!!!!!!!!
      integer, parameter, dimension (linem, nplam) :: check4 =  &
      reshape ([ max ([(i, i= 1,linem), (10*i, i= 1,linem)],    &
               [(6, i= 1, 2*linem) ]), [(i, i= 1,linem)]],      &
                check3 )
! This is not....
      integer, parameter, dimension (linem, nplam) :: nxttab =  &
      reshape ([ max ([(i, i= 1,linem), (10*i, i= 1,linem)],    &
               [(6, i= 1, 2*linem) ]), [(i, i= 1,linem)]],      &
               [linem, nplam ])
! This is the original
      integer, parameter, dimension (linem, nplam) :: nxttab2 = &
      reshape (                                                 &
               (/max ((/(6+3*((i-6+3)/3), i= 1,linem),          &
                        (6+2*((i-6+2)/2), i= 1,linem)/),        &
                      (/(6, i= 1, 2*linem)/)),                  &
                (/(i, i= 1,linem)/)/), (/ linem, nplam /) )
end module splitprms

Resolution of the 'reshape' function is being derailed for some reason by the shape expression in gfc_simplify_reshape.  However, simplifying this does not do the job but adding a gfc_simplify_expr in gfc_get_array_element fixes this problem but breaks everything else!

*sigh*

Paul
Comment 4 Jerry DeLisle 2008-01-13 01:24:24 UTC
This is similar to 34432 is some ways. I think we are not matching the (\ \) correctly.  I don't think gfc_match_expr has the tooling for it yet.

Investigating further
Comment 5 Paul Thomas 2008-01-13 08:49:16 UTC
(In reply to comment #4)
> This is similar to 34432 is some ways. I think we are not matching the (\ \)
> correctly.  I don't think gfc_match_expr has the tooling for it yet.

The error message is spurious in my opinion.  It is left on the stack from a failed match. As I say above, the problem is in simplification and, specifically, the simplification of reshape.

Hang a gfc_show_expr_n in gfc_simplify_reshape for each of the arguments and see what happens.  You will find, I believe, that the simplification is failing on arguments that look perfectly OK for reasons that I just do not understand.

Good luck - I think that it is easily fixable but that one needs to alight on what triggers failure.

Paul
Comment 6 Jerry DeLisle 2008-01-13 15:18:11 UTC
Subject: Re:  Rejects valid with bogus error message:
 parameter initalization

pault at gcc dot gnu dot org wrote:
> ------- Comment #5 from pault at gcc dot gnu dot org  2008-01-13 08:49 -------
> (In reply to comment #4)
>> This is similar to 34432 is some ways. I think we are not matching the (\ \)
>> correctly.  I don't think gfc_match_expr has the tooling for it yet.
> 
> The error message is spurious in my opinion.  It is left on the stack from a
> failed match. As I say above, the problem is in simplification and,
> specifically, the simplification of reshape.
> 
I agree there is a failed match.  I am reducing the test case until I can get 
this to succeed.  I have managed to ICE a similar test case. Here:

! Rejects-valid. Fails with gfortran 4.1, 4.2 and 4.3
! For 4.3 the error message is:
!
!                (/ linem, nplam /) )
!                 1
!Error: Invalid character in name at (1)
!
! Found using the Fortran Company Fortran 90 Test Suite (Lite),
! Version 1.4
program splitprms
       integer, parameter  :: nplam = 3 ! # of plans to expand TABs
       integer, parameter  :: linem = 132 ! max. line length
       integer, parameter  :: ncntm = 39 ! max. # cont. lines
       integer, dimension (linem, nplam) :: nxttab
       nxttab      =  &
       reshape (                                                 &
                (/ max( (/ (6+3*((i-6+3)/3), i= 1,linem),        &
                           (6+2*((i-6+2)/2), i= 1,linem) /),     &
                        (/ (6, i= 1, 2*linem) /)            ),   &
                   (/                      (i, i= 1,linem) /) /),&
                 (/ linem, nplam /) )
       print *, nxttab
end program splitprms

]$ gfc pr34556.f90
pr34556.f90: In function ‘splitprms’:
pr34556.f90:10: internal compiler error: Intrinsic function (164)
Comment 7 Jerry DeLisle 2008-01-13 19:38:27 UTC
In gfc_simplify_reshape, gfc_get_array_element is returning a NULL pointer.  This is due to a failure in expand_constructor.  I am still tracing this.
Comment 8 Jerry DeLisle 2008-01-14 01:11:33 UTC
Patch submitted:

http://gcc.gnu.org/ml/fortran/2008-01/msg00170.html
Comment 9 Daniel Franke 2008-01-14 09:28:21 UTC
In reply to comment #8:
Jerry, does your patch also fix the ICE from comment #2?
Comment 10 Tobias Burnus 2008-01-14 09:32:21 UTC
> Jerry, does your patch also fix the ICE from comment #2?

It does. However, as Paul points out, the following gives still:

      reshape ([[(6, i= 1, 2*linem) ], [(i, i= 1,linem)],    &
               1
Error: Invalid character in name at (1)


      integer, parameter  :: nplam = 3 ! # of plans to expand TABs
      integer, parameter  :: linem = 132 ! max. line length
      integer, parameter  :: ncntm = 39 ! max. # cont. lines
      integer, parameter, dimension (linem, nplam) :: nxttab =  &
      reshape ([[(6, i= 1, 2*linem) ], [(i, i= 1,linem)],    &
                max ([(i, i= 1,linem)], [(10*i, i= 1,linem)])],      &
               [linem, nplam ])
      end
Comment 11 Jerry DeLisle 2008-01-18 02:09:11 UTC
Subject: Bug 34556

Author: jvdelisle
Date: Fri Jan 18 02:08:22 2008
New Revision: 131623

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131623
Log:
2008-01-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/34556
	* simplify.c (is_constant_array_expr): New static function that returns
	true if the given expression is an array and is constant.
	(gfc_simplify_reshape): Use new function.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/simplify.c

Comment 12 Jerry DeLisle 2008-01-18 02:17:32 UTC
Subject: Bug 34556

Author: jvdelisle
Date: Fri Jan 18 02:16:48 2008
New Revision: 131624

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131624
Log:
2007-01-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR target/34556
	* gfortran.dg/reshape_2.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/reshape_2.f90
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 13 Jerry DeLisle 2008-01-18 04:05:48 UTC
Fixed on trunk.