Bug 69223 - [5/6/7 regression] ICE with polymorphic lambda
Summary: [5/6/7 regression] ICE with polymorphic lambda
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.3.0
: P2 normal
Target Milestone: 4.9.4
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2016-01-11 07:02 UTC by nightstrike
Modified: 2016-07-27 15:46 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.9.3, 5.3.0, 6.0, 6.1.0
Last reconfirmed: 2016-01-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description nightstrike 2016-01-11 07:02:52 UTC
The following code causes an ICE on gcc 4.9.3, 5.1, 5.2, and 5.3:
[If a fix is found, could it be backported to 4.9?]

#include <array>
#include <cstddef>
#include <vector>

int main(int argc, char * argv[]) {
  std::vector<std::array<std::uint32_t, 20>> out;
  std::vector<std::uint32_t> data;

  auto saveChan = [&](std::size_t size, auto const & src, auto & dest, auto && f) {
    for (std::size_t chan = 0; chan < size; ++chan)
      for (auto const & i: src)
        dest.emplace_back(f(i)[chan]);
  };
  saveChan(20, out, data, [](decltype(out)::value_type const & i){ return i;});

  return 0;
}


$ g++ -std=gnu++14 aa.cpp -c
aa.cpp: In lambda function:
aa.cpp:14:81: internal compiler error: Segmentation fault
  saveChan(20, out, dataInt32, [](decltype(out)::value_type const & i){ return i;});
                                                                                 ^
0x9def6f crash_signal
	../../gcc/toplev.c:337
0x86c90e gimplify_return_expr
	../../gcc/gimplify.c:1229
0x86c90e gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
	../../gcc/gimplify.c:7874
0x86e4b6 gimplify_stmt(tree_node**, gimple_statement_base**)
	../../gcc/gimplify.c:5373
0x86c34d gimplify_cleanup_point_expr
	../../gcc/gimplify.c:5149
0x86c34d gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
	../../gcc/gimplify.c:7990
0x86e4b6 gimplify_stmt(tree_node**, gimple_statement_base**)
	../../gcc/gimplify.c:5373
0x86ed4b gimplify_bind_expr
	../../gcc/gimplify.c:1099
0x86c2be gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
	../../gcc/gimplify.c:7824
0x86e4b6 gimplify_stmt(tree_node**, gimple_statement_base**)
	../../gcc/gimplify.c:5373
0x86f36a gimplify_body(tree_node*, bool)
	../../gcc/gimplify.c:8734
0x86f657 gimplify_function_tree(tree_node*)
	../../gcc/gimplify.c:8887
0x769d27 cgraph_analyze_function(cgraph_node*)
	../../gcc/cgraphunit.c:648
0x76aa57 analyze_functions
	../../gcc/cgraphunit.c:1016
0x76b895 finalize_compilation_unit()
	../../gcc/cgraphunit.c:2328
0x61e4d3 cp_write_global_declarations()
	../../gcc/cp/decl2.c:4647
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Jonathan Wakely 2016-01-13 19:22:16 UTC
Slightly reduced:

#include <array>
#include <vector>

int main() {
  std::vector<std::array<int, 20>> out;

  auto saveChan = [&](auto && f) {
        f({});
  };
  saveChan([](decltype(out)::value_type const & i){ return i;});
}
Comment 2 nightstrike 2016-07-06 16:06:51 UTC
This is still a problem on 6.1.0
Comment 3 Martin Sebor 2016-07-06 16:23:44 UTC
Bisection points to the commit below as the cause of the ICE (before that, GCC gave an error for the program).

r202612 | abutcher | 2013-09-16 03:14:34 -0400 (Mon, 16 Sep 2013) | 37 lines

Support using 'auto' in a function parameter list to introduce an implicit template parameter.

