From c19a66ed4eadd5f16b586b349fd578d873902be2 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Tue, 6 Feb 2024 14:06:40 +0800 Subject: [PATCH 1/2] [Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context --- clang/docs/ReleaseNotes.rst | 5 +++++ clang/lib/Sema/SemaTemplateInstantiate.cpp | 17 +++++++++++------ clang/test/CodeGen/PR76674.cpp | 11 +++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGen/PR76674.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 06c7d57d73ca7..7dcff2e3d3f2c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -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 `). +<<<<<<< HEAD - Clang now ignores top-level cv-qualifiers on function parameters in template partial orderings. (`#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 `_) +>>>>>>> 5430d0709c2a ([Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 371378485626c..99aa1274c20de 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -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); @@ -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); } diff --git a/clang/test/CodeGen/PR76674.cpp b/clang/test/CodeGen/PR76674.cpp new file mode 100644 index 0000000000000..2ce931920afe4 --- /dev/null +++ b/clang/test/CodeGen/PR76674.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -std=c++20 -emit-llvm -o - %s +// expected-no-diagnostics + +template +struct A { + template + using Func = decltype([] {return U{};}); +}; + +A::Func f{}; +int i{f()}; From 842f8481102fb2abfcaaa790ec04034d55744311 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sat, 17 Feb 2024 09:36:44 +0800 Subject: [PATCH 2/2] resolve conflict of ReleaseNote --- clang/docs/ReleaseNotes.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7dcff2e3d3f2c..ee724e9df47dd 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -260,16 +260,13 @@ 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 `). -<<<<<<< HEAD - Clang now ignores top-level cv-qualifiers on function parameters in template partial orderings. (`#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 `_) ->>>>>>> 5430d0709c2a ([Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^