https://github.com/MoritzS updated 
https://github.com/llvm/llvm-project/pull/179141

>From 59c9eff6443b782a0904ff195700f5080cfd4676 Mon Sep 17 00:00:00 2001
From: Moritz Sichert <[email protected]>
Date: Sun, 1 Feb 2026 22:06:20 +0100
Subject: [PATCH] [Clang] Fix coroutine promise with inherited allocation
 functions

The compiler frontend crashed when the promise class overloads
operator new/delete without a regular function declaration. This happens
when the promise class derives from a base class and takes the
allocation functions from the base class with:
    using Base::operator new;
    using Base::operator delete;

This was initially introduced by 1cd59264aa2fb4b0ba70ff03c1298b1b5c21271e.
---
 clang/lib/Sema/SemaCoroutine.cpp              |  4 +-
 .../SemaCXX/coroutine-inherited-allocator.cpp | 39 +++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/coroutine-inherited-allocator.cpp

diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index c0aba832dba94..0bd990b784961 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -1098,7 +1098,9 @@ static bool DiagnoseTypeAwareAllocators(Sema &S, 
SourceLocation Loc,
   S.LookupQualifiedName(R, PromiseType->getAsCXXRecordDecl());
   bool HaveIssuedWarning = false;
   for (auto Decl : R) {
-    if (!Decl->getAsFunction()->isTypeAwareOperatorNewOrDelete())
+    if (!Decl->getUnderlyingDecl()
+             ->getAsFunction()
+             ->isTypeAwareOperatorNewOrDelete())
       continue;
     if (!HaveIssuedWarning) {
       S.Diag(Loc, DiagnosticID) << Name;
diff --git a/clang/test/SemaCXX/coroutine-inherited-allocator.cpp 
b/clang/test/SemaCXX/coroutine-inherited-allocator.cpp
new file mode 100644
index 0000000000000..2981c91dc5d1c
--- /dev/null
+++ b/clang/test/SemaCXX/coroutine-inherited-allocator.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -std=c++20 -fsyntax-only -verify
+
+// Verify that coroutines with promise types that inherit operator new/delete 
from a base class via
+// using declarations don't crash during compilation.
+// This is a regression test for a bug where DiagnoseTypeAwareAllocators 
didn't handle
+// UsingShadowDecl properly.
+
+#include "Inputs/std-coroutine.h"
+
+namespace std {
+  typedef __SIZE_TYPE__ size_t;
+}
+
+struct PromiseBase {
+  static void *operator new(std::size_t size);
+  static void operator delete(void *ptr, std::size_t size);
+};
+
+struct Task {
+  struct promise_type : PromiseBase {
+    using PromiseBase::operator new;
+    using PromiseBase::operator delete;
+
+    Task get_return_object() {
+      return Task{std::coroutine_handle<promise_type>::from_promise(*this)};
+    }
+
+    std::suspend_never initial_suspend() noexcept { return {}; }
+    std::suspend_always final_suspend() noexcept { return {}; }
+    void return_void() {}
+    void unhandled_exception() {}
+  };
+
+  std::coroutine_handle<promise_type> handle;
+};
+
+Task example_coroutine() {
+  co_return;
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to