Skip to content

[Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context #80802

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ Bug Fixes to C++ Support
- No longer reject valid use of the ``_Alignas`` specifier when declaring a
local variable, which is supported as a C11 extension in C++. Previously, it
was only accepted at namespace scope but not at local function scope.
- Fix a crash in codegen when lambdas declared in an unevaluated context.
Fixes (`#76674 <https://github.com/llvm/llvm-project/issues/76674>`_)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
17 changes: 11 additions & 6 deletions clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,17 @@ bool TemplateInstantiator::AlreadyTransformed(QualType T) {
if (T.isNull())
return true;

if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
bool DependentLambdaType = false;
if (CXXRecordDecl *RD = T->getAsCXXRecordDecl(); RD && RD->isLambda()) {
QualType LambdaCallType = RD->getLambdaCallOperator()->getType();
if (LambdaCallType->isInstantiationDependentType() ||
LambdaCallType->isVariablyModifiedType()) {
DependentLambdaType = true;
}
}

if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
DependentLambdaType)
return false;

getSema().MarkDeclarationsReferencedInType(Loc, T);
Expand Down Expand Up @@ -2683,11 +2693,6 @@ QualType Sema::SubstType(QualType T,
"Cannot perform an instantiation without some context on the "
"instantiation stack");

// If T is not a dependent type or a variably-modified type, there
// is nothing to do.
if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
return T;

TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
return Instantiator.TransformType(T);
}
Expand Down
11 changes: 11 additions & 0 deletions clang/test/CodeGen/PR76674.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %clang_cc1 -std=c++20 -emit-llvm -o - %s
// expected-no-diagnostics

template <class>
struct A {
template <class U>
using Func = decltype([] {return U{};});
};

A<int>::Func<int> f{};
int i{f()};