public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc"
@ 2024-01-17 20:09 dboles.src at gmail dot com
2024-01-17 20:33 ` [Bug c++/113457] " mpolacek at gcc dot gnu.org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: dboles.src at gmail dot com @ 2024-01-17 20:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
Bug ID: 113457
Summary: Trying to emulate views::concat with std::generator
gives ICE on co_yield: "internal compiler error: in
canonicalize_component_ref, at gimplify.cc"
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dboles.src at gmail dot com
Target Milestone: ---
Created attachment 57118
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57118&action=edit
.ii and .s files
I'm using Debian's snapshot:
g++ (Debian 20240101-1) 14.0.0 20240101 (experimental) [master
r14-6875-g3a7dd24eade]
I don't see any likely / still-open dupes, but of course I'm happy if this was
already reported! But in case not...
I'm trying to implement a simple `views::concat` analog by following this
answer:
* https://stackoverflow.com/a/76869567
The answer is a bit limited in real-world use, as we should be able to mix
ranges of different-but-compatible value types. So in reality we'd use
common_reference_t, common_type_t, etc. - but for this repro I simplify by
mixing ranges of either int or double values, to a std::generator<double,
double>:
```cpp
#include <array>
#include <generator>
#include <ranges>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;
template <ranges::input_range... Ranges>
[[nodiscard]] auto
concat(Ranges&&... ranges) -> generator<double, double>
{
(co_yield ranges::elements_of(ranges), ...);
}
auto
main() -> int
{
auto const numbers1 = {4, 8, 15, 16, 23, 42};
auto const numbers2 = vector{11, 22, 77, 99};
auto const numbers3 = array{0.5, 1.0, 1.333};
return *concat(numbers1, numbers2, numbers3).begin();
}
```
This ICEs as follows:
```none
concatICE.cpp: In function 'void concat(concat<const
std::initializer_list<int>&, const std::vector<int, std::allocator<int> >&,
const std::array<double, 3>&>(const std::initializer_list<int>&, const
std::vector<int, std::allocator<int> >&, const std::array<double,
3>&)::_Z6concatITpTkNSt6ranges11input_rangeEJRKSt16initializer_listIiERKSt6vectorIiSaIiEERKSt5arrayIdLm3EEEESt9generatorIddvEDpOT_.Frame*)':
concatICE.cpp:14:10: internal compiler error: in canonicalize_component_ref, at
gimplify.cc:3153
14 | (co_yield ranges::elements_of(ranges), ...);
| ^~~~~~~~
0x93a07c canonicalize_component_ref(tree_node**) [clone .isra.0]
../../src/gcc/gimplify.cc:3153
0x1e0d70d gimplify_compound_lval
../../src/gcc/gimplify.cc:3570
0x1d76e41 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
../../src/gcc/gimplify.cc:17722
0x1dd275d gimplify_addr_expr
../../src/gcc/gimplify.cc:6811
0x1d76f99 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
../../src/gcc/gimplify.cc:17817
0x1e2b958 gimplify_expr
../../src/gcc/gimplify.cc:18839
0x1e2b958 gimplify_arg(tree_node**, gimple**, unsigned int, bool)
../../src/gcc/gimplify.cc:3748
0x20b22ed cp_gimplify_arg
../../src/gcc/cp/cp-gimplify.cc:582
0x1ea2994 cp_gimplify_expr(tree_node**, gimple**, gimple**)
../../src/gcc/cp/cp-gimplify.cc:852
0x1d76ba1 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
../../src/gcc/gimplify.cc:17679
0x1d774a8 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
../../src/gcc/gimplify.cc:18547
0x1d864e3 gimplify_modify_expr
../../src/gcc/gimplify.cc:6402
0x1d76f7c gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
../../src/gcc/gimplify.cc:17770
0x1eeac68 gimplify_stmt(tree_node**, gimple**)
../../src/gcc/gimplify.cc:7477
0x1eeac68 gimplify_cleanup_point_expr
../../src/gcc/gimplify.cc:7215
0x1d77a44 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
../../src/gcc/gimplify.cc:18163
0x1dc3162 gimplify_cond_expr
../../src/gcc/gimplify.cc:4713
0x1d77a5d gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
../../src/gcc/gimplify.cc:17727
0x1d77ad0 gimplify_stmt(tree_node**, gimple**)
../../src/gcc/gimplify.cc:7477
0x1d77ad0 gimplify_statement_list
../../src/gcc/gimplify.cc:2222
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-snapshot/README.Bugs> for instructions.
shell returned 1
```
The save-temps output is attached.
Thanks for any help and all the amazing work on GCC and C++!
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/113457] Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc"
2024-01-17 20:09 [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc" dboles.src at gmail dot com
@ 2024-01-17 20:33 ` mpolacek at gcc dot gnu.org
2024-01-17 20:59 ` dboles.src at gmail dot com
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-17 20:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2024-01-17
Keywords| |needs-bisection,
| |needs-reduction
Status|UNCONFIRMED |NEW
CC| |mpolacek at gcc dot gnu.org
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.
GCC 13 says "fatal error: generator: No such file or directory" so I don't know
if it's a regression or not.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/113457] Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc"
2024-01-17 20:09 [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc" dboles.src at gmail dot com
2024-01-17 20:33 ` [Bug c++/113457] " mpolacek at gcc dot gnu.org
@ 2024-01-17 20:59 ` dboles.src at gmail dot com
2024-01-17 21:08 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: dboles.src at gmail dot com @ 2024-01-17 20:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
--- Comment #2 from Daniel Boles <dboles.src at gmail dot com> ---
Yeah, std::generator is new for GCC/libstdc++ v14. I think it landed a month or
two ago. I'm just getting started using it now. Getting in early bug-finding :)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/113457] Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc"
2024-01-17 20:09 [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc" dboles.src at gmail dot com
2024-01-17 20:33 ` [Bug c++/113457] " mpolacek at gcc dot gnu.org
2024-01-17 20:59 ` dboles.src at gmail dot com
@ 2024-01-17 21:08 ` redi at gcc dot gnu.org
2024-01-17 21:16 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-17 21:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
A little less than a month ago, Dec 21.
I'm trying to bisect it. A slightly modified copy of trunk headers (to remove
the use of explicit object member functions) compiles with GCC 13.1 but ICEs
with the releases/gcc-13 branchpoint, so might be an ice-with-checking
GCC 13.1 with -std=c++23 -fchecking=3 bails out with:
gen.cc: In function 'void concat(concat<const std::initializer_list<int>&,
const std::vector<int, std::allocator<int> >&, const std::array<double,
3>&>(const std::initializer_list<int>&, const std::vector<int,
std::allocator<int> >&, const std::array<double,
3>&)::_Z6concatIJRKSt16initializer_listIiERKSt6vectorIiSaIiEERKSt5arrayIdLm3EEEESt9generatorIddvEDpOT_.Frame*)':
gen.cc:12:1: error: type mismatch in 'component_ref'
12 | concat(Ranges&&... ranges) -> generator<double, double>
| ^~~~~~
struct _Recursive_awaiter
struct _Recursive_awaiter
gen.cc:12:1: error: invalid LHS in gimple call
frame_ptr->Yd0_2_3 = std::__gen::_Promise_erased<const
double&>::yield_value<const std::initializer_list<int>&,
std::allocator<std::byte> > (_15, _16); [return slot optimization]
gen.cc:12:1: error: type mismatch in 'component_ref'
struct _Recursive_awaiter
struct _Recursive_awaiter
gen.cc:12:1: error: invalid LHS in gimple call
frame_ptr->Yd0_2_3 = std::__gen::_Promise_erased<const
double&>::yield_value<const std::vector<int, std::allocator<int> >&,
std::allocator<std::byte> > (_23, _24); [return slot optimization]
gen.cc:12: confused by earlier errors, bailing out
I'll attach the .ii I'm using.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/113457] Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc"
2024-01-17 20:09 [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc" dboles.src at gmail dot com
` (2 preceding siblings ...)
2024-01-17 21:08 ` redi at gcc dot gnu.org
@ 2024-01-17 21:16 ` redi at gcc dot gnu.org
2024-01-18 2:02 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-17 21:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Created attachment 57121
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57121&action=edit
Gzipped preprocessed source
This ICEs with current trunk, and r14-1 and r13-1 with this error:
gen.cc:14:10: internal compiler error: in canonicalize_component_ref, at
gimplify.cc:3153
With r12-1 it's a bit different, but still ICEs:
/home/jwakely/gcc/14/include/c++/14.0.1/ranges:6116:30: internal compiler
error: in enforce_access, at cp/semantics.c:366
However, anything older than GCC 14.0.0 gives dozens of errors about new C++23
features that aren't understood, so I'm not sure how meaningful anything above
is. It needs reducing.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/113457] Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc"
2024-01-17 20:09 [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc" dboles.src at gmail dot com
` (3 preceding siblings ...)
2024-01-17 21:16 ` redi at gcc dot gnu.org
@ 2024-01-18 2:02 ` pinskia at gcc dot gnu.org
2024-01-18 3:47 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-18 2:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reducing ...
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/113457] Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc"
2024-01-17 20:09 [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc" dboles.src at gmail dot com
` (4 preceding siblings ...)
2024-01-18 2:02 ` pinskia at gcc dot gnu.org
@ 2024-01-18 3:47 ` pinskia at gcc dot gnu.org
2024-01-18 7:51 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-18 3:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So you can reproduce it easier without even vector or array:
```
#include <generator>
using namespace std;
template <ranges::input_range... Ranges>
[[nodiscard]] auto
concat(Ranges&&... ranges) -> generator<double, double>
{
(co_yield ranges::elements_of(ranges), ...);
}
auto
main() -> int
{
int const numbers1[] = {4, 8, 15, 16, 23, 42};
double const numbers2[] = {4, 8, 15, 16, 23, 42};
return *concat(numbers1, numbers2).begin();
}
```
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/113457] Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc"
2024-01-17 20:09 [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc" dboles.src at gmail dot com
` (5 preceding siblings ...)
2024-01-18 3:47 ` pinskia at gcc dot gnu.org
@ 2024-01-18 7:51 ` pinskia at gcc dot gnu.org
2024-08-23 17:37 ` [Bug c++/113457] Nesting coroutine definitions (e.g. via a lambda or a template expansion) can ICE the compiler arsen at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-18 7:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 57134
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57134&action=edit
Reduced as far as I can make it right now
Here is more reduced testcase though I see it depends on
__remove_reference/__remove_cv/__is_array though.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/113457] Nesting coroutine definitions (e.g. via a lambda or a template expansion) can ICE the compiler
2024-01-17 20:09 [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc" dboles.src at gmail dot com
` (6 preceding siblings ...)
2024-01-18 7:51 ` pinskia at gcc dot gnu.org
@ 2024-08-23 17:37 ` arsen at gcc dot gnu.org
2024-08-26 23:05 ` cvs-commit at gcc dot gnu.org
2024-08-29 12:16 ` arsen at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: arsen at gcc dot gnu.org @ 2024-08-23 17:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
Arsen Arsenović <arsen at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Trying to emulate |Nesting coroutine
|views::concat with |definitions (e.g. via a
|std::generator gives ICE on |lambda or a template
|co_yield: "internal |expansion) can ICE the
|compiler error: in |compiler
|canonicalize_component_ref, |
|at gimplify.cc" |
Assignee|unassigned at gcc dot gnu.org |arsen at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #8 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
reduced more:
#include <coroutine>
struct coro
{
struct promise_type
{
std::suspend_never initial_suspend ();
std::suspend_never final_suspend () noexcept;
void return_void ();
void unhandled_exception ();
coro get_return_object ();
};
};
struct not_quite_suspend_never : std::suspend_never
{};
coro
foo ()
{
co_await std::suspend_never{},
[] () -> coro { co_return; },
co_await not_quite_suspend_never{};
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/113457] Nesting coroutine definitions (e.g. via a lambda or a template expansion) can ICE the compiler
2024-01-17 20:09 [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc" dboles.src at gmail dot com
` (7 preceding siblings ...)
2024-08-23 17:37 ` [Bug c++/113457] Nesting coroutine definitions (e.g. via a lambda or a template expansion) can ICE the compiler arsen at gcc dot gnu.org
@ 2024-08-26 23:05 ` cvs-commit at gcc dot gnu.org
2024-08-29 12:16 ` arsen at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-08-26 23:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Arsen Arsenovic <arsen@gcc.gnu.org>:
https://gcc.gnu.org/g:5cca7517c5868b7b9aa13992145eb6082ac5d5b9
commit r15-3203-g5cca7517c5868b7b9aa13992145eb6082ac5d5b9
Author: Arsen ArsenoviÄ <arsen@aarsen.me>
Date: Fri Aug 23 20:19:05 2024 +0200
c++/coros: do not assume coros don't nest [PR113457]
In the testcase presented in the PR, during template expansion, an
tsubst of an operand causes a lambda coroutine to be processed, causing
it to get an initial suspend and final suspend. The code for assigning
awaitable var names (get_awaitable_var) assumed that the sequence Is ->
Is -> Fs -> Fs is impossible (i.e. that one could only 'open' one
coroutine before closing it at a time), and reset the counter used for
unique numbering each time a final suspend occured. This assumption is
false in a few cases, usually when lambdas are involved.
Instead of storing this counter in a static-storage variable, we can
store it in coroutine_info. This struct is local to each function, so
we don't need to worry about "cross-contamination" nor resetting.
PR c++/113457
gcc/cp/ChangeLog:
* coroutines.cc (struct coroutine_info): Add integer field
awaitable_number. This is a counter used for assigning unique
names to awaitable temporaries.
(get_awaitable_var): Use awaitable_number from coroutine_info
instead of the static int awn.
gcc/testsuite/ChangeLog:
* g++.dg/coroutines/pr113457-1.C: New test.
* g++.dg/coroutines/pr113457.C: New test.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/113457] Nesting coroutine definitions (e.g. via a lambda or a template expansion) can ICE the compiler
2024-01-17 20:09 [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc" dboles.src at gmail dot com
` (8 preceding siblings ...)
2024-08-26 23:05 ` cvs-commit at gcc dot gnu.org
@ 2024-08-29 12:16 ` arsen at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: arsen at gcc dot gnu.org @ 2024-08-29 12:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
Arsen Arsenović <arsen at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |WAITING
--- Comment #10 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
fixed on trunk, maybe a backport candidate
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-08-29 12:17 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17 20:09 [Bug c++/113457] New: Trying to emulate views::concat with std::generator gives ICE on co_yield: "internal compiler error: in canonicalize_component_ref, at gimplify.cc" dboles.src at gmail dot com
2024-01-17 20:33 ` [Bug c++/113457] " mpolacek at gcc dot gnu.org
2024-01-17 20:59 ` dboles.src at gmail dot com
2024-01-17 21:08 ` redi at gcc dot gnu.org
2024-01-17 21:16 ` redi at gcc dot gnu.org
2024-01-18 2:02 ` pinskia at gcc dot gnu.org
2024-01-18 3:47 ` pinskia at gcc dot gnu.org
2024-01-18 7:51 ` pinskia at gcc dot gnu.org
2024-08-23 17:37 ` [Bug c++/113457] Nesting coroutine definitions (e.g. via a lambda or a template expansion) can ICE the compiler arsen at gcc dot gnu.org
2024-08-26 23:05 ` cvs-commit at gcc dot gnu.org
2024-08-29 12:16 ` arsen at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).