Bug 72457 - [6/7 Regression] ICE: Segmentation fault
Summary: [6/7 Regression] ICE: Segmentation fault
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P1 normal
Target Milestone: 6.2
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 55922
  Show dependency treegraph
 
Reported: 2016-07-26 05:22 UTC by James Almer
Modified: 2017-09-18 18:34 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 6.1.0
Known to fail:
Last reconfirmed: 2016-07-26 00:00:00


Attachments
Preprocessed output as created by -freport-bug (251.08 KB, application/x-gzip)
2016-07-26 05:22 UTC, James Almer
Details
Somewhat reduced testcase (4.39 KB, text/plain)
2016-07-26 15:46 UTC, Markus Trippelsdorf
Details
reduced testcase (3.47 KB, text/plain)
2016-07-26 18:41 UTC, Markus Trippelsdorf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Almer 2016-07-26 05:22:19 UTC
Created attachment 39010 [details]
Preprocessed output as created by -freport-bug

/home/jamrial/range-v3/include/range/v3/utility/box.hpp:198:14: internal compiler error: Segmentation fault
             {}
              ^
0xd6e91f crash_signal
        /home/jamrial/gcc-svn/gcc/toplev.c:335
0x86e332 cx_check_missing_mem_inits
        /home/jamrial/gcc-svn/gcc/cp/constexpr.c:740
0x87def1 cx_check_missing_mem_inits
        /home/jamrial/gcc-svn/gcc/hash-table.h:906
0x87def1 register_constexpr_fundef(tree_node*, tree_node*)
        /home/jamrial/gcc-svn/gcc/cp/constexpr.c:800
0x67a190 maybe_save_function_definition
        /home/jamrial/gcc-svn/gcc/cp/decl.c:14619
0x67a190 finish_function(int)
        /home/jamrial/gcc-svn/gcc/cp/decl.c:14744
0x6aa5d6 instantiate_decl(tree_node*, int, bool)
        /home/jamrial/gcc-svn/gcc/cp/pt.c:22170
0x7330ac mark_used(tree_node*, int)
        /home/jamrial/gcc-svn/gcc/cp/decl2.c:5290
0x63f4f0 build_over_call
        /home/jamrial/gcc-svn/gcc/cp/call.c:7818
0x64af0f build_new_method_call_1
        /home/jamrial/gcc-svn/gcc/cp/call.c:8543
0x64af0f build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, tree_node**, int)
        /home/jamrial/gcc-svn/gcc/cp/call.c:8613
0x64be95 build_special_member_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, int)
        /home/jamrial/gcc-svn/gcc/cp/call.c:8139
0x7bfa06 expand_default_init
        /home/jamrial/gcc-svn/gcc/cp/init.c:1748
0x7bfa06 expand_aggr_init_1
        /home/jamrial/gcc-svn/gcc/cp/init.c:1863
0x7c66a0 emit_mem_initializers(tree_node*)
        /home/jamrial/gcc-svn/gcc/cp/init.c:1166
0x6afcc3 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        /home/jamrial/gcc-svn/gcc/cp/pt.c:15222
0x6ad89a tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        /home/jamrial/gcc-svn/gcc/cp/pt.c:15401
0x6aa52b instantiate_decl(tree_node*, int, bool)
        /home/jamrial/gcc-svn/gcc/cp/pt.c:22148
0x7330ac mark_used(tree_node*, int)
        /home/jamrial/gcc-svn/gcc/cp/decl2.c:5290
0x63f4f0 build_over_call
        /home/jamrial/gcc-svn/gcc/cp/call.c:7818

Make sure to compile the preprocessed source with -Wall or it will not trigger the ICE.
Comment 1 Markus Trippelsdorf 2016-07-26 05:40:45 UTC
Confirmed. Reducing...
Comment 2 Markus Trippelsdorf 2016-07-26 15:46:25 UTC
Created attachment 39020 [details]
Somewhat reduced testcase

Thread 2.1 "cc1plus" received signal SIGSEGV, Segmentation fault.
[Switching to process 24708]
cx_check_missing_mem_inits (fun=<optimized out>, body=0x3fffaf688268, complain=<optimized out>) at ../../gcc/gcc/cp/constexpr.c:740
740               if (TREE_CODE (field) != FIELD_DECL
(gdb) p field
$1 = (tree) 0x0

Unfortunately reducing the testcase takes ages.
Comment 3 Markus Trippelsdorf 2016-07-26 18:41:13 UTC
Created attachment 39023 [details]
reduced testcase
Comment 4 Markus Trippelsdorf 2016-07-26 18:54:38 UTC
Started with r238688.
Comment 5 Markus Trippelsdorf 2016-07-26 19:24:35 UTC
Since the patch was backported to gcc-6 branch immediately, gcc-6 is also affected.
Comment 6 Markus Trippelsdorf 2016-07-26 20:49:18 UTC
So, perhaps simply:

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 6bcb41a..83fd9a4 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -734,7 +734,7 @@ cx_check_missing_mem_inits (tree fun, tree body, bool complain)
              || DECL_ARTIFICIAL (index))
            continue;
        }
-      for (; field != index; field = DECL_CHAIN (field))
+      for (; field != NULL_TREE && field != index; field = DECL_CHAIN (field))
        {
          tree ftype;
          if (TREE_CODE (field) != FIELD_DECL
Comment 7 Jason Merrill 2016-07-28 21:36:15 UTC
Reduced:

template <typename Element> struct box {
  Element value;
  constexpr box() : value{} {}
};
struct B: box<int> { };
template box<B>::box();
Comment 8 Jason Merrill 2016-07-29 14:03:58 UTC
Author: jason
Date: Fri Jul 29 14:03:26 2016
New Revision: 238867

URL: https://gcc.gnu.org/viewcvs?rev=238867&root=gcc&view=rev
Log:
	PR c++/72457 - ICE with list-value-initialized base.

	* init.c (expand_aggr_init_1): Only handle value-init of bases.
	* constexpr.c (build_data_member_initialization): Handle multiple
	initializers for the same field.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-list1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c
    trunk/gcc/cp/init.c
Comment 9 Jason Merrill 2016-07-29 14:08:34 UTC
Author: jason
Date: Fri Jul 29 14:08:03 2016
New Revision: 238868

URL: https://gcc.gnu.org/viewcvs?rev=238868&root=gcc&view=rev
Log:
	PR c++/72457 - ICE with list-value-initialized base.

	* init.c (expand_aggr_init_1): Only handle value-init of bases.
	* constexpr.c (build_data_member_initialization): Handle multiple
	initializers for the same field.

Added:
    branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-list1.C
Modified:
    branches/gcc-6-branch/gcc/cp/ChangeLog
    branches/gcc-6-branch/gcc/cp/constexpr.c
    branches/gcc-6-branch/gcc/cp/init.c
Comment 10 Jason Merrill 2016-07-29 14:08:50 UTC
Fixed.
Comment 11 Jason Merrill 2017-09-18 18:34:30 UTC
Author: jason
Date: Mon Sep 18 18:33:58 2017
New Revision: 252938

URL: https://gcc.gnu.org/viewcvs?rev=252938&root=gcc&view=rev
Log:
	PR c++/72457 - ICE with list-value-initialized base.

	* init.c (expand_aggr_init_1): Only handle value-init of bases.
	* constexpr.c (build_data_member_initialization): Handle multiple
	initializers for the same field.

Added:
    branches/gcc-5-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-list1.C
Modified:
    branches/gcc-5-branch/gcc/cp/ChangeLog
    branches/gcc-5-branch/gcc/cp/constexpr.c
    branches/gcc-5-branch/gcc/cp/init.c