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

2024-05-03 Thread via cfe-commits

cor3ntin wrote:

This was fixed by https://github.com/llvm/llvm-project/pull/82310

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-03 Thread via cfe-commits

https://github.com/cor3ntin closed 
https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-20 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> @jcsxky Do you have more test cases other than the one from #76674? I wonder 
> what'll happen if constraint checking is involved.

Do you mean `concept`? If yes, I will have a try.

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-20 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

@jcsxky Do you have more test cases other than the one from #76674? I wonder 
what'll happen if constraint checking is involved.

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-16 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>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 06c7d57d73ca70..7dcff2e3d3f2c1 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 371378485626c2..99aa1274c20de0 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 00..2ce931920afe4f
--- /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 7dcff2e3d3f2c1..ee724e9df47ddc 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] [Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context (PR #80802)

2024-02-13 Thread Erich Keane via cfe-commits

https://github.com/erichkeane approved this pull request.


https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-13 Thread Qizhi Hu via cfe-commits


@@ -1614,7 +1614,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (RD && RD->isLambda()) {

jcsxky wrote:

Fixed

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-13 Thread Qizhi Hu via cfe-commits


@@ -1614,7 +1614,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());

jcsxky wrote:

Indeed, code has been fixed.

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-13 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 5430d0709c2ae62bf1cf749b50ab312098ad3771 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 17 +++--
 clang/test/CodeGen/PR76674.cpp | 11 +++
 3 files changed, 24 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..d809d7eec4d550 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ 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 `).
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d2..c18360b7b0f308 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 00..2ce931920afe4f
--- /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()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-12 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 2f09be514adff0c5e19494b14fbe4cc9588fea9c Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 18 --
 clang/test/CodeGen/PR76674.cpp | 11 +++
 3 files changed, 25 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..d809d7eec4d550 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ 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 `).
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d2..f80664e0e29a47 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1614,7 +1614,18 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  CXXRecordDecl *RD = T->getAsCXXRecordDecl();
+  if (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 +2694,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 00..2ce931920afe4f
--- /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()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-12 Thread Erich Keane via cfe-commits


@@ -1614,7 +1614,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());

erichkeane wrote:

Is this step necessary?  `getAsCXXRecordDecl` should at least canonicalize.  

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-12 Thread Erich Keane via cfe-commits


@@ -1614,7 +1614,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (RD && RD->isLambda()) {

erichkeane wrote:

`if (auto *RD = T->getAsCXXRecordDecl(); RD && RD->isLambda())`

??

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-12 Thread Erich Keane via cfe-commits

https://github.com/erichkeane edited 
https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-12 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

A few suggestions, but I REALLY would like @cor3ntin to take a final pass, it 
mostly LGTM.

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-12 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

@cor3ntin @erichkeane Could you please take another look at this PR? I think 
current version would be a reasonable fix since it transforms type only when 
it's needed. Or you have any other opinions? Thank you for guidance!

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-10 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 0063efb61d8076d46289f76a490c28f2ca7f Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 19 +--
 clang/test/CodeGen/PR76674.cpp | 11 +++
 3 files changed, 26 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..d809d7eec4d550 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ 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 `).
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d2..7134b80ae455df 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1614,7 +1614,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (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 +2695,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 00..2ce931920afe4f
--- /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()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-10 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 59fb684ff051dc50eb6f8e4e1c294fd5a2dc55d0 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 19 +--
 clang/test/CodeGen/PR76674.cpp | 11 +++
 3 files changed, 26 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..d809d7eec4d550 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ 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 `).
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d2..7134b80ae455df 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1614,7 +1614,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (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 +2695,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 00..2ce931920afe4f
--- /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()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-10 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 78c54ee65b16d33a3c9b19c453ded69adfe62732 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 34 ++
 clang/test/CodeGen/PR76674.cpp | 11 +++
 3 files changed, 42 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..d809d7eec4d550 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ 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 `).
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d2..b0476429aedddc 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1614,7 +1614,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (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,10 +2695,22 @@ 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;
+  // bool DependentLambdaType = false;
+  // QualType DesugaredType = T.getDesugaredType(getASTContext());
+  // CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  // if (RD && RD->isLambda()) {
+  //   QualType LambdaCallType = RD->getLambdaCallOperator()->getType();
+  //   if (LambdaCallType->isInstantiationDependentType() ||
+  //   LambdaCallType->isVariablyModifiedType()) {
+  // DependentLambdaType = true;
+  //   }
+  // }
+
+  // // If T is not a dependent type or a variably-modified type, there
+  // // is nothing to do.
+  // if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
+  // !DependentLambdaType)
+  //   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 00..2ce931920afe4f
--- /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()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-10 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 95f7690ccc843a5878ac212f467693877c40b232 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [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 | 34 ++
 clang/test/CodeGen/PR76674.cpp | 11 +++
 3 files changed, 45 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..c666e37f631bd1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -219,12 +219,17 @@ Bug Fixes to C++ Support
   Fixes (`#68490 `_)
 - Fix a crash when trying to call a varargs function that also has an explicit 
object parameter.
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
+<<< HEAD
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
 - Clang now classifies aggregate initialization in C++17 and newer as constant
   or non-constant more accurately. Previously, only a subset of the initializer
   elements were considered, misclassifying some initializers as constant. Fixes
   some of (`#80510 `).
+===
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
+>>> 096517a5a04e ([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 6d59180bc446d2..b0476429aedddc 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1614,7 +1614,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (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,10 +2695,22 @@ 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;
+  // bool DependentLambdaType = false;
+  // QualType DesugaredType = T.getDesugaredType(getASTContext());
+  // CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  // if (RD && RD->isLambda()) {
+  //   QualType LambdaCallType = RD->getLambdaCallOperator()->getType();
+  //   if (LambdaCallType->isInstantiationDependentType() ||
+  //   LambdaCallType->isVariablyModifiedType()) {
+  // DependentLambdaType = true;
+  //   }
+  // }
+
+  // // If T is not a dependent type or a variably-modified type, there
+  // // is nothing to do.
+  // if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
+  // !DependentLambdaType)
+  //   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 00..2ce931920afe4f
--- /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()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-08 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 376d5b0f6986f7cdf7bddd29fdbd418ba632da7a Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 28 --
 clang/test/CodeGen/PR76674.cpp | 11 +
 3 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52a48c750fe55..31b7120d475c3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -210,6 +210,8 @@ Bug Fixes to C++ Support
   Fixes (`#68490 `_)
 - Fix a crash when trying to call a varargs function that also has an explicit 
object parameter.
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d..95793ae730148 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1614,7 +1614,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (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,9 +2695,21 @@ QualType Sema::SubstType(QualType T,
  "Cannot perform an instantiation without some context on the "
  "instantiation stack");
 
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (RD && RD->isLambda()) {
+QualType LambdaCallType = RD->getLambdaCallOperator()->getType();
+if (LambdaCallType->isInstantiationDependentType() ||
+LambdaCallType->isVariablyModifiedType()) {
+  DependentLambdaType = true;
+}
+  }
+
   // If T is not a dependent type or a variably-modified type, there
   // is nothing to do.
-  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
+  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
+  !DependentLambdaType)
 return T;
 
   TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
diff --git a/clang/test/CodeGen/PR76674.cpp b/clang/test/CodeGen/PR76674.cpp
new file mode 100644
index 0..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()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-08 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 1706840eccdabcd3d5cc8bd7a80c9db96d6230c3 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 28 --
 clang/test/CodeGen/PR76674.cpp | 11 +
 3 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4d57ea4fd55b8c..7ad575e4f57fa6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -204,6 +204,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d2..95793ae7301481 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1614,7 +1614,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (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,9 +2695,21 @@ QualType Sema::SubstType(QualType T,
  "Cannot perform an instantiation without some context on the "
  "instantiation stack");
 
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (RD && RD->isLambda()) {
+QualType LambdaCallType = RD->getLambdaCallOperator()->getType();
+if (LambdaCallType->isInstantiationDependentType() ||
+LambdaCallType->isVariablyModifiedType()) {
+  DependentLambdaType = true;
+}
+  }
+
   // If T is not a dependent type or a variably-modified type, there
   // is nothing to do.
-  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
+  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
+  !DependentLambdaType)
 return T;
 
   TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
diff --git a/clang/test/CodeGen/PR76674.cpp b/clang/test/CodeGen/PR76674.cpp
new file mode 100644
index 00..2ce931920afe4f
--- /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()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-08 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 2b55af4e11a637e268e498242041cb0fe482e375 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 29 --
 clang/test/CodeGen/PR76674.cpp | 11 
 3 files changed, 40 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4d57ea4fd55b8..7ad575e4f57fa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -204,6 +204,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d..b7dd80b3e2457 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -16,6 +16,7 @@
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/ASTMutationListener.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprConcepts.h"
@@ -1614,7 +1615,19 @@ bool TemplateInstantiator::AlreadyTransformed(QualType 
T) {
   if (T.isNull())
 return true;
 
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(SemaRef.getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (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,9 +2696,21 @@ QualType Sema::SubstType(QualType T,
  "Cannot perform an instantiation without some context on the "
  "instantiation stack");
 
+  bool DependentLambdaType = false;
+  QualType DesugaredType = T.getDesugaredType(getASTContext());
+  CXXRecordDecl *RD = DesugaredType->getAsCXXRecordDecl();
+  if (RD && RD->isLambda()) {
+QualType LambdaCallType = RD->getLambdaCallOperator()->getType();
+if (LambdaCallType->isInstantiationDependentType() ||
+LambdaCallType->isVariablyModifiedType()) {
+  DependentLambdaType = true;
+}
+  }
+
   // If T is not a dependent type or a variably-modified type, there
   // is nothing to do.
-  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
+  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
+  !DependentLambdaType)
 return T;
 
   TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
diff --git a/clang/test/CodeGen/PR76674.cpp b/clang/test/CodeGen/PR76674.cpp
new file mode 100644
index 0..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()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-07 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-07 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-06 Thread Qizhi Hu via cfe-commits


@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -verify -std=c++20 -emit-llvm -o - %s

jcsxky wrote:

removed `-verify`

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-06 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 9dbc077e263bc16ab3919b6691ee8c4585377caf Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  7 ---
 clang/test/CodeGen/PR76674.cpp | 11 +++
 3 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4d57ea4fd55b8..7ad575e4f57fa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -204,6 +204,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d..383163ea969a9 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))
 return false;
 
   getSema().MarkDeclarationsReferencedInType(Loc, T);
@@ -2685,7 +2685,8 @@ QualType Sema::SubstType(QualType T,
 
   // If T is not a dependent type or a variably-modified type, there
   // is nothing to do.
-  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
+  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
+  (getLangOpts().CPlusPlus20 && !T->isDecltypeType()))
 return T;
 
   TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
diff --git a/clang/test/CodeGen/PR76674.cpp b/clang/test/CodeGen/PR76674.cpp
new file mode 100644
index 0..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()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-06 Thread Qizhi Hu via cfe-commits


@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))

jcsxky wrote:

> Can you please add the relevant standards-quote here, particularly for the 
> C++20 vs pre-C++20 change here?

Sorry, I couldn't get what you mean of  relevant standards-quote and I am not 
very familiar with cpp standards. I add `SemaRef.getLangOpts().CPlusPlus20` 
just because command args contains `-std=c++20` and clang diagnose says 'lambda 
expression in an unevaluated operand' and don't retransform `decltype` all the 
time(issue only exists in code of cpp20 and later).

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-06 Thread Qizhi Hu via cfe-commits


@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))

jcsxky wrote:

@cor3ntin I use this test case locally:
```cpp
A::Func f{};
```
AST looks like:
```cpp
Breakpoint 42, clang::DecltypeType::DecltypeType (this=0x39d190, E=0x39cfd0, 
underlyingType=..., can=...) at 
/home/huqizhi/Downloads/llvm-project/clang/lib/AST/Type.cpp:3797
3797  E(E), UnderlyingType(underlyingType) {}
(gdb-ChatDBG) p E->dumpColor()
CXXBindTemporaryExpr 0x39cfd0 'class A::(lambda at 
/home/huqizhi/K.cpp:18:27)' (CXXTemporary 0x39cfd0)
`-LambdaExpr 0x39cfa0 'class A::(lambda at /home/huqizhi/K.cpp:18:27)'
  |-CXXRecordDecl 0x39ca60  implicit class definition
  | |-DefinitionData lambda pass_in_registers empty standard_layout 
trivially_copyable trivial literal has_constexpr_non_copy_move_ctor 
can_const_default_init
  | | |-DefaultConstructor exists trivial constexpr needs_implicit 
defaulted_is_constexpr
  | | |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
  | | |-MoveConstructor exists simple trivial needs_implicit
  | | |-CopyAssignment simple trivial has_const_param needs_implicit 
implicit_has_const_param
  | | |-MoveAssignment exists simple trivial needs_implicit
  | | `-Destructor simple irrelevant trivial constexpr
  | |-CXXMethodDecl 0x39cbc8  constexpr operator() 'auto (void) const -> auto' 
implicit_instantiation inline instantiated_from 0x37cc18
  | | `-CompoundStmt 0x39cd58
  | |   `-ReturnStmt 0x39cd48
  | | `-CXXUnresolvedConstructExpr 0x39cd08 'U' 'U' list
  | |   `-InitListExpr 0x39ccc8 'void'
  | |-CXXConversionDecl 0x39cdf0  implicit constexpr operator auto (*)() 'auto 
(*(void) const noexcept)(void) -> auto' inline
  | |-CXXMethodDecl 0x39ceb0  implicit __invoke 'auto (void) -> auto' static 
inline
  | `-CXXDestructorDecl 0x39cff8  implicit referenced constexpr ~(lambda at 
/home/huqizhi/K.cpp:18:27) 'void (void) noexcept' inline default trivial
  `-CompoundStmt 0x39cd58
`-ReturnStmt 0x39cd48
  `-CXXUnresolvedConstructExpr 0x39cd08 'U' 'U' list
`-InitListExpr 0x39ccc8 'void'
```
`CXXBindTemporaryExpr` and `LambdaExpr` both are not 
`InstantiationDependentType`
```cpp
(gdb-ChatDBG) p E->isInstantiationDependent()
$306 = false
(gdb-ChatDBG) p 
((CXXBindTemporaryExpr*)E)->getSubExpr()->isInstantiationDependent()
$308 = false
```
This is because type of the lambda is not `InstantiationDependentType`:
```cpp
(gdb-ChatDBG) p 
((LambdaExpr*)(((CXXBindTemporaryExpr*)E)->getSubExpr()))->getType().dump()
RecordType 0x39cba0 'class A::(lambda at /home/huqizhi/K.cpp:18:27)'
`-CXXRecord 0x39ca60 ''
$312 = void
```
I think retransforming all the` decltype` should be right because 
retransforming should not change the result. But, this may involve some 
efficiency problem.
Since `CXXUnresolvedConstructExpr` in the lambda expression is 
`InstantiationDependentType`, Maybe visiting the lambda expression and checking 
whether it has `InstantiationDependentType` child is a better approach (I 
think, but more complex).




https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-06 Thread via cfe-commits


@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))