gcc/cp/
	* cp-tree.h (type_uses_auto_or_concept): Declare.
	(is_auto_or_concept): Declare.
	* decl.c (grokdeclarator): Allow 'auto' parameters in lambdas with
	-std=gnu++1y or -std=c++1y or, as a GNU extension, in plain functions.
	* type-utils.h: New header defining ...
	(find_type_usage): ... this new function based on pt.c (type_uses_auto)
	for searching a type tree given a predicate.
	* pt.c (type_uses_auto): Reimplement via type-utils.h (find_type_usage).
	(is_auto_or_concept): New function.
	(type_uses_auto_or_concept): New function.
	* parser.h (struct cp_parser): Add fully_implicit_function_template_p.
	* parser.c (cp_parser_new): Initialize fully_implicit_function_template_p.
	(cp_parser_new): Initialize fully_implicit_function_template_p.
	(cp_parser_lambda_expression): Copy and restore value of
	fully_implicit_function_template_p as per other parser fields.
	(cp_parser_parameter_declaration_list): Count generic
	parameters and call ...
	(add_implicit_template_parms): ... this new function to synthesize them
	with help from type-utils.h (find_type_usage), ...
	(tree_type_is_auto_or_concept): ... this new static function and ...
	(make_generic_type_name): ... this new static function.
	(cp_parser_direct_declarator): Account for implicit template parameters.
	(cp_parser_lambda_declarator_opt): Finish fully implicit template if
	necessary by calling ...
	(finish_fully_implicit_template): ... this new function.
	(cp_parser_init_declarator): Likewise.
	(cp_parser_function_definition_after_declarator): Likewise.
	(cp_parser_member_declaration): Likewise.
	* Make-lang.in (cp/pt.o): Add dependency on type-utils.h.
	(cp/parser.o): Likewise.
Comment 4 Jason Merrill 2016-07-22 03:46:26 UTC
Author: jason
Date: Fri Jul 22 03:45:54 2016
New Revision: 238624

URL: https://gcc.gnu.org/viewcvs?rev=238624&root=gcc&view=rev
Log:
	PR c++/69223 - ICE with deduced template return type.

	* semantics.c (apply_deduced_return_type): Call
	complete_type_or_else before building the new RESULT_DECL.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
Comment 5 Jason Merrill 2016-07-22 03:47:26 UTC
Author: jason
Date: Fri Jul 22 03:46:54 2016
New Revision: 238627

URL: https://gcc.gnu.org/viewcvs?rev=238627&root=gcc&view=rev
Log:
	PR c++/69223 - ICE with deduced template return type.

	* semantics.c (apply_deduced_return_type): Call
	complete_type_or_else before building the new RESULT_DECL.

Added:
    branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce3.C
Modified:
    branches/gcc-6-branch/gcc/cp/ChangeLog
    branches/gcc-6-branch/gcc/cp/semantics.c
Comment 6 Jason Merrill 2016-07-22 03:51:54 UTC
Author: jason
Date: Fri Jul 22 03:51:22 2016
New Revision: 238630

URL: https://gcc.gnu.org/viewcvs?rev=238630&root=gcc&view=rev
Log:
	PR c++/69223 - ICE with deduced template return type.

	* semantics.c (apply_deduced_return_type): Call
	complete_type_or_else before building the new RESULT_DECL.

Added:
    branches/gcc-5-branch/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce3.C
Modified:
    branches/gcc-5-branch/gcc/cp/ChangeLog
    branches/gcc-5-branch/gcc/cp/semantics.c
Comment 7 Jason Merrill 2016-07-22 03:58:01 UTC
Fixed.
Comment 8 Jason Merrill 2016-07-22 03:58:15 UTC
Author: jason
Date: Fri Jul 22 03:57:43 2016
New Revision: 238631

URL: https://gcc.gnu.org/viewcvs?rev=238631&root=gcc&view=rev
Log:
	PR c++/69223 - ICE with deduced template return type.

	* semantics.c (apply_deduced_return_type): Call
	complete_type_or_else before building the new RESULT_DECL.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce3.C
Modified:
    branches/gcc-4_9-branch/gcc/cp/ChangeLog
    branches/gcc-4_9-branch/gcc/cp/semantics.c