Skip to content

[Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument #94542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 21, 2024

Conversation

a-tarasyuk
Copy link
Member

Fixes #93512

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jun 5, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 5, 2024

@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)

Changes

Fixes #93512


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

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+2)
  • (modified) clang/lib/Sema/SemaStmt.cpp (+1-1)
  • (added) clang/test/SemaCXX/lambda-as-default-parameter.cpp (+6)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 39a9013c75a41..819fe1811ddaf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -840,6 +840,8 @@ Bug Fixes to C++ Support
 - Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
 - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307),
   (#GH88081), (#GH89496), (#GH90669) and (#GH91633).
+- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a
+  forward-declared class. (#GH93512).
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 57465d4a77ac2..56f69dd50f361 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) {
 
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
-  if (!VD->hasDependentAlignment() &&
+  if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() &&
       Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType))
     Info.S = NamedReturnInfo::MoveEligible;
 
diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp
new file mode 100644
index 0000000000000..1f07a7f5644b7
--- /dev/null
+++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+struct a; // expected-note {{forward declaration of 'a'}} \
+             expected-note {{forward declaration of 'a'}}
+void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \
+                                   expected-error {{variable has incomplete type 'a'}}

@a-tarasyuk a-tarasyuk changed the title fix(93512): skip alignment checks on incomplete types [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument Jun 15, 2024
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@a-tarasyuk
Copy link
Member Author

@AaronBallman Thank you for your feedback. Do you think this needs to be reviewed by someone else? I can't add reviewers myself :)

@AaronBallman
Copy link
Collaborator

@AaronBallman Thank you for your feedback. Do you think this needs to be reviewed by someone else? I can't add reviewers myself :)

Nope, it's ready to land; sorry for not asking earlier, do you need me to commit this on your behalf?

@a-tarasyuk
Copy link
Member Author

@AaronBallman Yes, I do. I don't have access to merge…

@AaronBallman AaronBallman merged commit 9b50a88 into llvm:main Jun 21, 2024
8 checks passed
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
…on failure while parsing lambda used as default argument (llvm#94542)

Fixes llvm#93512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash while parsing lambda used as a default argument for the value of a forward class
3 participants