cor3ntin wrote:

Note that this would at best retransform all the `decltype` which does sound 
wrong?

I'd rather try to understand why `isInstantiationDependentType` gives a bogus 
result, although that might be involved.


https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-06 Thread Erich Keane via cfe-commits


@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))

erichkeane wrote:

Can you please add the relevant standards-quote here, particularly for the 
C++20 vs pre-C++20 change here?

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -verify -std=c++20 -emit-llvm -o - %s

Fznamznon wrote:

I wonder if `-verify` flag is necessary? There is no diagnostics expected, and 
the test makes sure LLVM IR generation doesn't crash even without `-verify` 
flag.

https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-05 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 741793c9584753e6e888c9824961501b676b1143 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  7 ---
 clang/test/CodeGen/PR76674.cpp | 11 +++
 3 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4d57ea4fd55b8..7ad575e4f57fa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -204,6 +204,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d..383163ea969a9 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))
 return false;
 
   getSema().MarkDeclarationsReferencedInType(Loc, T);
@@ -2685,7 +2685,8 @@ QualType Sema::SubstType(QualType T,
 
   // If T is not a dependent type or a variably-modified type, there
   // is nothing to do.
-  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
+  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
+  (getLangOpts().CPlusPlus20 && !T->isDecltypeType()))
 return T;
 
   TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
