Bug 58706 - ICE with lambda in OpenMP for-loop
Summary: ICE with lambda in OpenMP for-loop
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, openmp
Depends on:
Blocks:
 
Reported: 2013-10-12 21:44 UTC by Volker Reichelt
Modified: 2017-10-10 17:13 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.5.0, 4.6.0, 4.7.0, 4.8.0, 4.9.0, 6.1.0
Last reconfirmed: 2016-08-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2013-10-12 21:44:00 UTC
The following valid code snippet (compiled with "-std=c++11 -fopenmp") triggers an ICE since GCC 4.5.0 (when lambdas were introduced):

===================================================
template<typename T> void foo()
{
#pragma omp for
  for (T i = [](){ return 0; }(); i < 10; ++i)
    ;
}

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

bug.cc: In instantiation of 'void foo() [with T = int]':
bug.cc:10:12:   required from here
bug.cc:3:9: internal compiler error: Segmentation fault
 #pragma omp for
         ^
0xb15dff crash_signal
        ../../gcc/gcc/toplev.c:335
0x6cabd2 contains_struct_check
        ../../gcc/gcc/tree.h:2787
0x6cabd2 finish_omp_for(unsigned int, tree_code, tree_node*, tree_node*, tree_node*, tree_node*, tree_node*, tree_node*, tree_node*)
        ../../gcc/gcc/cp/semantics.c:6321
0x5aae3d tsubst_expr
        ../../gcc/gcc/cp/pt.c:13596
0x5a9db7 tsubst_expr
        ../../gcc/gcc/cp/pt.c:13384
0x5a6d69 instantiate_decl(tree_node*, int, bool)
        ../../gcc/gcc/cp/pt.c:19603
0x5e4c6f instantiate_pending_templates(int)
        ../../gcc/gcc/cp/pt.c:19715
0x6204c6 cp_write_global_declarations()
        ../../gcc/gcc/cp/decl2.c:4121
Please submit a full bug report, [etc.]
Comment 1 Andrew Pinski 2016-08-07 18:02:31 UTC
Confirmed:
t88.cc: In instantiation of 'void foo() [with T = int]':
t88.cc:10:12:   required from here
t88.cc:3:9: internal compiler error: in tsubst_copy, at cp/pt.c:14042
 #pragma omp for
         ^~~
0x5d0f73 tsubst_copy
        ../../gcc/gcc/cp/pt.c:14040
0x5d16b3 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
        ../../gcc/gcc/cp/pt.c:16992
0x5cbcd3 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc/gcc/cp/pt.c:15801
0x5ccc6f tsubst_omp_for_iterator
        ../../gcc/gcc/cp/pt.c:14880
0x5ccc6f tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc/gcc/cp/pt.c:15524
0x5cc44f tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc/gcc/cp/pt.c:15289
0x5e6987 instantiate_decl(tree_node*, int, bool)
        ../../gcc/gcc/cp/pt.c:22013
0x5e875f instantiate_pending_templates(int)
        ../../gcc/gcc/cp/pt.c:22130
0x607d1b c_parse_final_cleanups()
        ../../gcc/gcc/cp/decl2.c:4599
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 2 Jakub Jelinek 2016-08-08 14:49:44 UTC
This isn't valid code, as OpenMP doesn't support C++11 and later, so in order to stay in the well defined territory, you shouldn't use C++11 and later constructs in OpenMP constructs.
Comment 3 Jakub Jelinek 2016-08-08 19:51:01 UTC
Author: jakub
Date: Mon Aug  8 19:50:29 2016
New Revision: 239251

URL: https://gcc.gnu.org/viewcvs?rev=239251&root=gcc&view=rev
Log:
	PR c++/58706
	* parser.c: Include tree-iterator.h.
	(cp_parser_omp_for_loop_init): Move lambda DECL_EXPRs from init
	to FOR_BLOCK.
	(cp_parser_omp_for_loop): Handle non-STATEMENT_LIST FOR_BLOCK
	entries.

	* testsuite/libgomp.c++/pr58706.C: New test.

Added:
    trunk/libgomp/testsuite/libgomp.c++/pr58706.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/libgomp/ChangeLog
Comment 4 Paolo Carlini 2017-10-10 17:13:11 UTC
Fixed in 7.1.0 then.