This is an archive of the discontinued LLVM Phabricator instance.

[coroutines] Fix co_await for range statement
ClosedPublic

Authored by EricWF on Jun 7 2017, 10:15 PM.

Details

Summary

Currently we build the co_await expressions on the wrong implicit statements of the implicit ranged for; Specifically we build the co_await expression wrapping the range declaration, but it should wrap the begin expression.

This patch fixes co_await on range for.

Diff Detail

Event Timeline

EricWF created this revision.Jun 7 2017, 10:15 PM
EricWF updated this revision to Diff 101853.Jun 7 2017, 10:18 PM
  • Add FIXME comments for incorrect use of getCurScope() after initial parse.
EricWF updated this revision to Diff 101854.Jun 7 2017, 10:20 PM
  • Fix clang-format nonsense in tests.
EricWF updated this revision to Diff 101857.Jun 7 2017, 10:26 PM
  • More test cleanup. Sorry for the noise.
EricWF updated this revision to Diff 101858.Jun 7 2017, 10:27 PM
EricWF updated this revision to Diff 101862.Jun 8 2017, 12:09 AM
  • Fix value category of co_await/co_yield expression. ie use the return type of the resume expression to determine the value category.

@rsmith Should the CoroutineSuspendExpr constructor be using getCallReturnType() to determine the correct value category, or is the current formulation correct?

EricWF added inline comments.Jun 8 2017, 6:22 PM
test/SemaCXX/coawait_range_for.cpp
133 ↗(On Diff #101862)

This test is incorrect WRT ADL lookup.

This revision is now accepted and ready to land.Jun 12 2017, 6:49 PM
EricWF added inline comments.Jun 13 2017, 12:45 PM
include/clang/AST/ExprCXX.h
4136 ↗(On Diff #101862)

@rsmith Does this make sense, since the resume expression is a function call, or am I way off base in determining the expressions value category?

EricWF updated this revision to Diff 102472.Jun 13 2017, 8:23 PM
  • Remove changes to how CoroutineSuspendExprs ExprValueType is calculated. They were incorrect. However this means that Clang still fails to compile co_await and co_yield expressions where await_resume returns an lvalue reference. @GorNishanov Can you take a look at this? Reproducer:
struct AwaitResumeReturnsLValue {
  bool await_ready();
  void await_suspend(std::experimental::coroutine_handle<>);
  int& await_resume();
};

void AwaitReturnsLValue() {
  AwaitResumeReturnsLValue a;
  int& x = co_await a;
}
EricWF closed this revision.Jun 13 2017, 8:25 PM