[Bug fortran/68800] New: Fortran FE produces many memory leaks

marxin at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Dec 8 17:19:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68800

            Bug ID: 68800
           Summary: Fortran FE produces many memory leaks
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 36964
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36964&action=edit
test-case

Hello.

As mentioned in https://gcc.gnu.org/ml/gcc-patches/2015-12/msg00878.html,
Fortran FE produces really a lot of memory leaks, where the most common (having
>=1000 occurrences in test-suite)  are:

are definitely lost: 3099 occurences
  calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  xcalloc (xmalloc.c:163)
  gfc_match_actual_arglist(int, gfc_actual_arglist**) (primary.c:1758)
  gfc_match_rvalue(gfc_expr**) (primary.c:2989)
  match_primary (matchexp.c:157)
  match_level_1 (matchexp.c:211)
  match_mult_operand(gfc_expr**) (matchexp.c:267)
  match_add_operand(gfc_expr**) (matchexp.c:356)
  match_level_2(gfc_expr**) (matchexp.c:480)
  match_level_3(gfc_expr**) (matchexp.c:551)
  match_level_4 (matchexp.c:599)
  match_and_operand(gfc_expr**) (matchexp.c:693)
  match_or_operand(gfc_expr**) (matchexp.c:722)
  match_equiv_operand(gfc_expr**) (matchexp.c:765)
  match_level_5(gfc_expr**) (matchexp.c:811)

are definitely lost: 2004 occurences
  calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  xcalloc (xmalloc.c:163)
  gfc_get_namespace(gfc_namespace*, int) (symbol.c:2508)
  generate_finalization_wrapper (class.c:1589)
  gfc_find_derived_vtab(gfc_symbol*) (class.c:2406)
  resolve_fl_derived(gfc_symbol*) (resolve.c:13389)
  resolve_symbol(gfc_symbol*) (resolve.c:13669)
  do_traverse_symtree(gfc_symtree*, void (*)(gfc_symtree*), void
(*)(gfc_symbol*)) (symbol.c:3817)
  resolve_types(gfc_namespace*) (resolve.c:15443)
  gfc_resolve(gfc_namespace*) [clone .part.47] (resolve.c:15553)
  gfc_parse_file() (parse.c:5757)
  gfc_be_parse_file() (f95-lang.c:201)
  compile_file() (toplev.c:464)

are definitely lost: 1476 occurences
  calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  xcalloc (xmalloc.c:163)
  gfc_get_typebound_proc(gfc_typebound_proc*) (symbol.c:4669)
  match_procedure_in_type (decl.c:8749)
  gfc_match_procedure() (decl.c:5480)
  match_word(char const*, match (*)(), locus*) [clone .part.4] (parse.c:65)
  decode_statement() (parse.c:531)
  next_free (parse.c:1076)
  next_statement() (parse.c:1310)
  parse_derived_contains (parse.c:2549)
  parse_derived (parse.c:2751)
  parse_spec(gfc_statement) (parse.c:3368)
  parse_module() (parse.c:5421)
  gfc_parse_file() (parse.c:5737)
  gfc_be_parse_file() (f95-lang.c:201)
  compile_file() (toplev.c:464)

are definitely lost: 1413 occurences
  calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  xcalloc (xmalloc.c:163)
  gfc_get_expr() (expr.c:48)
  gfc_get_structure_constructor_expr(bt, int, locus*) (expr.c:127)
  gfc_class_initializer(gfc_typespec*, gfc_expr*) (class.c:450)
  gfc_conv_initializer(gfc_expr*, gfc_typespec*, tree_node*, bool, bool, bool)
(trans-expr.c:6662)
  gfc_get_symbol_decl(gfc_symbol*) (trans-decl.c:1686)
  generate_local_decl(gfc_symbol*) (trans-decl.c:5149)
  do_traverse_symtree(gfc_symtree*, void (*)(gfc_symtree*), void
(*)(gfc_symbol*)) (symbol.c:3817)
  generate_local_vars (trans-decl.c:5339)
  gfc_generate_function_code(gfc_namespace*) (trans-decl.c:6018)
  translate_all_program_units (parse.c:5612)
  gfc_parse_file() (parse.c:5818)
  gfc_be_parse_file() (f95-lang.c:201)

