[clang] [AST] Teach TextNodeDumper to print the "implicit" bit for coroutine AST nodes (PR #77311)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 8 07:33:53 PST 2024


================
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -std=c++20 \
+// RUN:    -fsyntax-only -ast-dump -ast-dump-filter test | FileCheck %s
+
+#include "Inputs/std-coroutine.h"
+
+using namespace std;
+
+struct Task {
+  struct promise_type {
+    std::suspend_always initial_suspend() { return {}; }
+    Task get_return_object() {
+      return std::coroutine_handle<promise_type>::from_promise(*this);
+    }
+    std::suspend_always final_suspend() noexcept { return {}; }
+    std::suspend_always return_void() { return {}; }
+    void unhandled_exception() {}
+
+    auto await_transform(int s) {
+      struct awaiter {
+        promise_type *promise;
+        bool await_ready() { return true; }
+        int await_resume() { return 1; }
+        void await_suspend(std::coroutine_handle<>) {}
+      };
+
+      return awaiter{this};
+    }
+  };
+
+  Task(std::coroutine_handle<promise_type> promise);
+
+  std::coroutine_handle<promise_type> handle;
+};
+
+// Verify the implicit AST nodes for coroutines.
+Task test()  {
+  co_await 1;
+}
+// CHECK:        |-DeclStmt {{.*}}
+// CHECK-NEXT:   | `-VarDecl {{.*}} implicit used __promise
+// CHECK-NEXT:   |   `-CXXConstructExpr {{.*}}
+// CHECK-NEXT:   |-ExprWithCleanups {{.*}} 'void'
+// CHECK-NEXT:   | `-CoawaitExpr {{.*}} 'void' implicit
----------------
ilya-biryukov wrote:

Is this node implicit for initial suspend, for a call to `await_transform` or both? It would be useful to clarify by matching some child nodes or the dump of `CoawaitExpr` itself.

Also, could you add matching for both implicit and non-implicit `co_await` and `co_return` instances to show that the bit does not incidentally gets set/unset all the time?

Fixing `CoreturnStmt` in a follow-up does make a lot of sense!

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


More information about the cfe-commits mailing list