diff --git a/clang/test/CodeGen/PR76674.cpp b/clang/test/CodeGen/PR76674.cpp
new file mode 100644
index 0..e47184b7fcb59
--- /dev/null
+++ b/clang/test/CodeGen/PR76674.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -verify -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()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-05 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 6dbd0937e8ded4dd8f71afb876bb3930c309 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  7 ---
 clang/test/CodeGen/PR76674.cpp | 11 +++
 3 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4d57ea4fd55b8c..7ad575e4f57fa6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -204,6 +204,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d2..383163ea969a95 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))
 return false;
 
   getSema().MarkDeclarationsReferencedInType(Loc, T);
@@ -2685,7 +2685,8 @@ QualType Sema::SubstType(QualType T,
 
   // If T is not a dependent type or a variably-modified type, there
   // is nothing to do.
-  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
+  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
+  (getLangOpts().CPlusPlus20 && !T->isDecltypeType()))
 return T;
 
   TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
diff --git a/clang/test/CodeGen/PR76674.cpp b/clang/test/CodeGen/PR76674.cpp
new file mode 100644
index 00..11b730dc44dbd6
--- /dev/null
+++ b/clang/test/CodeGen/PR76674.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c++20 -emit-llvm %s  -o /dev/null
+// expected-no-diagnostics
+
+template 
+struct A {
+template 
+using Func = decltype([] {return U{};});
+};
+
+A::Func f{};
+int i{f()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)


