Skip to content

Commit 0063efb

Browse files
author
huqizhi
committed
[Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context
1 parent c0ed1b2 commit 0063efb

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ Bug Fixes to C++ Support
225225
or non-constant more accurately. Previously, only a subset of the initializer
226226
elements were considered, misclassifying some initializers as constant. Fixes
227227
some of (`#80510 <https://github.com/llvm/llvm-project/issues/80510>`).
228+
- Fix a crash in codegen when lambdas declared in an unevaluated context.
229+
Fixes (`#76674 <https://github.com/llvm/llvm-project/issues/76674>`_)
228230

229231
Bug Fixes to AST Handling
230232
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType T) {
16141614
if (T.isNull())
16151615
return true;
16161616

1617-
if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
1617+
bool DependentLambdaType = false;
1618+
QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());
1619+
CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
1620+
if (RD && RD->isLambda()) {
1621+
QualType LambdaCallType = RD->getLambdaCallOperator()->getType();
1622+
if (LambdaCallType->isInstantiationDependentType() ||
1623+
LambdaCallType->isVariablyModifiedType()) {
1624+
DependentLambdaType = true;
1625+
}
1626+
}
1627+
1628+
if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
1629+
DependentLambdaType)
16181630
return false;
16191631

16201632
getSema().MarkDeclarationsReferencedInType(Loc, T);
@@ -2683,11 +2695,6 @@ QualType Sema::SubstType(QualType T,
26832695
"Cannot perform an instantiation without some context on the "
26842696
"instantiation stack");
26852697

2686-
// If T is not a dependent type or a variably-modified type, there
2687-
// is nothing to do.
2688-
if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
2689-
return T;
2690-
26912698
TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
26922699
return Instantiator.TransformType(T);
26932700
}

clang/test/CodeGen/PR76674.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -std=c++20 -emit-llvm -o - %s
2+
// expected-no-diagnostics
3+
4+
template <class>
5+
struct A {
6+
template <class U>
7+
using Func = decltype([] {return U{};});
8+
};
9+
10+
A<int>::Func<int> f{};
11+
int i{f()};

0 commit comments

Comments
 (0)