Bug 84518 - [8 Regression] ICE with lambda capturing broken variable
Summary: [8 Regression] ICE with lambda capturing broken variable
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P4 normal
Target Milestone: 9.0
Assignee: Not yet assigned to anyone
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2018-02-22 17:59 UTC by Volker Reichelt
Modified: 2021-05-14 10:41 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-02-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2018-02-22 17:59:34 UTC
The following invalid testcase triggers an ICE on trunk:

============================
template<int> void foo()
{
  int x[=];
  [&x]{};
}

void bar()
{
  foo<0>();
}
============================

bug.cc: In function 'void foo()':
bug.cc:3:9: error: expected primary-expression before '=' token
   int x[=];
         ^
bug.cc:3:10: error: expected primary-expression before ']' token
   int x[=];
          ^
bug.cc: In instantiation of 'void foo() [with int <anonymous> = 0]':
bug.cc:9:10:   required from here
bug.cc:4:3: internal compiler error: tree check: expected class 'expression', have 'exceptional' (error_mark) in tree_operand_check, at tree.h:3630
   [&x]{};
   ^
0x78a846 tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*)
	../../gcc/gcc/tree.c:9385
0x614d34 expr_check(tree_node*, char const*, int, char const*)
	../../gcc/gcc/tree.h:3301
0x614d34 tree_operand_check(tree_node*, int, char const*, int, char const*)
	../../gcc/gcc/tree.h:3630
0x614d34 build_capture_proxy(tree_node*, tree_node*)
	../../gcc/gcc/cp/lambda.c:447
0x8d8596 start_lambda_function(tree_node*, tree_node*)
	../../gcc/gcc/cp/lambda.c:1374
0x95a004 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
	../../gcc/gcc/cp/pt.c:17080
0x95a9e2 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../gcc/gcc/cp/pt.c:18368
0x969349 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../gcc/gcc/cp/pt.c:17130
0x969349 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../gcc/gcc/cp/pt.c:16862
0x968ce0 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../gcc/gcc/cp/pt.c:16079
0x9683c9 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../gcc/gcc/cp/pt.c:16065
0x966481 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../gcc/gcc/cp/pt.c:16346
0x965718 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../gcc/gcc/cp/pt.c:16050
0x965718 instantiate_decl(tree_node*, bool, bool)
	../../gcc/gcc/cp/pt.c:23406
0x98b7ab instantiate_pending_templates(int)
	../../gcc/gcc/cp/pt.c:23522
0x8b1cab c_parse_final_cleanups()
	../../gcc/gcc/cp/decl2.c:4720
Please submit a full bug report, [etc.]

The regression was introduced between 2017-09-26 and 2017-10-07.
Comment 1 Volker Reichelt 2018-02-22 18:14:17 UTC
A modified testcase produces a slightly different stack-trace:

====================================
template<typename T> void foo()
{
  T x[=];
  [&x]{};
}
====================================

bug.cc: In function 'void foo()':
bug.cc:3:7: error: expected primary-expression before '=' token
   T x[=];
       ^
bug.cc:3:8: error: expected primary-expression before ']' token
   T x[=];
        ^
bug.cc: In lambda function:
bug.cc:4:6: internal compiler error: in is_normal_capture_proxy, at cp/lambda.c:289
   [&x]{};
      ^
0x614602 is_normal_capture_proxy(tree_node*)
	../../gcc/gcc/cp/lambda.c:289
0x8d4918 is_capture_proxy_with_ref(tree_node*)
	../../gcc/gcc/cp/lambda.c:301
0x8d49ad insert_capture_proxy(tree_node*)
	../../gcc/gcc/cp/lambda.c:311
0x8d546f build_capture_proxy(tree_node*, tree_node*)
	../../gcc/gcc/cp/lambda.c:474
0x8d8596 start_lambda_function(tree_node*, tree_node*)
	../../gcc/gcc/cp/lambda.c:1374
0x91daad cp_parser_lambda_body
	../../gcc/gcc/cp/parser.c:10662
