Bug 24813 - ICE with scalarization LEN of character types
Summary: ICE with scalarization LEN of character types
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: Fortran_character
  Show dependency treegraph
 
Reported: 2005-11-11 20:55 UTC by david serafini
Modified: 2006-05-08 06:25 UTC (History)
1 user (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2006-01-27 20:41:02


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description david serafini 2005-11-11 20:55:21 UTC
../Src/fparser.f90:329: internal compiler error: in gfc_conv_array_constructor_expr, at fortran/trans-expr.c:1975

The problem is at the line "CHARACTER (LEN=LEN(Funcs)) :: fun"
It goes away if changed to: LEN=LEN(Funcs(cAbs))
but I believe the standard says the argument to LEN() can be
array valued (I don't have my copy handy, but my DEC Reference Manual,
which is rarely wrong, says this.)

Here's the code:

MODULE fparser
  IMPLICIT NONE
  INTEGER, PARAMETER :: is = SELECTED_INT_KIND(4) ! Data type of bytecode
  PRIVATE
  SAVE
  INTEGER(is),                              PARAMETER :: cImmed   = 1,          &
                                                         cAbs     = 8,          &
                                                         cExp     = 9,          &
                                                         cLog10   = 10,         &
                                                         cLog     = 11,         &
                                                         cSqrt    = 12,         &
                                                         cSinh    = 13,         &
                                                         cCosh    = 14,         &
                                                         cTanh    = 15,         &
                                                         cSin     = 16,         &
                                                         cCos     = 17,         &
                                                         cTan     = 18,         &
                                                         cAsin    = 19,         &
                                                         cAcos    = 20,         &
                                                         cAtan    = 21,         &
                                                         VarBegin = 22
  CHARACTER (LEN=5), DIMENSION(cAbs:cAtan), PARAMETER :: Funcs    = (/ 'abs  ', &
                                                                       'exp  ', &
                                                                       'log10', &
                                                                       'log  ', &
                                                                       'sqrt ', &
                                                                       'sinh ', &
                                                                       'cosh ', &
                                                                       'tanh ', &
                                                                       'sin  ', &
                                                                       'cos  ', &
                                                                       'tan  ', &
                                                                       'asin ', &
                                                                       'acos ', &
                                                                       'atan ' /)
CONTAINS
  FUNCTION MathFunctionIndex (str) RESULT (n)
    IMPLICIT NONE
    CHARACTER (LEN=*), INTENT(in) :: str
    INTEGER(is)                   :: n,j
    INTEGER                       :: k
    CHARACTER (LEN=LEN(Funcs))    :: fun
    n = 0
    DO j=cAbs,cAtan                                          ! Check all math functions
       k = MIN(LEN_TRIM(Funcs(j)), LEN(str))   
       CALL LowCase (str(1:k), fun)
       IF (fun == Funcs(j)) THEN                             ! Compare lower case letters
          n = j                                              ! Found a matching function
          EXIT
       END IF
    END DO
  END FUNCTION MathFunctionIndex

END MODULE fparser
Comment 1 Andrew Pinski 2005-11-11 21:10:54 UTC
Confirmed, reduced testcase:
MODULE fparser
  INTEGER(is),     PARAMETER :: cImmed   = 1,         &
                                                       VarBegin = 22
  CHARACTER (LEN=5),DIMENSION(cAbs:cAtan), PARAMETER :: Funcs  = (/ 'abs  ',&
                                                                     'exp  ',&
                                                                     'log10',&
                                                                    'log  ',&
                                                                    'sqrt ',&
                                                                     'sinh ',&
                                                                     'cosh ',&
                                                                     'tanh ',&
                                                                     'sin  ',&
                                                                     'atan '&
/)
CONTAINS
    CHARACTER (LEN=LEN(Funcs))    :: fun
END MODULE fparser
Comment 2 Andrew Pinski 2006-01-01 06:26:47 UTC
Even better reduced testcase:
CHARACTER (LEN=5),DIMENSION(2),PARAMETER :: Funcs = (/'abs  ',&
                                                      'atan '/)
CHARACTER (LEN=LEN(Funcs))    :: fun
 fun = '    '
End
Comment 3 Andrew Pinski 2006-01-02 02:42:17 UTC
Actually the reduced testcase is:
l = LEN((/'atan '/))
End
Comment 4 Paul Thomas 2006-04-23 06:03:29 UTC
This looks to be fixable at trans-intrinsic.c(gfc_conv_intrinsic_len), here a special switch branch for constructors is needed.

I will make it so.

Paul
Comment 5 Paul Thomas 2006-04-24 09:10:28 UTC
(In reply to comment #4)
> This looks to be fixable at trans-intrinsic.c(gfc_conv_intrinsic_len), here a
> special switch branch for constructors is needed.
> I will make it so.
> Paul

This is indeed the case; the ICE comes about because none of the trappings of the scalarizer have been invoked to translate the array constructor.  Rather than do this, I have called trans-array.c (get_array_ctor_strlen) to obtain the string length directly.  This clears the bug; I will regtest tonight and will submit tomorrow.

Comment 6 patchapp@dberlin.org 2006-04-28 08:00:18 UTC
Subject: Bug number PR24813

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-04/msg01075.html
Comment 7 Paul Thomas 2006-05-07 05:46:36 UTC
Subject: Bug 24813

Author: pault
Date: Sun May  7 05:46:26 2006
New Revision: 113594

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113594
Log:
2006-05-07  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/24813
	* trans-array.c (get_array_ctor_strlen): Remove static attribute.
	* trans.h: Add prototype for get_array_ctor_strlen.
	* trans-intrinsic.c (gfc_conv_intrinsic_len): Switch on EXPR_ARRAY
	and call get_array_ctor_strlen.

2006-05-07  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/24813
	* gfortran.dg/char_cons_len_1.f90: New test.



Added:
    trunk/gcc/testsuite/gfortran.dg/char_cons_len.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/fortran/trans.h
    trunk/gcc/testsuite/ChangeLog

Comment 8 Paul Thomas 2006-05-08 05:02:13 UTC
Subject: Bug 24813

Author: pault
Date: Mon May  8 05:01:56 2006
New Revision: 113618

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113618
Log:
2006-05-08  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/24813
	* trans-array.c (get_array_ctor_strlen): Remove static attribute.
	* trans.h: Add prototype for get_array_ctor_strlen.
	* trans-intrinsic.c (gfc_conv_intrinsic_len): Switch on EXPR_ARRAY
	and call get_array_ctor_strlen.

	PR fortran/27269
	* module.c: Add static flag in_load_equiv.
	(mio_expr_ref): Return if no symtree and in_load_equiv.
	(load_equiv): If any of the equivalence members have no symtree, free
	the equivalence and the associated expressions.

	PR fortran/27324
	* trans-common.c (gfc_trans_common): Invert the order of calls to
	finish equivalences and gfc_commit_symbols.

	PR fortran/25099
	* resolve.c (resolve_call): Check conformity of elemental
	subroutine actual arguments.

2006-05-08  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/24813
	* gfortran.dg/char_cons_len.f90: New test.

	PR fortran/27269
	PR fortran/27324
	* gfortran.dg/module_equivalence_2.f90: New test.

	PR fortran/25099
	* gfortran.dg/elemental_subroutine_4.f90: New test.
	* gfortran.dg/assumed_size_refs_1.f90: Add error to non-conforming
	call sub (m, x).



Added:
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/char_cons_len.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/elemental_subroutine_4.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/module_equivalence_2.f90
Modified:
    branches/gcc-4_1-branch/gcc/fortran/ChangeLog
    branches/gcc-4_1-branch/gcc/fortran/module.c
    branches/gcc-4_1-branch/gcc/fortran/resolve.c
    branches/gcc-4_1-branch/gcc/fortran/trans-array.c
    branches/gcc-4_1-branch/gcc/fortran/trans-common.c
    branches/gcc-4_1-branch/gcc/fortran/trans-intrinsic.c
    branches/gcc-4_1-branch/gcc/fortran/trans.h
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/assumed_size_refs_1.f90

Comment 9 Paul Thomas 2006-05-08 06:25:32 UTC
Fixed on trunk and 4.1

Paul