are definitely lost: 1401 occurences
  calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  xcalloc (xmalloc.c:163)
  gfc_get_namespace(gfc_namespace*, int) (symbol.c:2508)
  generate_finalization_wrapper (class.c:1589)
  gfc_find_derived_vtab(gfc_symbol*) (class.c:2406)
  resolve_fl_derived(gfc_symbol*) (resolve.c:13389)
  resolve_symbol(gfc_symbol*) (resolve.c:13669)
  do_traverse_symtree(gfc_symtree*, void (*)(gfc_symtree*), void
(*)(gfc_symbol*)) (symbol.c:3817)
  resolve_types(gfc_namespace*) (resolve.c:15443)
  gfc_resolve(gfc_namespace*) [clone .part.47] (resolve.c:15553)
  resolve_all_program_units (parse.c:5551)
  gfc_parse_file() (parse.c:5803)
  gfc_be_parse_file() (f95-lang.c:201)
  compile_file() (toplev.c:464)

are definitely lost: 1219 occurences
  calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  xcalloc (xmalloc.c:163)
  gfc_match_actual_arglist(int, gfc_actual_arglist**) (primary.c:1758)
  gfc_match_rvalue(gfc_expr**) (primary.c:3200)
  match_primary (matchexp.c:157)
  match_level_1 (matchexp.c:211)
  match_mult_operand(gfc_expr**) (matchexp.c:267)
  match_add_operand(gfc_expr**) (matchexp.c:356)
  match_level_2(gfc_expr**) (matchexp.c:480)
  match_level_3(gfc_expr**) (matchexp.c:551)
  match_level_4 (matchexp.c:599)
  match_and_operand(gfc_expr**) (matchexp.c:693)
  match_or_operand(gfc_expr**) (matchexp.c:722)
  match_equiv_operand(gfc_expr**) (matchexp.c:765)
  match_level_5(gfc_expr**) (matchexp.c:811)

are definitely lost: 1077 occurences
  calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  xcalloc (xmalloc.c:163)
  gfc_new_symbol(char const*, gfc_namespace*) (symbol.c:2772)
  gfc_get_sym_tree(char const*, gfc_namespace*, gfc_symtree**, bool)
(symbol.c:2998)
  gfc_get_symbol(char const*, gfc_namespace*, gfc_symbol**) (symbol.c:3051)
  build_sym(char const*, gfc_charlen*, bool, gfc_array_spec**, locus*)
(decl.c:1219)
  variable_decl (decl.c:2103)
  gfc_match_data_decl() (decl.c:4533)
  match_word(char const*, match (*)(), locus*) [clone .part.4] (parse.c:65)
  match_word (parse.c:372)
  decode_statement() (parse.c:372)
  next_free (parse.c:1076)
  next_statement() (parse.c:1310)
  parse_spec(gfc_statement) (parse.c:3407)
  parse_progunit(gfc_statement) (parse.c:5189)

are definitely lost: 1000 occurences
  calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  xcalloc (xmalloc.c:163)
  gfc_get_namespace(gfc_namespace*, int) (symbol.c:2508)
  parse_interface (parse.c:3010)
  parse_spec(gfc_statement) (parse.c:3364)
  parse_progunit(gfc_statement) (parse.c:5189)
  gfc_parse_file() (parse.c:5698)
  gfc_be_parse_file() (f95-lang.c:201)
  compile_file() (toplev.c:464)
  do_compile (toplev.c:1977)
  toplev::main(int, char**) (toplev.c:2084)
  main (main.c:39)

I know that it would require a lot of work, but I what about starting with a
simple source file 'b.f03' that exposes
many of aforementioned:

