Skip to content

Commit c19a66e

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

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,16 @@ Bug Fixes to C++ Support
260260
or non-constant more accurately. Previously, only a subset of the initializer
261261
elements were considered, misclassifying some initializers as constant. Fixes
262262
some of (`#80510 <https://github.com/llvm/llvm-project/issues/80510>`).
263+
<<<<<<< HEAD
263264
- Clang now ignores top-level cv-qualifiers on function parameters in template partial orderings.
264265
(`#75404 <https://github.com/llvm/llvm-project/issues/75404>`_)
265266
- No longer reject valid use of the ``_Alignas`` specifier when declaring a
266267
local variable, which is supported as a C11 extension in C++. Previously, it
267268
was only accepted at namespace scope but not at local function scope.
269+
=======
270+
- Fix a crash in codegen when lambdas declared in an unevaluated context.
271+
Fixes (`#76674 <https://github.com/llvm/llvm-project/issues/76674>`_)
272+
>>>>>>> 5430d0709c2a ([Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context)
268273

269274
Bug Fixes to AST Handling
270275
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplateInstantiate.cpp

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

1617-
if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
1617+
bool DependentLambdaType = false;
1618+
if (CXXRecordDecl *RD = T->getAsCXXRecordDecl(); RD && RD->isLambda()) {
1619+
QualType LambdaCallType = RD->getLambdaCallOperator()->getType();
1620+
if (LambdaCallType->isInstantiationDependentType() ||
1621+
LambdaCallType->isVariablyModifiedType()) {
1622+
DependentLambdaType = true;
1623+
}
1624+
}
1625+
1626+
if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
1627+
DependentLambdaType)
16181628
return false;
16191629

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

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-
26912696
TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
26922697
return Instantiator.TransformType(T);
26932698
}

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)