Changes

Try to fix [issue](https://github.com/llvm/llvm-project/issues/76674)
When transform a lambda expression which is declared in an unevaluated context, 
`isInstantiationDependentType()` and `isVariablyModifiedType()` both return 
false and lead to skip transforming the lambda expression. On the other hand, 
`AlreadyTransformed` also skip transform in this case. Add the condition to 
check whether it's in decltype makes it work.

---
Full diff: https://github.com/llvm/llvm-project/pull/80802.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+4-3) 
- (added) clang/test/SemaTemplate/PR76674.cpp (+11) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4d57ea4fd55b8..7ad575e4f57fa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -204,6 +204,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d..383163ea969a9 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))
 return false;
 
   getSema().MarkDeclarationsReferencedInType(Loc, T);
@@ -2685,7 +2685,8 @@ QualType Sema::SubstType(QualType T,
 
   // If T is not a dependent type or a variably-modified type, there
   // is nothing to do.
-  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
+  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
+  (getLangOpts().CPlusPlus20 && !T->isDecltypeType()))
 return T;
 
   TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
diff --git a/clang/test/SemaTemplate/PR76674.cpp 
b/clang/test/SemaTemplate/PR76674.cpp
new file mode 100644
index 0..50e9053e41e0f
--- /dev/null
+++ b/clang/test/SemaTemplate/PR76674.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -c -std=c++20 -verify=cxx20 -o /dev/null %s
+// expected-no-diagnostics
+
+template 
+struct A {
+template 
+using Func = decltype([] {return U{};});
+};
+
+A::Func f{};
+int i{f()};

