[clang] [Clang] Avoid assertion on unset coroutine statement location in diagnostic note (PR #248890)

Bhavya Gautam via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 4 05:59:56 PST 2026


https://github.com/gautam899 updated https://github.com/llvm/llvm-project/pull/248890

>From 1d8d73265e93f36bf902f395952546f1c4fb9974 Mon Sep 17 00:00:00 2001
From: Bhavya Gautam <gautambhavya899 at gmail.com>
Date: Fri, 4 Dec 2026 17:35:11 +0530
Subject: [PATCH] [Clang] Avoid assertion on unset coroutine statement location
 in diagnostic note

---
 clang/lib/Sema/SemaCoroutine.cpp        |  7 +++++--
 clang/test/SemaCXX/coroutine-246535.cpp | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/coroutine-246535.cpp

diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index d68a9ec2d8f35c..5c19cd7afbae12 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -1873,8 +1873,11 @@ static void noteMemberDeclaredHere(Sema &S, Expr *E, FunctionScopeInfo &Fn) {
     S.Diag(MethodDecl->getLocation(), diag::note_member_declared_here)
         << MethodDecl;
   }
-  S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
-      << Fn.getFirstCoroutineStmtKeyword();
+
+  if (Fn.FirstCoroutineStmtLoc.isValid()) {
+    S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
+        << Fn.getFirstCoroutineStmtKeyword();
+  }
 }
 
 bool CoroutineStmtBuilder::makeGroDeclAndReturnStmt() {
diff --git a/clang/test/SemaCXX/coroutine-246535.cpp b/clang/test/SemaCXX/coroutine-246535.cpp
new file mode 100644
index 00000000000000..c8a6afc6bd0187
--- /dev/null
+++ b/clang/test/SemaCXX/coroutine-246535.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+#include "Inputs/std-coroutine.h"
+
+struct S { // expected-note {{candidate constructor (the implicit copy constructor) not viable}} \
+           // expected-note {{candidate constructor (the implicit move constructor) not viable}}
+  struct promise_type {
+    void get_return_object(); // expected-note {{member 'get_return_object' declared here}}
+    std::suspend_never initial_suspend();
+    std::suspend_never final_suspend() noexcept;
+    void unhandled_exception();
+  };
+};
+
+template <typename... T>
+S foo(T... args) { // expected-error {{no viable conversion from returned value of type 'void' to function return type 'S'}}
+  co_yield args;   // expected-error {{expression contains unexpanded parameter pack 'args'}}
+}
+
+void f() { foo(); } // expected-note {{in instantiation of function template specialization 'foo<>' requested here}}



More information about the cfe-commits mailing list