[Coroutines] Pass size parameter for deallocation function when qualified
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Mon, 6 Feb 2023 16:20:50 +0000 (00:20 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Mon, 6 Feb 2023 16:22:22 +0000 (00:22 +0800)
Close https://github.com/llvm/llvm-project/issues/60545.

Previously, we would only pass the size parameter to the deallocation
function if the type is completely the same. But it is good enough to
make them unqualified the smae.

clang/lib/Sema/SemaCoroutine.cpp
clang/test/SemaCXX/coroutine-dealloc.cpp

index 79c08ad..9678e30 100644 (file)
@@ -1562,7 +1562,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
   const auto *OpDeleteType =
       OpDeleteQualType.getTypePtr()->castAs<FunctionProtoType>();
   if (OpDeleteType->getNumParams() > DeleteArgs.size() &&
-      S.getASTContext().hasSameType(
+      S.getASTContext().hasSameUnqualifiedType(
           OpDeleteType->getParamType(DeleteArgs.size()), FrameSize->getType()))
     DeleteArgs.push_back(FrameSize);
 
@@ -1579,7 +1579,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
   // So we are not forced to pass alignment to the deallocation function.
   if (S.getLangOpts().CoroAlignedAllocation &&
       OpDeleteType->getNumParams() > DeleteArgs.size() &&
-      S.getASTContext().hasSameType(
+      S.getASTContext().hasSameUnqualifiedType(
           OpDeleteType->getParamType(DeleteArgs.size()),
           FrameAlignment->getType()))
     DeleteArgs.push_back(FrameAlignment);
index 6eca1e6..762a144 100644 (file)
@@ -25,3 +25,19 @@ struct task {
 task f() {
   co_return 43;
 }
+
+// From https://github.com/llvm/llvm-project/issues/60545
+struct generator {
+    struct promise_type {
+        generator get_return_object();
+        std::suspend_always initial_suspend();
+        std::suspend_always final_suspend() noexcept;
+        void return_void();
+        [[noreturn]] void unhandled_exception();
+
+        static void* operator new(std::size_t size);
+        static void operator delete(void* ptr, const std::size_t size);
+    };
+};
+
+generator goo() { co_return; }