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

>From e1656df3890c0cd1e8e796573f31fac0a3bb75af 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 | 8 ++++++++
 3 files changed, 17 insertions(+)
 create mode 100644 clang/test/SemaCXX/deleted-function-return.cpp

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 28fea9a99b609..d8943d6af7a7d 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -334,6 +334,8 @@ latest release, please see the [Clang Web 
Site](https://clang.llvm.org) or the
   `[](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..9320b85cd1dc8
--- /dev/null
+++ b/clang/test/SemaCXX/deleted-function-return.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only %s
+
+auto f() = delete; // expected-note {{candidate function has been explicitly 
deleted}}
+
+auto g() {
+  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