Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[Clang][Sema] fix crash in codegen stage when an lambda expression de…
…clared in an unevaluated context
  • Loading branch information
huqizhi committed Feb 17, 2024
commit c19a66ed4eadd5f16b586b349fd578d873902be2
5 changes: 5 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,16 @@ Bug Fixes to C++ Support
or non-constant more accurately. Previously, only a subset of the initializer
elements were considered, misclassifying some initializers as constant. Fixes
some of (`#80510 <https://github.com/llvm/llvm-project/issues/80510>`).
<<<<<<< HEAD
- Clang now ignores top-level cv-qualifiers on function parameters in template partial orderings.
(`#75404 <https://github.com/llvm/llvm-project/issues/75404>`_)
- 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>`_)
>>>>>>> 5430d0709c2a ([Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context)

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()};