https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127884

            Bug ID: 127884
           Summary: [15/17 Regression] ICE with co_await in range-for
                    initializer
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: [email protected]
  Target Milestone: ---

Reproducing code:
```
namespace std {
template <class R, class...>
struct coroutine_traits {
    using promise_type = typename R::promise_type;
};
template <class P = void>
struct coroutine_handle;
template <>
struct coroutine_handle<void> {
    static coroutine_handle from_address(void*);
    void* address();
    void* ptr_ = nullptr;
};
template <class P>
struct coroutine_handle : coroutine_handle<> {
    static coroutine_handle from_address(void*);
};
struct suspend_always {
    bool await_ready() noexcept;
    void await_suspend(coroutine_handle<>) noexcept;
    void await_resume() noexcept;
};
} // namespace std

struct Range {
    int* begin();
    int* end();
};

struct Task {
    struct promise_type {
        Task get_return_object();
        std::suspend_always initial_suspend();
        std::suspend_always final_suspend() noexcept;
        void return_void();
        void unhandled_exception();
    };
    bool await_ready();
    std::coroutine_handle<> await_suspend(std::coroutine_handle<>);
    Range await_resume();
};

Task f() {
    for (int i : co_await f()) {
    }
}
```


Command:
```
./gcc/xg++ -B./gcc -nostdinc++ -std=c++23 -c repro.cc
```
It works when the `-fno-range-for-ext-temps` flag is added.


I reproduced on latest master: 51ade34151dff8e444bfe3623373f42c1a29b5fa
The master build has this version output:
```
Using built-in specs.
COLLECT_GCC=./gcc/xg++
Target: x86_64-pc-linux-gnu
Configured with: /usr/scratch/tmp/gcc15/bisect/src-master/configure
--enable-languages=c++ --disable-bootstrap --disable-multilib
--disable-libsanitizer --disable-libstdcxx-pch --disable-nls
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 17.0.0 20261012 (experimental) (GCC)
```

I can also reproduce on GCC15: ee148006fd5d11f438358e1f46367d806c0664a1


I suspect this is the first commit to break it based on a bisect:
a169a4718b5b621f1770789e55eb8c441f7d0fcd ("c++, coroutines: Remove use of
coroutine handle in the frame.")


Output on master (abridged):
```
/usr/scratch/tmp/gcc15/repro_noinclude.cc: In function 'void f(_Z1fv.Frame*)':
/usr/scratch/tmp/gcc15/repro_noinclude.cc:48:1: internal compiler error: in
expand_one_await_expression, at cp/coroutines.cc:2207
   48 | }
      | ^
0x2bf0efd internal_error(char const*, ...)
       
/usr/scratch/tmp/gcc15/bisect/src-master/gcc/diagnostic-global-context.cc:787
0xb76357 fancy_abort(char const*, int, char const*)
       
/usr/scratch/tmp/gcc15/bisect/src-master/gcc/diagnostics/context.cc:1813
0x80b27f expand_one_await_expression
        /usr/scratch/tmp/gcc15/bisect/src-master/gcc/cp/coroutines.cc:2207
0xc07f63 process_one_statement
        /usr/scratch/tmp/gcc15/bisect/src-master/gcc/cp/coroutines.cc:2345
0xc07f63 await_statement_expander
        /usr/scratch/tmp/gcc15/bisect/src-master/gcc/cp/coroutines.cc:2372
0x19acd7f walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        /usr/scratch/tmp/gcc15/bisect/src-master/gcc/tree.cc:11869
```

Reply via email to