Bug 105839 - internal compiler error: in tsubst_omp_for_iterator, at cp/pt.cc:18122 (instantiate_pending_templates -> instantiate_decl -> tsubst_lambda_expr)
Summary: internal compiler error: in tsubst_omp_for_iterator, at cp/pt.cc:18122 (insta...
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, openmp
Depends on:
Blocks:
 
Reported: 2022-06-03 16:49 UTC by northon_patrick3
Modified: 2022-06-21 02:40 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Result from -freport-bug (1.21 KB, text/x-csrc)
2022-06-03 16:49 UTC, northon_patrick3
Details

Note You need to log in before you can comment on or make changes to this bug.
Description northon_patrick3 2022-06-03 16:49:34 UTC
Created attachment 53079 [details]
Result from -freport-bug

The code:
```
void test(const auto &b1)
{
	const auto loopImpl = [&](auto&& fc)
		{
			#pragma omp parallel for
			for(auto&& [v1, v2] : b1);
		};
		
	loopImpl([]{});
}

void test2()
{
	int a[10];
	test(a);
}
```

The command line:
```
g++ -fopenmp test.cpp
```

The error:
```
internal compiler error: in tsubst_omp_for_iterator, at cp/pt.cc:18126
   11 |                         for(auto&& [v1, v2] : b1);
      |                         ^~~
0x1ac4724 internal_error(char const*, ...)
	???:0
0x663b55 fancy_abort(char const*, int, char const*)
	???:0
0x81d054 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
	???:0
0x80614a tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	???:0
0x7fedbe instantiate_decl(tree_node*, bool, bool)
	???:0
0x81e704 instantiate_pending_templates(int)
	???:0
0x7173d1 c_parse_final_cleanups()
	???:0
```

GCC is configured with:

```
configure --prefix=/opt/pat-gcc --libdir=/opt/pat-gcc/lib --libexecdir=/opt/pat-gcc/lib --enable-languages=c,c++,lto --with-isl --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-werror gdc_include_dir=/opt/pat-gcc/include/dlang/gdc
```

It happens from version 10.1 to latest commit at this date.

It no longer crash if:
- I don't use structured bindings.
- b1 isn't a template.
- I remove `auto&& fc`.
Comment 1 Jakub Jelinek 2022-06-03 17:07:15 UTC
Adjusted testcase, so that it is already valid C++17:
template <typename T>
void
foo (const T &x)
{
  [&] (auto&& y)
  {
    #pragma omp parallel for
    for (auto&& [v1, v2] : x)
      ;
  } ([]{});
}

void
bar ()
{
  int a[10];
  foo (a);
}