Bug 93033 - [10 Regression] error: incorrect sharing of tree nodes
Summary: [10 Regression] error: incorrect sharing of tree nodes
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: 10.0
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
: 93077 93079 93137 (view as bug list)
Depends on: 66139
Blocks: 93048 93076 93077 93163
  Show dependency treegraph
 
Reported: 2019-12-20 19:17 UTC by David Binderman
Modified: 2020-01-13 18:50 UTC (History)
8 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-12-20 00:00:00


Attachments
gzipped C++ source code (247.02 KB, application/gzip)
2019-12-20 19:17 UTC, David Binderman
Details
gzipped C++ source code (836.31 KB, application/gzip)
2020-01-06 19:10 UTC, David Binderman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2019-12-20 19:17:27 UTC
Created attachment 47536 [details]
gzipped C++ source code

For the attached C++ code on recent gcc trunk, I get

../dialogs/StartDialog.cpp: In constructor ‘StartDialog::StartDialog()’:
../dialogs/StartDialog.cpp:51:1: error: incorrect sharing of tree nodes
*D.113735
D.113735->option = LangResource::getKey (&D.113738, &D.113740); [return slot opt
imization]

The bug first appears sometime between revision 279550 and 279600.

I will try to reduce the code to something smaller.
Comment 1 David Binderman 2019-12-20 19:55:20 UTC
Reduced C++ code seems to be

template <typename a> class b {
public:
  b(a *);
  ~b();
};
class c {
  struct C {
    b<unsigned> d;
    float e;
  };
  c();
};
b<unsigned> f(b<char>);
c::c() { C a[]{f("")}; }
Comment 2 Marek Polacek 2019-12-20 20:03:57 UTC
Confirmed with latest trunk, that is, r279447 didn't fix it.
Comment 3 Marek Polacek 2019-12-20 20:49:22 UTC
Which it couldn't have, because it hadn't been broken yet.

Started with r279576.
Comment 4 Marek Polacek 2019-12-20 21:21:20 UTC
template <typename T> struct S {
  S(T *);
  ~S();
};
struct X {
  struct C {
    S<unsigned> d;
    float e;
  };
  X();
};
S<unsigned> f(S<const char>);
X::X() { C a[]{f("")}; }

$ ./cc1plus -quiet 93033.C
93033.C: In constructor ‘X::X()’:
93033.C:13:1: error: incorrect sharing of tree nodes
   13 | X::X() { C a[]{f("")}; }
      | ^
*D.2489
D.2489->d = f (&D.2492); [return slot optimization]
during GIMPLE pass: cfg
93033.C:13:1: internal compiler error: verify_gimple failed
0x1525a5a verify_gimple_in_cfg(function*, bool)
	/home/mpolacek/src/gcc/gcc/tree-cfg.c:5445
0x1351abd execute_function_todo
	/home/mpolacek/src/gcc/gcc/passes.c:1983
0x1350a9a do_per_function
	/home/mpolacek/src/gcc/gcc/passes.c:1638
0x1351cad execute_todo
	/home/mpolacek/src/gcc/gcc/passes.c:2037
Comment 5 zwen7 2019-12-24 00:09:31 UTC
I am also having the same problem.
My code is here:
https://github.com/zyddnys/PatchyVideo-autocomplete
compile command line: g++ -O3 -std=c++2a -o autocomplete.app autocomplete.cpp
compiler is compiled from latest pull from github.

In file included from autocomplete.cpp:7:
tree.h: In function ‘void AddTag(uint32_t, uint32_t, uint32_t)’:
tree.h:151:6: error: incorrect sharing of tree nodes
  151 | void AddTag(std::uint32_t id, std::uint32_t count, std::uint32_t category)
      |      ^~~~~~
MEM[(struct Tag *)D.232969]
MEM[(struct Tag *)D.232969].count = count;
tree.h:151:6: error: incorrect sharing of tree nodes
MEM[(struct Tag *)D.232969]
MEM[(struct Tag *)D.232969].category = category;
tree.h:151:6: error: incorrect sharing of tree nodes
MEM[(struct Tag *)D.232969]
MEM[(struct Tag *)D.232969].lang_keywords = {};
tree.h:151:6: error: incorrect sharing of tree nodes
MEM[(struct Tag *)D.232969]
MEM[(struct Tag *)D.232969].alias_keywords = {};
during GIMPLE pass: cfg
tree.h:151:6: internal compiler error: verify_gimple failed
0x1013f4a verify_gimple_in_cfg(function*, bool)
        ../.././gcc/tree-cfg.c:5445
0xefad8f execute_function_todo
        ../.././gcc/passes.c:1983
0xefbbcc do_per_function
        ../.././gcc/passes.c:1638
0xefbbcc execute_todo
        ../.././gcc/passes.c:2037
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.


