On Fri, Oct 11, 2019 at 09:03:53AM +0200, Jan Hubicka wrote:
> Bootstrapped/regtested x86_64-linux, OK?
> 
>       * ggc-page.c (release_pages): Output statistics when !quiet_flag.
>       (ggc_collect): Dump later to not interfere with release_page dump.
>       (ggc_trim): New function.
>       * ggc-none.c (ggc_trim): New.
> 
>       * lto.c (lto_wpa_write_files): Call ggc_trim.

> @@ -1152,10 +1156,20 @@ release_pages (void)
>       *gp = g->next;
>       G.bytes_mapped -= g->alloc_size;
>       free (g->allocation);
> +     n1 += g->alloc_size;
>        }
>      else
>        gp = &g->next;
>  #endif

This broke !defined(USING_MMAP) support, the second g->alloc_size read
is after the memory containing *g is freed.

Fixed thusly, tested with #undef USING_MMAP in the file (without the patch
self-test ICEs, with it succeeds), committed to trunk as obvious.

2019-10-18  Jakub Jelinek  <ja...@redhat.com>

        PR middle-end/92153
        * ggc-page.c (release_pages): Read g->alloc_size before free rather
        than after it.

--- gcc/ggc-page.c.jj   2019-10-11 14:10:44.987386981 +0200
+++ gcc/ggc-page.c      2019-10-18 19:13:59.458085610 +0200
@@ -1155,8 +1155,8 @@ release_pages (void)
       {
        *gp = g->next;
        G.bytes_mapped -= g->alloc_size;
-       free (g->allocation);
        n1 += g->alloc_size;
+       free (g->allocation);
       }
     else
       gp = &g->next;


        Jakub

Reply via email to