Bug 95315 - [11 Regression] ICE: Segmentation fault (in lookup_page_table_entry) since r11-382-g7a50e7087567cffb
Summary: [11 Regression] ICE: Segmentation fault (in lookup_page_table_entry) since r1...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: 11.0
Assignee: Jakub Jelinek
URL:
Keywords: ice-on-valid-code, openmp
Depends on:
Blocks:
 
Reported: 2020-05-25 14:37 UTC by Arseny Solokha
Modified: 2020-05-29 09:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.1.0
Known to fail: 11.0
Last reconfirmed: 2020-05-26 00:00:00


Attachments
gcc11-pr95315.patch (1.08 KB, patch)
2020-05-26 11:50 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Arseny Solokha 2020-05-25 14:37:50 UTC
gcc-11.0.0-alpha20200524 snapshot (g:d176184d98a00ab379ae5959aed1908a79995e6b) ICEs when compiling gcc/testsuite/c-c++-common/gomp/declare-variant-5.c w/ -O2 -fopenmp --param ggc-min-heapsize=0:

% gcc-11.0.0 -O2 -fopenmp --param ggc-min-heapsize=0 -c gcc/testsuite/c-c++-common/gomp/declare-variant-5.c
gcc/testsuite/c-c++-common/gomp/declare-variant-5.c: In function 'test':
gcc/testsuite/c-c++-common/gomp/declare-variant-5.c:36:1: internal compiler error: Segmentation fault
   36 | }
      | ^
0xd9fcff crash_signal
	/var/tmp/portage/sys-devel/gcc-11.0.0_alpha20200524/work/gcc-11-20200524/gcc/toplev.c:328
0x8af45b lookup_page_table_entry
	/var/tmp/portage/sys-devel/gcc-11.0.0_alpha20200524/work/gcc-11-20200524/gcc/ggc-page.c:630
0x8af45b ggc_set_mark(void const*)
	/var/tmp/portage/sys-devel/gcc-11.0.0_alpha20200524/work/gcc-11-20200524/gcc/ggc-page.c:1544
0xb0b331 gt_ggc_mx_symtab_node(void*)
	/var/tmp/portage/sys-devel/gcc-11.0.0_alpha20200524/work/build/gcc/gtype-desc.c:1300
0xc58316 gt_ggc_mx_omp_declare_variant_base_entry(void*)
	./gt-omp-general.h:47
0xc58316 gt_ggc_mx_omp_declare_variant_base_entry(void*)
	./gt-omp-general.h:41
0xc58316 gt_ggc_mx(omp_declare_variant_base_entry*&)
	./gt-omp-general.h:65
0xc55121 ggc_remove<omp_declare_variant_base_entry*>::ggc_mx(omp_declare_variant_base_entry*&)
	/var/tmp/portage/sys-devel/gcc-11.0.0_alpha20200524/work/gcc-11-20200524/gcc/hash-traits.h:237
0xc55121 ggc_remove<omp_declare_variant_base_entry*>::ggc_maybe_mx(omp_declare_variant_base_entry*&)
	/var/tmp/portage/sys-devel/gcc-11.0.0_alpha20200524/work/gcc-11-20200524/gcc/hash-traits.h:244
0xc55121 gt_ggc_mx<omp_declare_variant_alt_hasher>
	/var/tmp/portage/sys-devel/gcc-11.0.0_alpha20200524/work/gcc-11-20200524/gcc/hash-table.h:1163
0xc55121 gt_ggc_mx_hash_table_omp_declare_variant_alt_hasher_(void*)
	./gt-omp-general.h:90
0xc55121 gt_ggc_mx_hash_table_omp_declare_variant_alt_hasher_(void*)
	./gt-omp-general.h:85
0xa93055 ggc_mark_root_tab
	/var/tmp/portage/sys-devel/gcc-11.0.0_alpha20200524/work/gcc-11-20200524/gcc/ggc-common.c:78
0xa9336c ggc_mark_roots()
	/var/tmp/portage/sys-devel/gcc-11.0.0_alpha20200524/work/gcc-11-20200524/gcc/ggc-common.c:95