==18926== Memcheck, a memory error detector
==18926== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==18926== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==18926== Command: ./xgcc -B. b.f03 -c
==18926== 
==18927== Memcheck, a memory error detector
==18927== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==18927== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==18927== Command: ./f951 b.f03 -quiet -dumpbase b.f03 -mtune=generic
-march=x86-64 -auxbase b -fintrinsic-modules-path finclude -o /tmp/ccHD9F5o.s
==18927== 
==18927== 
==18927== HEAP SUMMARY:
==18927==     in use at exit: 1,718,810 bytes in 2,171 blocks
==18927==   total heap usage: 8,134 allocs, 5,963 frees, 4,543,215 bytes
allocated
==18927== 
==18927== 80 bytes in 2 blocks are definitely lost in loss record 265 of 728
==18927==    at 0x4C2AE25: calloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==18927==    by 0x11334C0: xcalloc (xmalloc.c:163)
==18927==    by 0x66CBC9: gfc_match_actual_arglist(int, gfc_actual_arglist**)
(primary.c:1758)
==18927==    by 0x66F826: gfc_match_rvalue(gfc_expr**) (primary.c:2989)
==18927==    by 0x648A4E: match_primary (matchexp.c:157)
==18927==    by 0x648A4E: match_level_1 (matchexp.c:211)
==18927==    by 0x648A4E: match_mult_operand(gfc_expr**) (matchexp.c:267)
==18927==    by 0x648C98: match_add_operand(gfc_expr**) (matchexp.c:356)
==18927==    by 0x648F2C: match_level_2(gfc_expr**) (matchexp.c:480)
==18927==    by 0x649082: match_level_3(gfc_expr**) (matchexp.c:551)
==18927==    by 0x649194: match_level_4 (matchexp.c:599)
==18927==    by 0x649194: match_and_operand(gfc_expr**) (matchexp.c:693)
==18927==    by 0x649342: match_or_operand(gfc_expr**) (matchexp.c:722)
==18927==    by 0x649432: match_equiv_operand(gfc_expr**) (matchexp.c:765)
==18927==    by 0x649524: match_level_5(gfc_expr**) (matchexp.c:811)
==18927== 
==18927== 192 bytes in 1 blocks are definitely lost in loss record 620 of 728
==18927==    at 0x4C2AE25: calloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==18927==    by 0x11334C0: xcalloc (xmalloc.c:163)
==18927==    by 0x61558F: gfc_get_expr() (expr.c:48)
==18927==    by 0x615A3B: gfc_copy_expr(gfc_expr*) (expr.c:272)
==18927==    by 0x686E48: resolve_select_type(gfc_code*, gfc_namespace*)
(resolve.c:8359)
==18927==    by 0x67DB41: gfc_resolve_code(gfc_code*, gfc_namespace*)
(resolve.c:10624)
==18927==    by 0x67FCA2: resolve_codes(gfc_namespace*) (resolve.c:15521)
==18927==    by 0x67FBA7: resolve_codes(gfc_namespace*) (resolve.c:15506)
==18927==    by 0x67FD91: gfc_resolve(gfc_namespace*) [clone .part.48]
(resolve.c:15555)
==18927==    by 0x669C4C: gfc_parse_file() (parse.c:5757)
==18927==    by 0x6B0232: gfc_be_parse_file() (f95-lang.c:201)
==18927==    by 0xA789DE: compile_file() (toplev.c:464)
==18927== 
==18927== 304 bytes in 1 blocks are definitely lost in loss record 647 of 728
==18927==    at 0x4C2AE25: calloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==18927==    by 0x11334C0: xcalloc (xmalloc.c:163)
==18927==    by 0x69FC63: gfc_new_symbol(char const*, gfc_namespace*)
(symbol.c:2772)
==18927==    by 0x605732: gfc_match_decl_type_spec(gfc_typespec*, int)
(decl.c:2883)
==18927==    by 0x608E16: gfc_match_data_decl() (decl.c:4467)
==18927==    by 0x65F70E: match_word(char const*, match (*)(), locus*)
(parse.c:65)
==18927==    by 0x660221: decode_statement() (parse.c:372)
==18927==    by 0x66301E: next_free() (parse.c:1076)
==18927==    by 0x6635DC: next_statement() (parse.c:1310)
==18927==    by 0x666269: parse_spec(gfc_statement) (parse.c:3407)
==18927==    by 0x668C2F: parse_progunit(gfc_statement) (parse.c:5189)
==18927==    by 0x669C26: gfc_parse_file() (parse.c:5749)
==18927== 
==18927== 560 (192 direct, 368 indirect) bytes in 1 blocks are definitely lost
in loss record 661 of 728
==18927==    at 0x4C2AE25: calloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==18927==    by 0x11334C0: xcalloc (xmalloc.c:163)
==18927==    by 0x61558F: gfc_get_expr() (expr.c:48)
==18927==    by 0x61E066: gfc_get_variable_expr(gfc_symtree*) (expr.c:4009)
==18927==    by 0x686F84: resolve_select_type(gfc_code*, gfc_namespace*)
(resolve.c:8433)
==18927==    by 0x67DB41: gfc_resolve_code(gfc_code*, gfc_namespace*)
(resolve.c:10624)
==18927==    by 0x67FCA2: resolve_codes(gfc_namespace*) (resolve.c:15521)
==18927==    by 0x67FBA7: resolve_codes(gfc_namespace*) (resolve.c:15506)
==18927==    by 0x67FD91: gfc_resolve(gfc_namespace*) [clone .part.48]
(resolve.c:15555)
==18927==    by 0x669C4C: gfc_parse_file() (parse.c:5757)
==18927==    by 0x6B0232: gfc_be_parse_file() (f95-lang.c:201)
==18927==    by 0xA789DE: compile_file() (toplev.c:464)
==18927== 
==18927== 3,536 (2,480 direct, 1,056 indirect) bytes in 1 blocks are definitely
lost in loss record 694 of 728
==18927==    at 0x4C2AE25: calloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==18927==    by 0x11334C0: xcalloc (xmalloc.c:163)
==18927==    by 0x69F4DC: gfc_get_namespace(gfc_namespace*, int)
(symbol.c:2508)
==18927==    by 0x6506F1: load_needed(pointer_info*) (module.c:4837)
==18927==    by 0x65055B: load_needed(pointer_info*) (module.c:4816)
==18927==    by 0x650550: load_needed(pointer_info*) (module.c:4815)
==18927==    by 0x650550: load_needed(pointer_info*) (module.c:4815)
==18927==    by 0x651D03: read_module (module.c:5298)
==18927==    by 0x651D03: gfc_use_module(gfc_use_list*) (module.c:6973)
==18927==    by 0x653616: gfc_use_modules() (module.c:7097)
==18927==    by 0x65F7E9: use_modules() (parse.c:114)
==18927==    by 0x6600BF: decode_statement() (parse.c:331)
==18927==    by 0x66301E: next_free() (parse.c:1076)
==18927== 
==18927== 4,072 (2,480 direct, 1,592 indirect) bytes in 1 blocks are definitely
lost in loss record 698 of 728
==18927==    at 0x4C2AE25: calloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==18927==    by 0x11334C0: xcalloc (xmalloc.c:163)
==18927==    by 0x69F4DC: gfc_get_namespace(gfc_namespace*, int)
(symbol.c:2508)
==18927==    by 0x5FA366: generate_finalization_wrapper(gfc_symbol*,
gfc_namespace*, char const*, gfc_component*) (class.c:1589)
==18927==    by 0x5FD1A4: gfc_find_derived_vtab(gfc_symbol*) (class.c:2406)
==18927==    by 0x5FDEE4: gfc_find_vtab(gfc_typespec*) (class.c:2721)
==18927==    by 0x61CFF8: gfc_check_pointer_assign(gfc_expr*, gfc_expr*)
(expr.c:3662)
==18927==    by 0x67EA4F: gfc_resolve_code(gfc_code*, gfc_namespace*)
(resolve.c:10572)
==18927==    by 0x67FCA2: resolve_codes(gfc_namespace*) (resolve.c:15521)
==18927==    by 0x67FD91: gfc_resolve(gfc_namespace*) [clone .part.48]
(resolve.c:15555)
==18927==    by 0x6695D8: resolve_all_program_units(gfc_namespace*)
(parse.c:5551)
==18927==    by 0x669D80: gfc_parse_file() (parse.c:5803)


As I've never touched Fortran FE, it's not easy for me to hunt these.

Thanks,
Martin


More information about the Gcc-bugs mailing list