User account creation filtered due to spam.

Bug 34248 - ICE on assumed length character function
Summary: ICE on assumed length character function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-11-27 12:30 UTC by francois.jacq
Modified: 2007-11-29 17:43 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.1.3 4.2.2 4.3.0
Last reconfirmed: 2007-11-27 13:48:47


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description francois.jacq 2007-11-27 12:30:08 UTC
I tried to find without success a simular bug with CHARACTER(*) function :

Files test5.f90 :

FUNCTION ctbgt() RESULT(ctab)
  CHARACTER(*) :: ctab
END

lcoul@b07p0012:~/test$ gfortran -c test5.f90
test5.f90: In function 'ctbgt':
test5.f90:2: 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.
Comment 1 Paul Thomas 2007-11-27 13:48:47 UTC
Confirmed.

gcc-4.2.0 20061221 (prerelease) gives

FUNCTION ctbgt() RESULT(ctab)
             1
Warning: CHARACTER(*) function 'ctbgt' at (1) is obsolescent in fortran 95
pr34248.f90: In function 'ctbgt':
pr34248.f90:1: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

4.3.0 requires -std=f95 to get the benefit of the warning.

However, the ICE certainly occurs - have changed the title to reflect this.

Note that the F77 version works OK:

CHARACTER(*) FUNCTION ctbgt()
  ctbgt = ""
END

Thanks for the report.

Paul
Comment 2 Tobias Burnus 2007-11-27 22:09:44 UTC
No regression. Valgrind shows:

==21714== Invalid read of size 4
==21714==    at 0x49C077: generate_local_decl (trans-decl.c:2980)
==21714==    by 0x471026: traverse_ns (symbol.c:2951)
==21714==    by 0x499FFD: gfc_generate_function_code (trans-decl.c:3081)
==21714==    by 0x4558AB: gfc_parse_file (parse.c:3399)
==21714==    by 0x47DA34: gfc_be_parse_file (f95-lang.c:258)
==21714==    by 0x6EDC54: toplev_main (toplev.c:1042)
==21714==    by 0x52CBB29: (below main) (in /lib64/libc-2.6.1.so)

> Note that the F77 version works OK:
Well, it works without RESULT. Using the following also crashes:

character(*) FUNCTION ctbgt()  RESULT(ctab)
END

The following patch fixes it. Or is it only a stupid workaround?

In the following, "sym->ts.cl->length" == NULL

Index: trans-decl.c
===================================================================
--- trans-decl.c        (revision 130466)
+++ trans-decl.c        (working copy)
@@ -2978,7 +2978,9 @@
   int i;

   if (sym->ts.type == BT_CHARACTER
-       && sym->ts.cl->length->expr_type != EXPR_CONSTANT)
+      && sym->ts.cl
+      && sym->ts.cl->length
+      && sym->ts.cl->length->expr_type != EXPR_CONSTANT)
     generate_expr_decls (sym, sym->ts.cl->length);
Comment 3 Tobias Burnus 2007-11-29 17:41:54 UTC
Subject: Bug 34248

Author: burnus
Date: Thu Nov 29 17:41:37 2007
New Revision: 130517

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

        PR fortran/34248
        * trans-decl.c (generate_dependency_declarations): Check
        for NULL pointers before accessing the string length.

2007-11-29  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34248
        * gfortran.dg/result_in_spec_3.f90: New.


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

Comment 4 Tobias Burnus 2007-11-29 17:43:43 UTC
FIXED on the trunk (4.3.0). I do not intent to backport the fix to 4.2.x or 4.1.x, but I can be convinced to do so.
Comment 5 Jerry DeLisle 2007-11-30 17:56:09 UTC
Subject: Bug 34248

Author: jvdelisle
Date: Fri Nov 30 17:55:55 2007
New Revision: 130542

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

	PR fortran/34248
	* gfortran.dg/result_in_spec_3.f90: Add dg-option -std=gnu.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/result_in_spec_3.f90