Bug 102557 - [12 Regression] ICE: Segmentation fault signal terminated program cc1plus (indefinite recursion in modref_ref_node<int>::insert_access) since r12-3202-gf5ff3a8ed4ca9173
Summary: [12 Regression] ICE: Segmentation fault signal terminated program cc1plus (in...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ipa (show other bugs)
Version: 12.0
: P1 normal
Target Milestone: 12.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2021-10-01 16:39 UTC by Arseny Solokha
Modified: 2021-11-04 02:02 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-10-01 00:00:00


Attachments
Testcase (417 bytes, text/plain)
2021-10-01 16:39 UTC, Arseny Solokha
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Arseny Solokha 2021-10-01 16:39:14 UTC
Created attachment 51533 [details]
Testcase

g++-12.0.0-alpha20210926 snapshot (g:fe2771b291c2c7c0ac37b75ec5b160937524b60c) ICEs when compiling the attached testcase, reduced from libstdc++-v3/testsuite/22_locale/time_get/get_monthname/char/6.cc, w/ -O3 --param max-inline-insns-single=2 --param modref-max-accesses=2:

% g++-12.0.0 -O3 --param max-inline-insns-single=2 --param modref-max-accesses=2 -c xv7snbwu.cc
g++-12.0.0: internal compiler error: Segmentation fault signal terminated program cc1plus

(gdb) where
#0  0x0000000000f345c7 in modref_access_node::merge (this=this@entry=0x7ffff77533f8, a=...,
    record_adjustments=record_adjustments@entry=false)
    at /var/tmp/portage/sys-devel/gcc-12.0.0_alpha20210926/work/gcc-12-20210926/gcc/ipa-modref-tree.h:204
#1  0x0000000000f35235 in modref_access_node::forced_merge (this=0x7ffff77533f8, a=..., record_adjustments=<optimized out>)
    at /var/tmp/portage/sys-devel/gcc-12.0.0_alpha20210926/work/gcc-12-20210926/gcc/ipa-modref-tree.h:351
#2  0x0000000000f39654 in modref_ref_node<int>::insert_access (this=this@entry=0x7ffff7732f00, a=...,
    max_accesses=max_accesses@entry=2, record_adjustments=record_adjustments@entry=false)
    at /var/tmp/portage/sys-devel/gcc-12.0.0_alpha20210926/work/gcc-12-20210926/gcc/ipa-modref-tree.h:575
#3  0x0000000000f397de in modref_ref_node<int>::insert_access (this=this@entry=0x7ffff7732f00, a=...,
    max_accesses=max_accesses@entry=2, record_adjustments=record_adjustments@entry=false)
    at /var/tmp/portage/sys-devel/gcc-12.0.0_alpha20210926/work/gcc-12-20210926/gcc/ipa-modref-tree.h:596
Comment 1 Arseny Solokha 2021-10-01 16:43:06 UTC
Semi-reduced testcase for the reference:

#include <sstream>

void
test01 (char *mname)
{
  std::istringstream iss;

  iss.str (mname);
  iss.str (mname);
}

% g++-12.0.0 -std=c++20 -O3 -fopenacc --param max-inline-insns-single=2 --param modref-max-accesses=2 --param uninlined-function-time=999998 -c ujd9xqvr.cc
g++-12.0.0: internal compiler error: Segmentation fault signal terminated program cc1plus
Comment 2 Martin Liška 2021-10-01 18:31:09 UTC
Started with r12-3202-gf5ff3a8ed4ca9173.
I can try taking a look.
Comment 3 Martin Liška 2021-10-04 08:27:04 UTC
I'm not familiar enough with the code, leaving to Honza.
Comment 4 Jan Hubicka 2021-10-07 14:40:17 UTC
It is caused by broken early exit while updating the access range which makes insert_access to get into infinite recursion (trying to free space to add extra item)
gcc/ChangeLog:

        PR ipa/102557
        * ipa-modref-tree.h (modref_access_node::update): Fix early
        exit conditional.
        (modref_ref_node::insert_access): Sanity check that mergin
        suceeded.

diff --git a/gcc/ipa-modref-tree.h b/gcc/ipa-modref-tree.h
index 8e9b89b3e2c..52f225b1aae 100644
--- a/gcc/ipa-modref-tree.h
+++ b/gcc/ipa-modref-tree.h
@@ -148,7 +148,8 @@ struct GTY(()) modref_access_node
               poly_int64 offset1, poly_int64 size1, poly_int64 max_size1,
               bool record_adjustments)
     {
-      if (known_eq (offset, offset1)
+      if (known_eq (parm_offset, parm_offset1)
+         && known_eq (offset, offset1)
          && known_eq (size, size1)
          && known_eq (max_size, max_size1))
        return;
@@ -577,6 +578,10 @@ struct GTY((user)) modref_ref_node
          }
        (*accesses)[best1].forced_merge (best2 < 0 ? a : (*accesses)[best2],
                                         record_adjustments);
+       /* Check that merging indeed merged ranges.  */
+       gcc_checking_assert ((*accesses)[best1].contains (best2 < 0 ? a : (*accesses)[best2]));
+       /*if (best2 >= 0)
+         accesses->unordered_remove (best2);*/
        if (!(*accesses)[best1].useful_p ())
          {
            collapse ();
Comment 5 GCC Commits 2021-10-14 13:49:54 UTC
The master branch has been updated by Jan Hubicka <hubicka@gcc.gnu.org>:

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

commit r12-4401-gfecd145359fc981beb2802f746190227c5cc010a
Author: Jan Hubicka <hubicka@ucw.cz>
Date:   Thu Oct 14 15:48:01 2021 +0200

    Fix ICE in insert_access.
    
    gcc/ChangeLog:
    
            PR ipa/102557
            * ipa-modref-tree.h (modref_access_node::update2):
            Also check that parm_offset is unchanged.
            (modref_ref_node::insert_access): Fix updating of
            parameter.
Comment 6 Martin Liška 2021-10-14 15:04:41 UTC
Can we close it as fixed now?
Comment 7 Jan Hubicka 2021-10-15 11:54:39 UTC
Fixed.