[all-commits] [llvm/llvm-project] 498e1c: [coroutine] Create coroutine body in the correct e...

Utkarsh Saxena via All-commits all-commits at lists.llvm.org
Thu Jan 18 23:23:37 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 498e1c2257da552abc58aa75f6b9f776bf826f86
      https://github.com/llvm/llvm-project/commit/498e1c2257da552abc58aa75f6b9f776bf826f86
  Author: Utkarsh Saxena <usx at google.com>
  Date:   2024-01-19 (Fri, 19 Jan 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/SemaCoroutine.cpp
    A clang/test/SemaCXX/coroutine-promise-ctor.cpp

  Log Message:
  -----------
  [coroutine] Create coroutine body in the correct eval context (#78589)

Fixes: https://github.com/llvm/llvm-project/issues/78290

See the bug for more context.
```cpp
Gen ACoroutine() {
  if constexpr (0) // remove it make clang compile.
    co_return;
  co_await Gen{};
}
```
We miss symbol of ctor of promise_type if the first coroutine statement
happens to be inside the disabled branch of `if constexpr`.

This happens because the promise object is built when we see the first
coroutine statement which is present in
`ExpressionEvaluationContext::DiscardedStatement` context due to `if
constexpr (0)`. This makes clang believe that the promise constructor is
only odr-used and not really "used".

The expr evaluation context for the coroutine body should not be related
to the context in which the first coroutine statement appears. We
override the context to `PotentiallyEvaluated`.

---------

Co-authored-by: cor3ntin <corentinjabot at gmail.com>




More information about the All-commits mailing list