https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/210973

>From c02f3ede269d3a28cf9772d691aadd1aa89040fb Mon Sep 17 00:00:00 2001
From: Rajveer <[email protected]>
Date: Tue, 21 Jul 2026 18:07:30 +0530
Subject: [PATCH] [clang][SemaCXX] Fixed a crash when returning an
 initialization to a top-level deleted function

Resolves #208488

This crash is caused due to requesting declaration alignment for
undeduced types like `auto`.
---
 clang/docs/ReleaseNotes.md                     |  2 ++
 clang/lib/Sema/SemaStmt.cpp                    |  7 +++++++
 clang/test/SemaCXX/deleted-function-return.cpp | 13 +++++++++++++
 3 files changed, 22 insertions(+)
 create mode 100644 clang/test/SemaCXX/deleted-function-return.cpp

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 44ae8ca102100..04644abe3ec1f 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -339,6 +339,8 @@ in a future version of Clang.
   `[](Types... = args...) {}`). Clang now diagnoses the illegal default
   argument instead of asserting. (#GH210714)
 
+- Fixed a crash when returning an initialization to a top-level deleted 
function. (#GH208488)
+
 #### Bug Fixes to AST Handling
 
 - Fixed a non-deterministic ordering of unused local typedefs that made
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index cc325620883f0..83e0eb9caadca 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3545,6 +3545,13 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const 
VarDecl *VD) {
     return NamedReturnInfo();
   }
 
+  const Type *T = VDType.getTypePtr();
+  if (T->getTypeClass() == Type::Auto) {
+    const auto *A = cast<DeducedType>(T);
+    if (A->isUndeducedAutoType())
+      return NamedReturnInfo();
+  }
+
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
   if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() &&
diff --git a/clang/test/SemaCXX/deleted-function-return.cpp 
b/clang/test/SemaCXX/deleted-function-return.cpp
new file mode 100644
index 0000000000000..60966ef5be216
--- /dev/null
+++ b/clang/test/SemaCXX/deleted-function-return.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only %s
+
+auto f() = delete; // expected-note 2 {{candidate function has been explicitly 
deleted}}
+
+auto g1() {
+  auto x = f(); // expected-error {{call to deleted function 'f'}}
+  return x;
+}
+
+auto g2() {
+  decltype(auto) x = f(); // expected-error {{call to deleted function 'f'}}
+  return x;
+}

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

Reply via email to