llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Rajveer Singh Bharadwaj (Rajveer100)

<details>
<summary>Changes</summary>

Resolves #<!-- -->208488

This crash is caused due to requesting declaration alignment for undeduced 
types like `auto`.

---
Full diff: https://github.com/llvm/llvm-project/pull/210973.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.md (+1) 
- (modified) clang/lib/Sema/SemaStmt.cpp (+7) 
- (added) clang/test/SemaCXX/deleted-function-return.cpp (+8) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 3e6c10666ca16..6db1a1657946d 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -839,6 +839,7 @@ latest release, please see the [Clang Web 
Site](https://clang.llvm.org) or the
 - Fixed a missing vtable for `dynamic_cast<FinalClass *>(this)` in a function 
template. (#GH198511)
 - Fixed an assertion failure during init-list checking of an array whose 
element type is an incomplete class. (#GH140685)
 - Fixed a crash when using a pack indexing type (e.g. ``Ts...[0]``) imported 
from another module. (#GH204479)
+- Fixed a crash when returning an initialization to a top-level deleted 
function. (#GH208488)
 
 #### Bug Fixes to AST Handling
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 27fee88d20c60..721df7be39838 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3466,6 +3466,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;
+}

``````````

</details>


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

Reply via email to