``




https://github.com/llvm/llvm-project/pull/80802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-05 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky created 
https://github.com/llvm/llvm-project/pull/80802

Try to fix [issue](https://github.com/llvm/llvm-project/issues/76674)
When transform a lambda expression which is declared in an unevaluated context, 
`isInstantiationDependentType()` and `isVariablyModifiedType()` both return 
false and lead to skip transforming the lambda expression. On the other hand, 
`AlreadyTransformed` also skip transform in this case. Add the condition to 
check whether it's in decltype makes it work.

>From f8ce2878f95df00aa84afb17bd14c20e82d44cd4 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  7 ---
 clang/test/SemaTemplate/PR76674.cpp| 11 +++
 3 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaTemplate/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4d57ea4fd55b8..7ad575e4f57fa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -204,6 +204,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d..383163ea969a9 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))
 return false;
 
   getSema().MarkDeclarationsReferencedInType(Loc, T);
@@ -2685,7 +2685,8 @@ QualType Sema::SubstType(QualType T,
 
   // If T is not a dependent type or a variably-modified type, there
   // is nothing to do.
-  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
+  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
+  (getLangOpts().CPlusPlus20 && !T->isDecltypeType()))
 return T;
 
   TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
diff --git a/clang/test/SemaTemplate/PR76674.cpp 
b/clang/test/SemaTemplate/PR76674.cpp
new file mode 100644
index 0..50e9053e41e0f
--- /dev/null
+++ b/clang/test/SemaTemplate/PR76674.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -c -std=c++20 -verify=cxx20 -o /dev/null %s
+// expected-no-diagnostics
+
+template 
+struct A {
+template 
+using Func = decltype([] {return U{};});
+};
+
+A::Func f{};
+int i{f()};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits