Bug 41044 - internal compiler error: in gfc_conv_intrinsic_function
Summary: internal compiler error: in gfc_conv_intrinsic_function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.1
: P3 normal
Target Milestone: 4.4.4
Assignee: Paul Thomas
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 32834 42361
  Show dependency treegraph
 
Reported: 2009-08-12 15:34 UTC by ros
Modified: 2010-02-07 03:39 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.5.0 4.3.2 4.4.1
Last reconfirmed: 2010-01-25 07:53:09


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ros 2009-08-12 15:34:53 UTC
Gfortran fails to compile the module rsplot.F95 with the following error message:
rsplot.F95: In function ‘ps_init’:
rsplot.F95:295: internal compiler error: Unexpected type in truthvalue_conversion
My compile command is 'gfortran -c -fdefault-real-8 -fno-backslash rsplot.F95'
The module rsplot.F95 uses the module rsutil.F95 wich has to be compiled with
the same options first.  This compilation runs without problems.  Both files
compile well with other Fortran compilers like IBM XLF, Intel or the g95 .

gcc -v gives
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --with-slibdir=/lib --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --program-suffix=-4.3 --enable-version-specific-runtime-libs --enable-linux-futex --without-system-libunwind --with-cpu=generic --build=i586-suse-linux
Thread model: posix
gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036] (SUSE Linux)

