]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Implement ~line_maps ()
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 25 Oct 2016 18:10:44 +0000 (18:10 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Tue, 25 Oct 2016 18:10:44 +0000 (18:10 +0000)
line_maps instances such as the global line_table are
GC-managed, but the htab within location_adhoc_data_map.htab
is not GC-managed.

Previously this was deleted manually by a call to
location_adhoc_data_fini within toplev::main.

However, on adding a call to forcibly_ggc_collect after the
selftests, all of the htabs for the various line_tables
created during the selftests start showing up as leaks
in "make selftest-valgrind", e.g.:

13,536 (1,344 direct, 12,192 indirect) bytes in 12 blocks are definitely lost in loss record 1,065 of 1,086
   at 0x4A081D4: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x16DB3B0: xcalloc (xmalloc.c:163)
   by 0x16D8D34: htab_create_typed_alloc (hashtab.c:358)
   by 0x16D8DBD: htab_create_alloc (hashtab.c:286)
   by 0x16A2CCC: linemap_init(line_maps*, unsigned int) (line-map.c:353)
   by 0x1685605: selftest::line_table_test::line_table_test(selftest::line_table_case const&) (input.c:1624)
   by 0x167D09C: selftest::test_applying_fixits_modernize_named_init(selftest::line_table_case const&) (edit-context.c:1430)
   by 0x1686827: selftest::for_each_line_table_case(void (*)(selftest::line_table_case const&)) (input.c:3227)
   by 0x167F067: selftest::edit_context_c_tests() (edit-context.c:1658)
   by 0x1616E67: selftest::run_tests() (selftest-run-tests.c:71)
   by 0xC0DB25: toplev::run_self_tests() (toplev.c:2076)
   by 0x618EB4: toplev::main(int, char**) (toplev.c:2153)

This patch removes the manual one-time cleanup in favor of
adding a destructor to class line_maps, which cleans up
the non-GC-managed htab.

Doing so improves "make selftest-valgrind" from:

==61118== LEAK SUMMARY:
==61118==    definitely lost: 121,248 bytes in 1,515 blocks
==61118==    indirectly lost: 974,344 bytes in 959 blocks
==61118==      possibly lost: 0 bytes in 0 blocks
==61118==    still reachable: 1,332,599 bytes in 3,684 blocks
==61118==         suppressed: 0 bytes in 0 blocks

to:

==57182== LEAK SUMMARY:
==57182==    definitely lost: 13,840 bytes in 556 blocks
==57182==    indirectly lost: 0 bytes in 0 blocks
==57182==      possibly lost: 0 bytes in 0 blocks
==57182==    still reachable: 1,355,703 bytes in 3,684 blocks
==57182==         suppressed: 0 bytes in 0 blocks

gcc/ChangeLog:
* toplev.c (toplev::main): Remove call to
location_adhoc_data_fini.

libcpp/ChangeLog:
* include/line-map.h (line_maps::~line_maps): New dtor.
(location_adhoc_data_fini): Delete decl.
* line-map.c (line_maps::~line_maps): New dtor.
(location_adhoc_data_fini): Delete.

From-SVN: r241533

gcc/ChangeLog
gcc/toplev.c
libcpp/ChangeLog
libcpp/include/line-map.h
libcpp/line-map.c

index 9f1ddc7b56294371b499de539148f798c6d6c1a4..f44656fac3c7e861e543fcfd531482cd88131916 100644 (file)
@@ -1,3 +1,8 @@
+2016-10-25  David Malcolm  <dmalcolm@redhat.com>
+
+       * toplev.c (toplev::main): Remove call to
+       location_adhoc_data_fini.
+
 2016-10-25  Eric Botcazou  <ebotcazou@adacore.com>
 
        * tree.h (wi::fits_to_tree_p): Accept only 0 and 1 for boolean types.
index 1df80d04442647e3a5b6a34a6dcca6b5cfb030f5..59b84eb4d4be9f61df80494783150f2c457ab5fe 100644 (file)
@@ -2169,7 +2169,6 @@ toplev::main (int argc, char **argv)
   diagnostic_finish (global_dc);
 
   finalize_plugins ();
-  location_adhoc_data_fini (line_table);
 
   after_memory_report = true;
 
index 87dae8496e2fa2599add676c03476577f6ab8eba..5ff0aad08f876660c0d44aa91f030dcfc63f94fe 100644 (file)
@@ -1,3 +1,10 @@
+2016-10-25  David Malcolm  <dmalcolm@redhat.com>
+
+       * include/line-map.h (line_maps::~line_maps): New dtor.
+       (location_adhoc_data_fini): Delete decl.
+       * line-map.c (line_maps::~line_maps): New dtor.
+       (location_adhoc_data_fini): Delete.
+
 2016-10-21  Andris Pavenis  <andris.pavenis@iki.fi>
 
        PR preprocessor/71681
index 8be98b5f59799023a611543315e858d4870be8f1..b61c3cc0d2c669c76bee7d80213ba3960f89472a 100644 (file)
@@ -699,6 +699,8 @@ struct GTY(()) location_adhoc_data_map {
 
 /* A set of chronological line_map structures.  */
 struct GTY(()) line_maps {
+
+  ~line_maps ();
   
   maps_info_ordinary info_ordinary;
 
@@ -977,7 +979,6 @@ LINEMAPS_LAST_ALLOCATED_MACRO_MAP (const line_maps *set)
   return (line_map_macro *)LINEMAPS_LAST_ALLOCATED_MAP (set, true);
 }
 
-extern void location_adhoc_data_fini (struct line_maps *);
 extern source_location get_combined_adhoc_loc (struct line_maps *,
                                               source_location,
                                               source_range,
index c5c42f0966b81710ce77c4e2b72a2c4b64270186..c98ee45965a60010f99f6c65eaed594a8aa8e896 100644 (file)
@@ -57,6 +57,14 @@ static source_location linemap_macro_loc_to_exp_point (struct line_maps *,
 extern unsigned num_expanded_macros_counter;
 extern unsigned num_macro_tokens_counter;
 
+/* Destructor for class line_maps.
+   Ensure non-GC-managed memory is released.  */
+
+line_maps::~line_maps ()
+{
+  htab_delete (location_adhoc_data_map.htab);
+}
+
 /* Hash function for location_adhoc_data hashtable.  */
 
 static hashval_t
@@ -333,13 +341,6 @@ get_pure_location (line_maps *set, source_location loc)
   return loc & ~((1 << ordmap->m_range_bits) - 1);
 }
 
-/* Finalize the location_adhoc_data structure.  */
-void
-location_adhoc_data_fini (struct line_maps *set)
-{
-  htab_delete (set->location_adhoc_data_map.htab);
-}
-
 /* Initialize a line map set.  */
 
 void