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
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ 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] 8+ messages in thread

end of thread, other threads:[~2024-01-18  7:51 UTC | newest]

Thread overview: 8+ 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

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).