0x91daad cp_parser_lambda_expression
	../../gcc/gcc/cp/parser.c:10182
0x91daad cp_parser_primary_expression
	../../gcc/gcc/cp/parser.c:5257
0x93043c cp_parser_postfix_expression
	../../gcc/gcc/cp/parser.c:7026
0x931010 cp_parser_unary_expression
	../../gcc/gcc/cp/parser.c:8318
0x91139f cp_parser_cast_expression
	../../gcc/gcc/cp/parser.c:9086
0x911baa cp_parser_binary_expression
	../../gcc/gcc/cp/parser.c:9187
0x9133e4 cp_parser_assignment_expression
	../../gcc/gcc/cp/parser.c:9482
0x913af8 cp_parser_expression
	../../gcc/gcc/cp/parser.c:9651
0x9157b8 cp_parser_expression_statement
	../../gcc/gcc/cp/parser.c:11118
0x91bb2d cp_parser_statement
	../../gcc/gcc/cp/parser.c:10922
0x91d040 cp_parser_statement_seq_opt
	../../gcc/gcc/cp/parser.c:11261
0x91d117 cp_parser_compound_statement
	../../gcc/gcc/cp/parser.c:11215
0x933890 cp_parser_function_body
	../../gcc/gcc/cp/parser.c:21756
0x933890 cp_parser_ctor_initializer_opt_and_function_body
	../../gcc/gcc/cp/parser.c:21793
Please submit a full bug report, [etc.]
Comment 2 David Malcolm 2018-02-22 21:19:40 UTC
Thanks for filing this report.

Confirmed.  Both ICEs started with r253265.

The first ICE (testcase in comment #0) happens at line 446 of lambda.c in build_capture_proxy here:

441	  if (DECL_NORMAL_CAPTURE_P (member))
442	    {
443	      if (DECL_VLA_CAPTURE_P (member))
444		{
445		  init = CONSTRUCTOR_ELT (init, 0)->value;
446		  init = TREE_OPERAND (init, 0); // Strip ADDR_EXPR.
447		  init = TREE_OPERAND (init, 0); // Strip ARRAY_REF.
448		}

where "init" is error_mark.


The second ICE (testcase in comment #1):

Happens at line 288 of lambda.c in is_normal_capture_proxy here:
288	  gcc_assert (TREE_CODE (val) == COMPONENT_REF);

where val is a NOP_EXPR around a COMPONENT_REF (casting from T* to reference to T[]).
Comment 3 Jakub Jelinek 2018-02-23 12:55:10 UTC
Actually P4, error-recovery...
Comment 4 Jakub Jelinek 2018-05-02 10:07:36 UTC
GCC 8.1 has been released.
Comment 5 Jakub Jelinek 2018-07-26 11:21:07 UTC
GCC 8.2 has been released.
Comment 6 Jakub Jelinek 2019-02-22 15:22:50 UTC
GCC 8.3 has been released.
Comment 7 Paolo Carlini 2019-03-07 20:41:41 UTC
These are fixed in trunk: I'm adding the testcases and removing the 9 regression marker.
Comment 8 paolo@gcc.gnu.org 2019-03-07 20:50:14 UTC
Author: paolo
Date: Thu Mar  7 20:49:42 2019
New Revision: 269469

URL: https://gcc.gnu.org/viewcvs?rev=269469&root=gcc&view=rev
Log:
2019-03-07  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/84518
	* g++.dg/cpp0x/lambda/lambda-ice30.C: New.
	* g++.dg/cpp0x/lambda/lambda-ice31.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice30.C
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice31.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 9 Jakub Jelinek 2019-03-07 21:54:47 UTC
It got fixed with r269292 in particular.
Comment 10 Jakub Jelinek 2020-03-04 09:33:19 UTC
GCC 8.4.0 has been released, adjusting target milestone.
Comment 11 Jakub Jelinek 2021-05-14 10:41:56 UTC
The GCC 8 branch is being closed, fixed in GCC 9.1.