Bug 38095 - character ICE
Summary: character ICE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P4 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 38119
  Show dependency treegraph
 
Reported: 2008-11-12 18:56 UTC by Vivek Rao
Modified: 2008-11-16 14:21 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-11-12 22:37:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vivek Rao 2008-11-12 18:56:58 UTC
Compiling

module bar
implicit none
contains
!
elemental function trim_append(xx,yy) result(xy)
character (len=*), intent(in) :: xx,yy
character (len=len(xx) + len(yy)) :: xy
xy = trim(xx) // yy
end function trim_append
!
function same(xx) result(yy)
character (len=*), intent(in) :: xx(:)
character (len=len(xx))       :: yy(size(xx))
yy = [xx]
end function same
!
subroutine foo(labels)
character (len=*), intent(in) :: labels(:)
print*,"size(labels)=",size(labels)
end subroutine foo
!
subroutine xmain()
call foo(trim_append(["a"],same(["b"])))
end subroutine xmain
!
end module bar

with

gfortran -c xchar_bug.f90

I get

xchar_bug.f90: In function 'xmain':
xchar_bug.f90:5: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

gfortran -v says

gfortran -v
Built by Equation Solution (http://www.Equation.com).
Using built-in specs.
Target: i386-pc-mingw32
Configured with: ../gcc-4.4-20081107-mingw/configure --host=i386-pc-mingw32 --build=x86_64-unknown-linux-gnu --target=i386-pc-mingw32 --prefix=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.4-20081107 --with-gcc --with-gnu-ld --with-gnu-as --disable-shared --disable-nls --disable-tls --with-gmp=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gmp --with-mpfr=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/mpfr --enable-languages=c,c++,fortran --with-sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.4-20081107 --enable-libgomp --enable-threads=win32 --disable-win32-registry : (reconfigured) ../gcc-4.4-20081107-mingw/configure --host=i386-pc-mingw32 --build=x86_64-unknown-linux-gnu --target=i386-pc-mingw32 --prefix=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.4-20081107 --with-gcc --with-gnu-ld --with-gnu-as --disable-shared --disable-nls --disable-tls --with-gmp=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gmp --with-mpfr=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/mpfr --enable-languages=c,c++,fortran --with-sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.4-20081107 --enable-libgomp --enable-threads=win32 --disable-win32-registry : (reconfigured) ../gcc-4.4-20081107-mingw/configure --host=i386-pc-mingw32 --build=x86_64-unknown-linux-gnu --target=i386-pc-mingw32 --prefix=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.4-20081107 --with-gcc --with-gnu-ld --with-gnu-as --disable-shared --disable-nls --disable-tls --with-gmp=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gmp --with-mpfr=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/mpfr --enable-languages=c,c++,fortran --with-sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.4-20081107 --enable-libgomp --enable-threads=win32 --disable-win32-registry
Thread model: win32
gcc version 4.4.0 20081107 (experimental) (GCC)
Comment 1 kargls 2008-11-12 20:27:59 UTC
While gfortran should not ICE, I'd be interested in knowing if
this code compiles with any other compiler. (Hint: remove
elemental from trim_append).
Comment 2 kargls 2008-11-12 20:29:25 UTC
Add ice-on-invalid-code to keywords.
Comment 3 kargls 2008-11-12 20:39:30 UTC
Whoop, it is valid Fortran 2003.  I forgot that
Lahey's checker does not understand the F2003
array syntax.
Comment 4 Dominique d'Humieres 2008-11-12 21:09:19 UTC
> Whoop, it is valid Fortran 2003.  I forgot that
> Lahey's checker does not understand the F2003 array syntax.

I was about to say that the code is compiled by ifort and g95.

Comment 5 Vivek Rao 2008-11-12 22:12:11 UTC
(In reply to comment #4)
> > Whoop, it is valid Fortran 2003.  I forgot that
> > Lahey's checker does not understand the F2003 array syntax.
> I was about to say that the code is compiled by ifort and g95.

I hope someone will mark the bug as "confirmed".
Comment 6 Dominique d'Humieres 2008-11-12 22:26:44 UTC
> I hope someone will mark the bug as "confirmed".

I have tried, but If I am allowed to do it, I did not find how. Did you try yourself?

Comment 7 Tobias Burnus 2008-11-12 22:37:24 UTC
Looks as if the code is valid. Valgrind shows:

==2910== Invalid read of size 4
==2910==    at 0x4B1005: gfc_apply_interface_mapping_to_expr (trans-expr.c:1916)
==2910==    by 0x4B6FBE: gfc_apply_interface_mapping (trans-expr.c:2133)
==2910==    by 0x49D13E: gfc_conv_expr_descriptor (trans-array.c:4717)
==2910==    by 0x4A033B: gfc_conv_array_parameter (trans-array.c:5272)
==2910==    by 0x4B1A80: gfc_conv_function_call (trans-expr.c:2680)

That line is:

  switch (expr->value.function.isym->id)
    {
    case GFC_ISYM_LEN:
      /* TODO figure out why this condition is necessary.  */
      if (sym->attr.function
            && arg1->ts.cl->length->expr_type != EXPR_CONSTANT
            && arg1->ts.cl->length->expr_type != EXPR_VARIABLE) // <- LINE 1916

The TODO was added by Paul in Rev. 130988. The cited bugreports were
PR 31213, PR 33888 and PR 33998.
Comment 8 Mikael Morin 2008-11-12 22:43:09 UTC
I tried to reduce the case. 


module bar
implicit none
contains
!
elemental function trim_append(xx,yy) result(xy)
character (len=*), intent(in) :: xx,yy
character (len=len(xx) + len(yy)) :: xy
xy = xx // yy
end function trim_append
!
function same(xx) result(yy)
character (len=*), intent(in) :: xx(:)
character (len=len(xx))       :: yy(size(xx))
yy = xx
end function same
!
subroutine xmain()
character(len=2) :: c(1)
c =  trim_append(["a"],same(["b"]))
end subroutine xmain
!
end module bar


pr38095.f90:5: erreur interne du compilateur: dans gfc_trans_create_temp_array, à fortran/trans-array.c:648
Veuillez soumettre un rapport complet d'anomalies,
avec le source pré-traité si nécessaire.
Consultez <http://gcc.gnu.org/bugs.html> pour plus de détail.



I bet some of you guys recognize that old friend of ours, PR31610, whose patch was reverted in PR37903.
Of course characters are a special (understand: not working) case. Argh!

This is probably unrelated to the original ICE though. 
 
Comment 9 kargls 2008-11-12 23:02:15 UTC
The problem appears to be with the reference to SAME() in

  subroutine xmain()
  call foo(trim_append(["a"],same(["b"])))
  end subroutine xmain

If one changes this to 

 call foo(trim_append(["a"],["b"]))

the code compiles.  So, it appears that a temporary array is not
be probably created.
 
Comment 10 Tobias Burnus 2008-11-12 23:42:01 UTC
Some debugging shows that sym->name is "same" and sym->attr.function == 1. Furthermore is arg1->expr_type == EXPR_FUNCTION and arg1->ts.cl->length == NULL.

(For cross referencing: http://gcc.gnu.org/ml/fortran/2007-12/msg00160.html is the mail to the patch which added the TODO line.)

Using the following patch and calling xmain, the program prints
"size(labels)= 1".


--- trans-expr.c        (Revision 141811)
+++ trans-expr.c
@@ -1912,8 +1912,9 @@ gfc_map_intrinsic_function (gfc_expr *ex
     case GFC_ISYM_LEN:
       /* TODO figure out why this condition is necessary.  */
       if (sym->attr.function
-           && arg1->ts.cl->length->expr_type != EXPR_CONSTANT
-           && arg1->ts.cl->length->expr_type != EXPR_VARIABLE)
+         && (arg1->ts.cl->length == NULL
+             || (arg1->ts.cl->length->expr_type != EXPR_CONSTANT
+                 && arg1->ts.cl->length->expr_type != EXPR_VARIABLE)))
        return false;

       new_expr = gfc_copy_expr (arg1->ts.cl->length);
Comment 11 Tobias Burnus 2008-11-12 23:45:09 UTC
(In reply to comment #8)
> I tried to reduce the case. 
> This is probably unrelated to the original ICE though. 

Looks unrelated, but still should be fixed; I think ICE from comment 8 is a regression with regards to gfortran 4.1, 4.2 and 4.3.
Comment 12 Tobias Burnus 2008-11-15 10:33:15 UTC
(In reply to comment #11)
> > I tried to reduce the case. 
> > This is probably unrelated to the original ICE though. 
> Looks unrelated, but still should be fixed; I think ICE from comment 8 is a
> regression with regards to gfortran 4.1, 4.2 and 4.3.

I filled PR38119 for that PR.

For my patch, it worked at least for the test case, since I currently cannot boot strap (PPL linking problem), I cannot regtest :-(
If someone wants to take over ...
Comment 13 Paul Thomas 2008-11-15 17:40:01 UTC
(In reply to comment #12)

> I filled PR38119 for that PR.

This is probably stupid but what is the difference between the two PRs?

Paul
Comment 14 Tobias Burnus 2008-11-15 18:06:10 UTC
(In reply to comment #13)
> > I filled PR38119 for that PR.
> This is probably stupid but what is the difference between the two PRs?

The program of comment 0 of this PR (PR 38095) gives an ICE with all gfortran versions and is fixed by the patch in comment 10.

The program of comment 8 and thus of PR 38119 fails only with gfortran 4.4 (= regression) and ICEs at a completely different place.
Comment 15 Paul Thomas 2008-11-16 12:22:01 UTC
(In reply to comment #14)
> (In reply to comment #13)
> > > I filled PR38119 for that PR.
> > This is probably stupid but what is the difference between the two PRs?

'twas stupid - I missed the difference between the testcases:-(

Paul
Comment 16 Tobias Burnus 2008-11-16 14:21:02 UTC
Subject: Bug 38095

Author: burnus
Date: Sun Nov 16 14:19:38 2008
New Revision: 141917

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141917
Log:
2008-11-16  Tobias Burnus  <burnus@net-b.de>

        PR fortran/38095
        * trans-expr.c (gfc_map_intrinsic_function): Fix pointer access.

2008-11-16  Tobias Burnus  <burnus@net-b.de>

        PR fortran/38095
        * gfortran.dg/char_length_13.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/char_length_13.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog

Comment 17 Tobias Burnus 2008-11-16 14:21:16 UTC
FIXED on the trunk (4.4.0). Thanks for the report!