Bug 40994 - ICE in gfc_undo_symbols
Summary: ICE in gfc_undo_symbols
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2009-08-07 08:17 UTC by Joost VandeVondele
Modified: 2010-08-11 19:30 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.0
Known to fail: 4.4.1 4.5.0
Last reconfirmed: 2010-04-23 20:17:34


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joost VandeVondele 2009-08-07 08:17:25 UTC
The following semi-invalid code ICEs (but compiles fine with ifort):

MODULE f03_test
 USE, INTRINSIC :: ISO_C_BINDING
 INTERFACE
    FUNCTION build(lib, np) BIND(C)
    END FUNCTION
 END INTERFACE
 PROCEDURE(build), POINTER               :: pbuild
CONTAINS
 SUBROUTINE test_asc()
 END SUBROUTINE test_asc
 SUBROUTINE test_bind_c BIND(C,name="test_bind_c")
 END SUBROUTINE test_bind_c
END MODULE f03_test
END
Comment 1 Joost VandeVondele 2009-08-07 09:15:19 UTC
for reference:

elete_root (t=0x1306d40) at /data03/vondele/gcc_trunk/gcc/gcc/fortran/bbt.c:149
149       if (t->left->priority > t->right->priority)
(gdb) bt
#0  delete_root (t=0x1306d40) at /data03/vondele/gcc_trunk/gcc/gcc/fortran/bbt.c:149
#1  0x00000000004a5bdf in gfc_delete_bbt (root=0x1306340, old=0x1306d40, compare=0)
    at /data03/vondele/gcc_trunk/gcc/gcc/fortran/bbt.c:196
#2  0x0000000000524c73 in gfc_delete_symtree (root=0x1306340, name=0x12fe970 "")
    at /data03/vondele/gcc_trunk/gcc/gcc/fortran/symbol.c:2299
#3  0x0000000000524d27 in gfc_undo_symbols () at /data03/vondele/gcc_trunk/gcc/gcc/fortran/symbol.c:2751
#4  0x00000000004fa2d5 in decode_statement () at /data03/vondele/gcc_trunk/gcc/gcc/fortran/parse.c:268
#5  0x00000000004fb485 in next_statement () at /data03/vondele/gcc_trunk/gcc/gcc/fortran/parse.c:708
#6  0x00000000004fea1a in gfc_parse_file () at /data03/vondele/gcc_trunk/gcc/gcc/fortran/parse.c:3924
#7  0x0000000000532ead in gfc_be_parse_file (set_yydebug=<value optimized out>)
    at /data03/vondele/gcc_trunk/gcc/gcc/fortran/f95-lang.c:241
#8  0x0000000000800433 in toplev_main (argc=13, argv=0x7fff4b9e7a08) at /data03/vondele/gcc_trunk/gcc/gcc/toplev.c:1026
#9  0x00007f094264a436 in __libc_start_main () from /lib64/libc.so.6
#10 0x000000000049e259 in _start ()
Comment 2 janus 2009-08-07 09:27:05 UTC
Before the ICE one gets the error:

 SUBROUTINE test_bind_c BIND(C,name="test_bind_c")
                                                  1
Error: Missing required parentheses before BIND(C) at (1)

