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.
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("")}; }
Confirmed with latest trunk, that is, r279447 didn't fix it.
Which it couldn't have, because it hadn't been broken yet. Started with r279576.
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
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)
*** Bug 93079 has been marked as a duplicate of this bug. ***
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;
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
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}; }
*** Bug 93137 has been marked as a duplicate of this bug. ***
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
I believe this PR can be closed now.
Fixed.
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.
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.
Re-confirmed, still broken.
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
Hopefully really fixed now.
*** Bug 93077 has been marked as a duplicate of this bug. ***