Bug 78018 - [C++14] "internal compiler error: Segmentation fault" with templates and lambdas
Summary: [C++14] "internal compiler error: Segmentation fault" with templates and lambdas
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.2.0
: P3 normal
Target Milestone: 6.4
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2016-10-18 11:22 UTC by andipeer
Modified: 2022-03-11 00:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 5.4.0, 6.2.0, 7.0
Last reconfirmed: 2016-10-18 00:00:00


Attachments
Minimal working example for triggering the crash (164 bytes, text/plain)
2016-10-18 11:22 UTC, andipeer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description andipeer 2016-10-18 11:22:39 UTC
Created attachment 39828 [details]
Minimal working example for triggering the crash

Trying to compile the minimal working example that is attached, the compiler crashes with a segfault. The exact output is stated below. The code should be correct, as other compilers like Clang have no problem in compiling it.
Note that the bug does not occur if all methods of A are declared inline. Also note that removing one element of the template-lambda call chain, the bug does not occur, neither.

Command line: "g++ -std=c++14 -c error.cpp"

The error that is thrown is:

error.cpp: In member function ‘void A::f2(F) [with F = A::f1()::<lambda(auto:1)>]’:
error.cpp:24:6: internal compiler error: Segmentation fault
 void A::f2(F f)
      ^
0xad48ef crash_signal
	../../src/gcc/toplev.c:333
0xd286ba wi::extended_tree<128>::get_len() const
	../../src/gcc/tree.h:5268
0xd286ba wi::int_traits<generic_wide_int<wi::extended_tree<128> > >::decompose(long*, unsigned int, generic_wide_int<wi::extended_tree<128> > const&)
	../../src/gcc/wide-int.h:898
0xd286ba wide_int_ref_storage<true>::wide_int_ref_storage<generic_wide_int<wi::extended_tree<128> > >(generic_wide_int<wi::extended_tree<128> > const&, unsigned int)
	../../src/gcc/wide-int.h:945
0xd286ba generic_wide_int<wide_int_ref_storage<true> >::generic_wide_int<generic_wide_int<wi::extended_tree<128> > >(generic_wide_int<wi::extended_tree<128> > const&, unsigned int)
	../../src/gcc/wide-int.h:722
0xd286ba wi::unary_traits<generic_wide_int<wi::extended_tree<128> > >::result_type wi::lshift<generic_wide_int<wi::extended_tree<128> >, int>(generic_wide_int<wi::extended_tree<128> > const&, int const&)
	../../src/gcc/wide-int.h:2847
0xd286ba int_bit_position(tree_node const*)
	../../src/gcc/tree.h:5377
0xd286ba classify_argument
	../../src/gcc/config/i386/i386.c:8095
0xd28b89 examine_argument
	../../src/gcc/config/i386/i386.c:8409
0xd28de6 function_arg_advance_64
	../../src/gcc/config/i386/i386.c:8822
0xd28de6 ix86_function_arg_advance
	../../src/gcc/config/i386/i386.c:8915
0x8afd94 gimplify_parameters()
	../../src/gcc/function.c:3999
0x8e5ef4 gimplify_body(tree_node*, bool)
	../../src/gcc/gimplify.c:11522
0x8e6097 gimplify_function_tree(tree_node*)
	../../src/gcc/gimplify.c:11682
0x7c5087 cgraph_node::analyze()
	../../src/gcc/cgraphunit.c:625
0x7c7a2f analyze_functions
	../../src/gcc/cgraphunit.c:1086
0x7c81a8 symbol_table::finalize_compilation_unit()
	../../src/gcc/cgraphunit.c:2542
Comment 1 Markus Trippelsdorf 2016-10-18 11:59:53 UTC
Confirmed. It is not a regression, because it never worked.

Even icc crashes:

markus@x4 tmp % icpc -c error.cpp
error.cpp(20): internal error: bad pointer
      f2([&] (auto t) { f3(t); } );
                        ^
compilation aborted for error.cpp (code 4)

Clang accepts the code.
Comment 2 paolo@gcc.gnu.org 2017-10-04 20:34:34 UTC
Author: paolo
Date: Wed Oct  4 20:34:03 2017
New Revision: 253430

URL: https://gcc.gnu.org/viewcvs?rev=253430&root=gcc&view=rev
Log:
2017-10-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/78018
	* g++.dg/cpp1y/lambda-generic-78018.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/lambda-generic-78018.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 3 Paolo Carlini 2017-10-04 20:35:47 UTC
Fixed in 6.4.0.