If this error is corrected, the ICE goes away.
Comment 3 Joost VandeVondele 2009-08-07 10:11:34 UTC
(In reply to comment #2)
> Before the ICE one gets the error:
> 
>  SUBROUTINE test_bind_c BIND(C,name="test_bind_c")
>                                                   1

that's why I called the testcase semi-invalid. Note that g95/ifort/NAG appear to allow this (non-standard) variant. 

Comment 4 Dominique d'Humieres 2010-04-18 15:49:36 UTC
Still there on trunk -> should be marked as NEW.
Comment 5 Joost VandeVondele 2010-04-23 20:17:34 UTC
as per comment #4, and reconfirmed for trunk
Comment 6 Daniel Franke 2010-05-07 22:09:55 UTC
Not related to ISO-C.

Reduced test case:
MODULE f03_test
 INTERFACE
    INTEGER FUNCTION build(lib, np)
    END FUNCTION
 END INTERFACE
 PROCEDURE(build), POINTER :: pbuild
CONTAINS
   XXXX                        ! simply generate any error
END MODULE f03_test

end


daniel@silence:~/pr$ valgrind /home/daniel/i686-pc-linux-gnu/gcc/libexec/gcc/i686-pc-linux-gnu/4.6.0/f951 pr40994.f90
==20641== Memcheck, a memory error detector
==20641== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==20641== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==20641== Command: /home/daniel/i686-pc-linux-gnu/gcc/libexec/gcc/i686-pc-linux-gnu/4.6.0/f951 pr40994.f90
==20641== 
pr40994.f90:10.50:

 SUBROUTINE test_bind_c BIND(C,name="test_bind_c")
                                                  1
Error: Missing required parentheses before BIND(C) at (1)
pr40994.f90:11.4:

 END SUBROUTINE test_bind_c
    1
Error: Expecting END MODULE statement at (1)
pr40994.f90:4.30-26:

    INTEGER FUNCTION build(lib, np) BIND(C)
                          2   1
Warning: Implicitly declared variable 'lib' at (1) may not be C interoperable but it is a dummy argument to the BIND(C) procedure 'build' at (2)
pr40994.f90:4.34-26:

    INTEGER FUNCTION build(lib, np) BIND(C)
                          2       1
Warning: Implicitly declared variable 'np' at (1) may not be C interoperable but it is a dummy argument to the BIND(C) procedure 'build' at (2)
pr40994.f90:4.26:

    INTEGER FUNCTION build(lib, np) BIND(C)
                          1
Warning: Variable 'build' at (1) may not be a C interoperable kind but it is bind(c)
==20641== Invalid read of size 4
==20641==    at 0x81578A2: gfc_undo_symbols (symbol.c:2813)
==20641==    by 0x8125CE6: decode_statement (parse.c:271)
==20641==    by 0x81277D0: next_free (parse.c:722)
==20641==    by 0x8127BB9: next_statement (parse.c:907)
==20641==    by 0x812BD8D: gfc_parse_file (parse.c:4220)
==20641==    by 0x8167059: gfc_be_parse_file (f95-lang.c:239)
==20641==    by 0x8481F2A: compile_file (toplev.c:1053)
==20641==    by 0x4131BD5: (below main) (libc-start.c:226)
==20641==  Address 0x430a910 is 136 bytes inside a block of size 296 free'd
==20641==    at 0x4024B3A: free (vg_replace_malloc.c:366)
==20641==    by 0x815710F: gfc_free_symbol (symbol.c:2485)
==20641==    by 0x8157FEF: free_sym_tree (symbol.c:3087)
==20641==    by 0x81582AD: gfc_free_namespace (symbol.c:3231)
==20641==    by 0x81570C7: gfc_free_symbol (symbol.c:2476)
==20641==    by 0x8157FEF: free_sym_tree (symbol.c:3087)
==20641==    by 0x8157F5B: free_sym_tree (symbol.c:3068)
==20641==    by 0x8157F5B: free_sym_tree (symbol.c:3068)
==20641==    by 0x8157F5B: free_sym_tree (symbol.c:3068)
==20641==    by 0x8157F5B: free_sym_tree (symbol.c:3068)
==20641==    by 0x8157F5B: free_sym_tree (symbol.c:3068)
==20641==    by 0x81582AD: gfc_free_namespace (symbol.c:3231)
[...]
Comment 7 Dominique d'Humieres 2010-07-26 13:30:51 UTC
This pr looks like a duplicate of pr37744, or at least the ICEs disappear with -fwhole-file (now the default: see http://gcc.gnu.org/ml/gcc-bugs/2010-07/msg02853.html#c9 ).
Comment 8 janus 2010-08-11 19:30:44 UTC
Both comment #0 and comment #6 work for me without ICE on 4.6 trunk r163095. Closing as fixed.