[clang] [coroutine] Create coroutine body in the correct eval context (PR #78589)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 18 11:44:19 PST 2024


================
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++20 -ast-dump %s | FileCheck %s
+#include "Inputs/std-coroutine.h"
+
+// Github issue: https://github.com/llvm/llvm-project/issues/78290
+class Gen {
+   public:
+    class promise_type {
+       public:
+        template<typename... Args>
+        explicit promise_type(Args...) {}
+        // CHECK:       CXXConstructorDecl {{.*}} used promise_type 'void ()' {{.*}}
+        // CHECK-NEXT:     TemplateArgument pack
+        // CHECK-NEXT:     CompoundStmt {{.*}}
+        Gen get_return_object() { return {}; }
+
+        void unhandled_exception() {}
+        void return_void() {}
+        std::suspend_always await_transform(Gen gen) { return {}; }
+
+        std::suspend_always initial_suspend() { return {}; }
+        // CHECK: CXXMethodDecl {{.*}} used initial_suspend {{.*}}
+        std::suspend_always final_suspend() noexcept { return {}; }
+        // CHECK: CXXMethodDecl {{.*}} used final_suspend {{.*}}
+    };
+};
+
+Gen CoroutineBody() {
+    if constexpr (0) {
+        co_await Gen{};
+    }
+    co_await Gen{};
+}
+
+int main() { return 0; }
----------------
hokein wrote:

nit: we do the verification by checking the presence  of CompoundStmt, the main function is not needed.

https://github.com/llvm/llvm-project/pull/78589


More information about the cfe-commits mailing list