[PATCH] D157296: [AST][Coroutine] Fix CoyieldExpr missing end loc

Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 9 17:05:14 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG8d60e10ce4bd: [AST][Coroutine] Fix CoyieldExpr missing end loc (authored by dingfei <fding at feysh.com>).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157296/new/

https://reviews.llvm.org/D157296

Files:
  clang/lib/Sema/SemaCoroutine.cpp
  clang/test/AST/Inputs/std-coroutine.h
  clang/test/AST/coroutine-co_yield-source-range.cpp


Index: clang/test/AST/coroutine-co_yield-source-range.cpp
===================================================================
--- /dev/null
+++ clang/test/AST/coroutine-co_yield-source-range.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 \
+// RUN:    -fsyntax-only -ast-dump | FileCheck %s
+
+#include "Inputs/std-coroutine.h"
+
+using namespace std;
+
+struct Chat {
+  struct promise_type {
+    std::suspend_always initial_suspend() { return {}; }
+    Chat get_return_object() {
+      return std::coroutine_handle<promise_type>::from_promise(*this);
+    }
+    std::suspend_always yield_value(int m) { return {}; }
+    std::suspend_always final_suspend() noexcept { return {}; }
+    std::suspend_always return_value(int) { return {}; }
+    void unhandled_exception() {}
+
+    auto await_transform(int s) {
+      struct awaiter {
+        promise_type *promise;
+        bool await_ready() { return true; }
+        int await_resume() { return promise->message; }
+        void await_suspend(std::coroutine_handle<>) {}
+      };
+
+      return awaiter{this};
+    }
+    int message;
+  };
+
+  Chat(std::coroutine_handle<promise_type> promise);
+
+  std::coroutine_handle<promise_type> handle;
+};
+
+Chat f(int s)  {
+  // CHECK:      CoyieldExpr {{.*}} <col:3, col:12>
+  // CHECK-NEXT:   CXXMemberCallExpr {{.*}} <col:3, col:12> {{.*}}
+  // CHECK-NEXT:     MemberExpr {{.*}} <col:3> {{.*}}
+  // CHECK-NEXT:       DeclRefExpr {{.*}} <col:3> {{.*}}
+  // CHECK-NEXT:     ImplicitCastExpr {{.*}} <col:12> {{.*}}
+  // CHECK-NEXT:       DeclRefExpr {{.*}} <col:12> {{.*}}
+  co_yield s;
+  // CHECK:      CoreturnStmt {{.*}} <line:{{.*}}:3, col:13>
+  co_return s;
+  // CHECK:      CoawaitExpr {{.*}} <col:3, col:12> 'int'
+  co_await s;
+}
Index: clang/test/AST/Inputs/std-coroutine.h
===================================================================
--- clang/test/AST/Inputs/std-coroutine.h
+++ clang/test/AST/Inputs/std-coroutine.h
@@ -55,9 +55,9 @@
 };
 
 struct suspend_always {
-  bool await_ready() { return false; }
-  void await_suspend(coroutine_handle<>) {}
-  void await_resume() {}
+  bool await_ready() noexcept { return false; }
+  void await_suspend(coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
 };
 
 struct suspend_never {
Index: clang/lib/Sema/SemaCoroutine.cpp
===================================================================
--- clang/lib/Sema/SemaCoroutine.cpp
+++ clang/lib/Sema/SemaCoroutine.cpp
@@ -318,7 +318,8 @@
     return ExprError();
   }
 
-  return S.BuildCallExpr(nullptr, Result.get(), Loc, Args, Loc, nullptr);
+  auto EndLoc = Args.empty() ? Loc : Args.back()->getEndLoc();
+  return S.BuildCallExpr(nullptr, Result.get(), Loc, Args, EndLoc, nullptr);
 }
 
 // See if return type is coroutine-handle and if so, invoke builtin coro-resume


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157296.548823.patch
Type: text/x-patch
Size: 2856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230810/7b41b4b0/attachment.bin>


More information about the cfe-commits mailing list