0x8afdc8 ggc_collect()
	/var/tmp/portage/sys-devel/gcc-11.0.0_alpha20200524/work/gcc-11-20200524/gcc/ggc-page.c:2220
Comment 1 Martin Liška 2020-05-26 07:21:31 UTC
Started with r11-382-g7a50e7087567cffb.
Comment 2 Jakub Jelinek 2020-05-26 11:50:12 UTC
Created attachment 48603 [details]
gcc11-pr95315.patch

Untested fix.
Comment 3 GCC Commits 2020-05-27 08:30:18 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:baff22c48bdee9cb644b7336bf6f20f799531507

commit r11-653-gbaff22c48bdee9cb644b7336bf6f20f799531507
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed May 27 10:25:56 2020 +0200

    openmp: Fix up omp_declare_variant{s,_alt} htab handling
    
    This patch fixes a GC ICE.  During debugging, I've found that during
    gimplification we can actually call omp_resolve_declare_variant multiple
    times and it would create a new magic declare_variant_alt FUNCTION_DECL
    each time, which is undesirable, once we have such a decl, we should just
    use that.  The other problem is that there was no cgraph node removal hook.
    As the omp_declare_variants htab is used just early during gimplification,
    we can just clear the whole htab, rather than trying to lookup and remove
    a particular entry.  The other hash table is used later as well and that
    one uses just DECL_UID as hash, so in that case the patch removes the elt.
    
    2020-05-27  Jakub Jelinek  <jakub@redhat.com>
    
            PR middle-end/95315
            * omp-general.c (omp_declare_variant_remove_hook): New function.
            (omp_resolve_declare_variant): Always return base if it is already
            declare_variant_alt magic decl itself.  Register
            omp_declare_variant_remove_hook as cgraph node removal hook.
    
            * gcc.dg/gomp/pr95315.c: New test.
Comment 4 Arseny Solokha 2020-05-27 10:53:15 UTC
(In reply to Jakub Jelinek from comment #2)
> Created attachment 48603 [details]
> gcc11-pr95315.patch
> 
> Untested fix.

@@ -1823,6 +1850,12 @@ omp_resolve_declare_variant (tree base)
 	    }
 	}
 
+      static struct cgraph_node_hook_list *node_removal_hook_holder;
+      if (node_removal_hook_holder)
+	node_removal_hook_holder
+	  = symtab->add_cgraph_removal_hook (omp_declare_variant_remove_hook,
+					     NULL);
+
       if (omp_declare_variants == NULL)
 	omp_declare_variants
 	  = hash_table<omp_declare_variant_hasher>::create_ggc (64);

Shouldn't there be

  if (!node_removal_hook_holder)
    node_removal_hook_holder
      = symtab->add_cgraph_removal_hook (…

instead?
Comment 5 Jakub Jelinek 2020-05-27 10:57:10 UTC
(In reply to Arseny Solokha from comment #4)
> Shouldn't there be
> 
>   if (!node_removal_hook_holder)
>     node_removal_hook_holder
>       = symtab->add_cgraph_removal_hook (…
> 
> instead?

Of course, good catch.  For the particular testcase, only the non-removal_hook related part of the patch is sufficient, and I didn't try to come up with a testcase where a function is originally needed, but e.g. early inlining makes it go away.  Will try to construct that and see if the removal hook fix will fix that.
Comment 6 GCC Commits 2020-05-29 08:50:25 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:3d0675f3bb54b58903bc9214d05c8e6d20e5f313

commit r11-712-g3d0675f3bb54b58903bc9214d05c8e6d20e5f313
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri May 29 10:48:40 2020 +0200

    openmp: One omp_resolve_declare_variant followup
    
    As noticed by Arseny, I got the condition when to call the add removal hook
    wrong wrong.  Fixed thusly.
    
    2020-05-28  Jakub Jelinek  <jakub@redhat.com>
    
            PR middle-end/95315
            * omp-general.c (omp_resolve_declare_variant): Fix up addition of
            declare variant cgraph node removal callback.
    
            * gcc.dg/gomp/pr95315-2.c: New test.
Comment 7 Jakub Jelinek 2020-05-29 09:42:33 UTC
Fixed.