uname -a gives
Linux ros-nb 2.6.25.20-0.4-pae #1 SMP 2009-06-01 09:57:12 +0200 i686 i686 i386 GNU/Linux
Comment 1 ros 2009-08-12 16:05:44 UTC
Unfortunately I am unable to find out how to attach the two Fortran source-code files that are needed to reproduce the bug :(
Comment 2 Tobias Burnus 2009-08-13 08:17:44 UTC
> Unfortunately I am unable to find out how to attach the two Fortran source-code
> files that are needed to reproduce the bug :(

Well, you cannot when you initially fill the bug (only in newer versions of Bugzilla). But you can attach them - one by one - after you filled the bug. Simply go to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41044 and click on "Create a New Attachment"

Comment 3 Joost VandeVondele 2009-09-27 17:13:02 UTC
source see:

http://www.rzg.mpg.de/~ros/WaveProp/

confirmed ICE, reducing
Comment 4 Joost VandeVondele 2009-09-27 17:13:33 UTC
classpath?
Comment 5 Joost VandeVondele 2009-09-27 17:44:44 UTC
reduced:

> cat bug.f90
    Subroutine PS_INIT (bkgd, punit, pform, psize, rot90, bbox, clip, eps,  &
                        caller)
    type psfd                          ! paper size and frame defaults
      character(3)                     :: n
      real                             :: p(2)
      real                             :: f(4)
    end type psfd
    character                          :: fn*4, orich, pfmt*16
    type(psfd), parameter              :: pfd(0:11)=(/  &
         psfd('   ',(/   0.0,   0.0/),(/200.,120.,800.,560./)), &    ! A0_L
         psfd('A0 ',(/ 840.9,1189.2/),(/140., 84.,560.,400./)), &    ! A0_P
         psfd('A1 ',(/ 594.6, 840.9/),(/100., 60.,400.,280./)), &    ! A1_P
         psfd('A2 ',(/ 420.4, 594.6/),(/ 70., 42.,280.,200./)), &    ! A2_P
         psfd('A3 ',(/ 297.3, 420.4/),(/ 50., 30.,200.,140./)), &    ! A3_P
         psfd('A4 ',(/ 210.2, 297.3/),(/ 35., 21.,140.,100./)), &    ! A4_P
         psfd('A5 ',(/ 148.7, 210.2/),(/ 25., 15.,100., 70./)), &    ! A5_P
         psfd('A6 ',(/ 105.1, 148.7/),(/ 18., 11., 70., 50./)), &    ! A6_P
         psfd('   ',(/   0.0,   0.0/),(/ 50., 30.,200.,140./)), &    ! Letter_L
         psfd('LET',(/ 215.9, 279.4/),(/ 35., 21.,140.,100./)), &    ! Letter_P
         psfd('   ',(/   0.0,   0.0/),(/ 50., 30.,200.,140./)), &    ! Legal_L
         psfd('LEG',(/ 215.9, 355.6/),(/ 35., 21.,140.,100./))/)     ! Legal_P
    if (len_trim(pfmt) > 0) then       ! set paper format
      idx=sum(maxloc(index(pfd%n,pfmt(1:3))))-1
    end if
    end subroutine PS_INIT
Comment 6 ros 2009-10-09 13:51:53 UTC
(In reply to comment #5)
I have further reducd the test code to:
idx=sum(maxloc(index(pfd%n,pfmt)))-1
    Program GF_BUG
!
    type psfd
      character              :: n*3
    end type psfd
    character                :: pfmt*3=''
    type(psfd), parameter    :: pfd(1)=[psfd('')]
!
    idx=sum(maxloc(index(pfd%n,pfmt)))-1
    end

For the error message to appear it is essential
- that the variable 'psfd' is of derived type,
- that the type declaration statement for 'pdf' has the attribute PARAMETER
- and the statement 'idx=sum(maxloc(index(pfd%n,pfmt)))-1' exists in this form.
Splitting up this statement into 
  'idx=sum(maxloc(index(pfd%n,pfmt)))'   and
  'idx=idx-1'
makes the error message disappear!

I hope, this helps for fixing the bug.
Comment 7 Tobias Burnus 2009-10-09 21:59:51 UTC
(In reply to comment #6)
>     idx=sum(maxloc(index(pfd%n,pfmt)))-1

The problem is that "pfd%n" is simplified to an array constructor [''] of type expr->value.constructor->ts == CHARACTER(kind=1,len=3).

But this typespec is not propagated to expr->ts while doing the simplification and thus expr->ts is BT_DERIVED and expr->ts.kind == 0 - which causes the assert to trigger. If one applies the hack below, one continues a bit further but ends up having an ICE in gfc_conv_string_parameter's
  gcc_assert (POINTER_TYPE_P (TREE_TYPE (se->expr)))

The proper solutions is presumably to find the spot in array.c or expr.c where the derived-type constructor is simplified into an character constructor; there at least updating the expr->ts is missing.


Not working hack (ICE in gfc_conv_string_parameter):

--- trans-intrinsic.c   (Revision 152601)
+++ trans-intrinsic.c   (Arbeitskopie)
@@ -5340,2 +5340,5 @@ gfc_conv_intrinsic_function (gfc_se * se
     case GFC_ISYM_INDEX:
+      if (expr->value.function.actual->expr->expr_type == EXPR_ARRAY)
+       expr->value.function.actual->expr->ts
+         = expr->value.function.actual->expr->value.constructor->expr->ts;
       kind = expr->value.function.actual->expr->ts.kind;
Comment 8 Tobias Burnus 2009-10-12 09:33:44 UTC
> I have further reducd the test code to:
> idx=sum(maxloc(index(pfd%n,pfmt)))-1

Even shorter:
    idx = index(pfd%n,pfmt) - 1
(Or any other one/two operator expression except of function calls; idx needs to be a rank-1 array.)

Another issue (or the same?) is that pfd%n is seen as EXPR_VARIABLE and not as EXPR_CONSTANT. The following vaguely related gives a segfault:

type t
  integer :: i
end type t
type(t), parameter :: a(1) = t(4)
real(a(1)%i) :: b
end

==27247== Invalid read of size 8
==27247==    at 0x4C3CDD: simplify_const_ref (expr.c:1168)

simplify_const_ref (p=<value optimized out>) at /home/tob/projects/gcc/gcc/fortran/expr.c:1559
1559              remove_subobject_ref (p, cons);

Seemingly, the segfault is in remove_subobject_ref, called by simplify_const_ref (and "cons" being not a valid pointer).
        case REF_COMPONENT:
          cons = find_component_ref (p->value.constructor, p->ref);
          remove_subobject_ref (p, cons);
Comment 9 Jerry DeLisle 2010-01-14 13:45:34 UTC
The test case in comment #8 is a separate issue.  The constructor pointer is coming out of find_component_ref as invalid.  I am still working on it.
Comment 10 Jerry DeLisle 2010-01-23 14:03:29 UTC
As Paul would say, I am flummoxed. In remove_subobject_ref at line expr.c:1159   e->ref = p->ref->next;  p->ref is NULL, resulting in the segfault.  I have been unable to conjure a solution.
Comment 11 Paul Thomas 2010-01-24 17:00:07 UTC
Subject: Bug 41044

Author: pault
Date: Sun Jan 24 16:59:51 2010
New Revision: 156197

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156197
Log:
2010-01-24  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/41044
	PR fortran/41167
	* expr.c (remove_subobject_ref): If the constructor is NULL use
	the expression as the source.
	(simplify_const_ref): Change the type of expression if
	there are component references.  Allow for substring to be at
	the end of an arbitrarily long chain of references.  If an
	element is found that is not in an EXPR_ARRAY, assume that this
	is scalar initialization of array. Call remove_subobject_ref in
	this case with NULL second argument.

2010-01-24  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/41044
	* gfortran.dg/parameter_array_ref_2.f90 : New test.

	PR fortran/41167
	* gfortran.dg/char_array_arg_1.f90 : New test.

	* gfortran.dg/pr25923.f90 : Remove XFAIL.

Added:
    trunk/gcc/testsuite/gfortran.dg/char_array_arg_1.f90
    trunk/gcc/testsuite/gfortran.dg/parameter_array_ref_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/pr25923.f90

Comment 12 Paul Thomas 2010-01-25 07:53:09 UTC
I just posted the patch for this, so could take it with some advantage.  Will correct 4.4 in a few days.

Paul
Comment 13 Paul Thomas 2010-01-30 21:13:16 UTC
Subject: Bug 41044

Author: pault
Date: Sat Jan 30 21:12:59 2010
New Revision: 156389

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156389
Log:
2010-01-30  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/41044
	PR fortran/41167
	* expr.c (remove_subobject_ref): If the constructor is NULL use
	the expression as the source.
	(simplify_const_ref): Change the type of expression if
	there are component references.  Allow for substring to be at
	the end of an arbitrarily long chain of references.  If an
	element is found that is not in an EXPR_ARRAY, assume that this
	is scalar initialization of array. Call remove_subobject_ref in
	this case with NULL second argument.

2010-01-30  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/41044
	* gfortran.dg/parameter_array_ref_2.f90 : New test.

	PR fortran/41167
	* gfortran.dg/char_array_arg_1.f90 : New test.

	* gfortran.dg/pr25923.f90 : Remove XFAIL.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/char_array_arg_1.f90
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/parameter_array_ref_2.f90
Modified:
    branches/gcc-4_4-branch/gcc/fortran/ChangeLog
    branches/gcc-4_4-branch/gcc/fortran/expr.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog

Comment 14 Paul Thomas 2010-01-30 21:14:49 UTC
Fixed on trunk and 4.4.

Thanks for the report

Paul