gcc -v:
sing built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/10.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --with-pkgversion=somegcc --disable-multilib --enable-languages=c,c++,lto --disable-bootstrap : (reconfigured) ./configure --with-pkgversion=somegcc --disable-multilib --enable-languages=c,c++,lto --disable-bootstrap : (reconfigured) ./configure --with-pkgversion=patchygcc --disable-multilib --enable-languages=c,c++,lto --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.0 20191223 (experimental) (somegcc)
Comment 6 Jan Hubicka 2019-12-27 14:23:40 UTC
*** Bug 93079 has been marked as a duplicate of this bug. ***
Comment 7 Jan Hubicka 2019-12-27 14:26:11 UTC
This patch fixes the testcase, but I am not familiar enough with the code to say if that is correct fix :)

Index: ../../gcc/cp/cp-gimplify.c
===================================================================
--- ../../gcc/cp/cp-gimplify.c  (revision 279724)
+++ ../../gcc/cp/cp-gimplify.c  (working copy)
@@ -534,7 +534,7 @@ cp_gimplify_init_expr (tree *expr_p, gim
     {
       gimplify_expr (&to, pre_p, NULL, is_gimple_lvalue, fb_lvalue);
       replace_placeholders (from, to);
-      from = split_nonconstant_init (to, from);
+      from = unshare_expr (split_nonconstant_init (to, from));
       cp_genericize_tree (&from, false);
       *expr_p = from;
       return;
Comment 8 Khem Raj 2019-12-28 19:47:31 UTC
with this patch I dont see the ICE I was seeing in quite a few qt apps as reported in

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93077
Comment 9 Jakub Jelinek 2020-01-03 13:43:16 UTC
Reduced testcase from PR93137:

template <typename, typename = int>
struct A {
  A ();
  ~A ();
};
template <typename T, typename U, typename V>
A<T> operator+(const T *, A<U, V>);

void
foo ()
{
  A<char> f;
  struct { A<char> g; bool h; } i[] {"" + f};
}
Comment 10 Jakub Jelinek 2020-01-03 13:44:00 UTC
*** Bug 93137 has been marked as a duplicate of this bug. ***
Comment 11 Jason Merrill 2020-01-03 22:11:27 UTC
Author: jason
Date: Fri Jan  3 22:10:56 2020
New Revision: 279871

URL: https://gcc.gnu.org/viewcvs?rev=279871&root=gcc&view=rev
Log:
	PR c++/93033 - incorrect tree node sharing with array init.

The split_nonconstant_init piece is the only one necessary to fix the
testcase, but it occurred to me that we might as well not split when
-fno-exceptions.

	* typeck2.c (split_nonconstant_init): Unshare non-decl.
	* cp-gimplify.c (cp_gimplify_init_expr): Only split if -fexceptions.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/initlist-array9.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-gimplify.c
    trunk/gcc/cp/typeck2.c
Comment 12 Arseny Solokha 2020-01-06 08:38:23 UTC
I believe this PR can be closed now.
Comment 13 Jason Merrill 2020-01-06 16:40:17 UTC
Fixed.
Comment 14 David Binderman 2020-01-06 19:10:44 UTC
Created attachment 47598 [details]
gzipped C++ source code

The attached C++ source code seems to be still broken.

-march=native (aka bdver2) seems to be required.
Comment 15 David Binderman 2020-01-06 20:14:12 UTC
Reduced C++ code seems to be:

struct a {
  char b;
};
class c {
public:
  c(c const &);
  ~c();
};
struct d {
  enum e {};
};
struct f {
  c g;
  a h;
  c i;
  d::e j;
};
class k {
  f l;
  k(c const &, a const &, c, d::e);
};
k::k(c const &g, a const &h, c i, d::e j) : l{g, h, i, j} {}

Flag -march=native not required now.
Comment 16 Richard Biener 2020-01-08 14:44:56 UTC
Re-confirmed, still broken.
Comment 17 Jason Merrill 2020-01-10 18:47:28 UTC
Author: jason
Date: Fri Jan 10 18:46:57 2020
New Revision: 280126

URL: https://gcc.gnu.org/viewcvs?rev=280126&root=gcc&view=rev
Log:
	PR c++/93173 - incorrect tree sharing.

My patch for 93033 wasn't sufficient to handle all the possible sharing
introduced by split_nonconstant_init, and it occurred to me that it would
make sense to use the same unsharing technique as unshare_body, namely
copy_if_shared.

	PR c++/93033
gcc/
	* gimplify.c (copy_if_shared): No longer static.
	* gimplify.h: Declare it.
gcc/cp/
	* cp-gimplify.c (cp_gimplify_init_expr, cp_gimplify_expr): Use
	copy_if_shared after cp_genericize_tree.
	* typeck2.c (split_nonconstant_init): Don't unshare here.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/initlist-new3.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-gimplify.c
    trunk/gcc/cp/typeck2.c
    trunk/gcc/gimplify.c
    trunk/gcc/gimplify.h
Comment 18 Jason Merrill 2020-01-10 19:23:00 UTC
Hopefully really fixed now.
Comment 19 Jason Merrill 2020-01-13 18:50:34 UTC
*** Bug 93077 has been marked as a duplicate of this bug. ***