User account creation filtered due to spam.

Bug 37201 - ICE in in gfc_conv_string_parameter
Summary: ICE in in gfc_conv_string_parameter
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 37205 (view as bug list)
Depends on:
Blocks: 32630
  Show dependency treegraph
 
Reported: 2008-08-22 13:47 UTC by francois.jacq
Modified: 2008-08-24 20:31 UTC (History)
2 users (show)

See Also:
Host:
Target: 4.4.0
Build: GNU Fortran (GCC) 4.4.0 20080821 (experimental) [trunk revision
Known to work:
Known to fail:
Last reconfirmed: 2008-08-23 13:07:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description francois.jacq 2008-08-22 13:47:02 UTC
$ gfortran odcdir.f90 cdir.o
odcdir.f90: In function 'test':
odcdir.f90:16: internal compiler error: in gfc_conv_string_parameter, at fortran/trans-expr.c:4009
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

file : odcdir.f90

MODULE mod
  INTERFACE 
    FUNCTION cdir() BIND(C,name="cdir") RESULT(r)
      USE iso_c_binding
      CHARACTER(kind=C_CHAR) :: r
    END FUNCTION
  END INTERFACE
  CONTAINS
  function odcdir() RESULT(c)
    CHARACTER :: c
    c=cdir()
  end function
END MODULE
PROGRAM test
  USE mod
  WRITE(*,*) ICHAR(odcdir())
  WRITE(*,*) ICHAR(cdir())
END PROGRAM

file cdir.c

char cdir(void){return '/';}
Comment 1 Thomas Koenig 2008-08-23 13:07:50 UTC
Confirmed.

Reduced test case:

program test
  INTERFACE
    FUNCTION cdir() BIND(C,name="cdir") RESULT(r)
      CHARACTER(kind=1) :: r
    END FUNCTION
  END INTERFACE
  WRITE(*,*) ICHAR(cdir())
END PROGRAM

Comment 2 Jerry DeLisle 2008-08-23 16:54:49 UTC
Needed a little better summary
Comment 3 Tobias Burnus 2008-08-23 19:13:56 UTC
*** Bug 37205 has been marked as a duplicate of this bug. ***
Comment 4 Tobias Burnus 2008-08-23 19:45:17 UTC
Actually, removing the assert

--- /home/tob/projects/gcc/gcc/fortran/trans-expr.c     (Revision 139520)
+++ /home/tob/projects/gcc/gcc/fortran/trans-expr.c
@@ -4008,2 +4008,0 @@ gfc_conv_string_parameter (gfc_se * se)
-  gcc_assert (se->string_length
-         && TREE_CODE (TREE_TYPE (se->string_length)) == INTEGER_TYPE);

is enough for assignments. Proof:

 str[1]{lb: 1 sz: 1} = cdir ();  ! str = cdir()
 i = (integer(kind=4)) cdir ();  ! i   = ichar(cdir())

TODO: Come up with a better assert which works also in this case.

 * * *

For I/O one also needs the following:

--- trans-io.c  (Revision 139521)
+++ trans-io.c
@@ -2071,2 +2071,6 @@ transfer_expr (gfc_se * se, gfc_typespec
-         gcc_assert (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE);
-         arg2 = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (tmp)));
+
+         /* BIND(C) function return value.  */
+         if (TREE_CODE (TREE_TYPE (tmp)) != ARRAY_TYPE)
+           arg2 = build_int_cst (gfc_charlen_type_node, 1);
+         else
+           arg2 = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (tmp)));
Comment 5 Tobias Burnus 2008-08-24 17:18:09 UTC
Subject: Bug 37201

Author: burnus
Date: Sun Aug 24 17:16:46 2008
New Revision: 139537

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

        PR fortran/37201
        * trans-expr.c (gfc_conv_function_call): Add string_length
        for character-returning bind(C) functions.

2008-08-24  Tobias Burnus  <burnus@net-b.de>

        PR fortran/37201
        * gfortran.dg/bind_c_usage_17.f90: New.
        * gfortran.dg/bind_c_usage_17_c.c: New.


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

Comment 6 Tobias Burnus 2008-08-24 20:31:57 UTC
FIXED on the trunk (4.4).

Thanks for reporting the bug.
Comment 7 Tobias Burnus 2008-08-24 20:32:35 UTC
Subject: Bug 37201

Author: burnus
Date: Sun Aug 24 20:31:09 2008
New Revision: 139545

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

        PR fortran/37201
        * decl.c (verify_bind_c_sym): Reject array/string returning
        functions.

2008-08-24  Tobias Burnus  <burnus@net-b.de>

        PR fortran/37201
        * gfortran.dg/bind_c_18.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/bind_c_18.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog