[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-28 Thread via cfe-commits

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


[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-28 Thread via cfe-commits

cor3ntin wrote:

> I wonder does this also fix this: #67058

Nope, this is unrelated, sadly.

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


[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-27 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

I wonder does this also fix this: 
https://github.com/llvm/llvm-project/issues/67058

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


[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-27 Thread Erich Keane via cfe-commits


@@ -718,3 +718,8 @@ void foo() {
 void GH48527() {
   auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
 }
+
+void GH67492() {
+  constexpr auto test = 42;
+  auto lambda = (test, []() noexcept(true) {});

erichkeane wrote:

I can't remember... you asked my advise on one the other day where a requires 
clause inside of a thing inside of a lambda (really long repro) was trying to 
capture and I suggested something similar to this one (checking the contexts 
were added correctly).

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


[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-27 Thread via cfe-commits


@@ -718,3 +718,8 @@ void foo() {
 void GH48527() {
   auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
 }
+
+void GH67492() {
+  constexpr auto test = 42;
+  auto lambda = (test, []() noexcept(true) {});

cor3ntin wrote:

Which one?

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


[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-27 Thread Erich Keane via cfe-commits

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


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


[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-27 Thread Erich Keane via cfe-commits

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


[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-27 Thread Erich Keane via cfe-commits


@@ -718,3 +718,8 @@ void foo() {
 void GH48527() {
   auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
 }
+
+void GH67492() {
+  constexpr auto test = 42;
+  auto lambda = (test, []() noexcept(true) {});

erichkeane wrote:

Ah, I see!  This is a different test than the one I'd seen before!  I thought 
you were fixing that concept-in-lambda thing from a day or two ago.

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


[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-27 Thread via cfe-commits


@@ -718,3 +718,8 @@ void foo() {
 void GH48527() {
   auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
 }
+
+void GH67492() {
+  constexpr auto test = 42;
+  auto lambda = (test, []() noexcept(true) {});

cor3ntin wrote:

Yes, that's exactly the bug. It attempt a capture because we are in the lambda 
(in term of declaration context/scope),
but we were in the evaluation context of the enclosing expression.

`ActOnFinishFullExpression` was called (on `true`), we were thinking that 
`test` was in that evaluation context, and we were attempting to mark it odr 
used... from within the declaration context of the lambda, it's beautiful

https://godbolt.org/z/Waosza81K

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


[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-27 Thread Erich Keane via cfe-commits


@@ -718,3 +718,8 @@ void foo() {
 void GH48527() {
   auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
 }
+
+void GH67492() {
+  constexpr auto test = 42;
+  auto lambda = (test, []() noexcept(true) {});

erichkeane wrote:

Does this really attempt a capture?  You have `noexcept(true)` here?

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


[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

The conditions of a noexcept and explicit specifier are full expressions. 
Before this patch, we would call ActOnFinishFullExpr on these in the context of 
the enclosing expression, which would cause the collect of odr-used variables 
(and subsequently capture attempts) in the wrong (enclosing) context.

This was observable when parsing the noexcept specifier condition of a lambda 
appearing in a wider full expression odr-using variables.

Fixes #67492

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/Parse/ParseDecl.cpp (+5-1) 
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+5-1) 
- (modified) clang/test/SemaCXX/lambda-expressions.cpp (+5) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a17efab57bcdfa3..d74cd46c3bfccc6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -363,6 +363,10 @@ Bug Fixes to C++ Support
   reference. Fixes:
   (`#64162 `_)
 
+- Clang no longer tries to capture non-odr-used variables that appear
+  in the enclosing expression of a lambda expression with a noexcept specifier.
+  (`#67492 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index f5b4107cc32c1f0..735d7a861c7bead 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4162,7 +4162,11 @@ void Parser::ParseDeclarationSpecifiers(
   ExprResult ExplicitExpr(static_cast(nullptr));
   BalancedDelimiterTracker Tracker(*this, tok::l_paren);
   Tracker.consumeOpen();
-  ExplicitExpr = ParseConstantExpression();
+
+  EnterExpressionEvaluationContext ConstantEvaluated(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+
+  ExplicitExpr = ParseConstantExpressionInExprEvalContext();
   ConsumedEnd = Tok.getLocation();
   if (ExplicitExpr.isUsable()) {
 CloseParenLoc = Tok.getLocation();
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index e5a278c598cfb63..6cae537ed21e215 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -3988,7 +3988,11 @@ ExceptionSpecificationType 
Parser::tryParseExceptionSpecification(
 // There is an argument.
 BalancedDelimiterTracker T(*this, tok::l_paren);
 T.consumeOpen();
-NoexceptExpr = ParseConstantExpression();
+
+EnterExpressionEvaluationContext ConstantEvaluated(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+NoexceptExpr = ParseConstantExpressionInExprEvalContext();
+
 T.consumeClose();
 if (!NoexceptExpr.isInvalid()) {
   NoexceptExpr =
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 0c9e8584e653473..9cf81a0a195a573 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -718,3 +718,8 @@ void foo() {
 void GH48527() {
   auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
 }
+
+void GH67492() {
+  constexpr auto test = 42;
+  auto lambda = (test, []() noexcept(true) {});
+}

``




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


[clang] [Clang] Handle sema of noexcept condition in their evaluation context. (PR #67538)

2023-09-27 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/67538

The conditions of a noexcept and explicit specifier are full expressions. 
Before this patch, we would call ActOnFinishFullExpr on these in the context of 
the enclosing expression, which would cause the collect of odr-used variables 
(and subsequently capture attempts) in the wrong (enclosing) context.

This was observable when parsing the noexcept specifier condition of a lambda 
appearing in a wider full expression odr-using variables.

Fixes #67492

>From 812579329cee47f8d6ddb04f3ddd5af2f56f79a3 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 27 Sep 2023 12:29:33 +0200
Subject: [PATCH] [Clang] Handle sema of noexcept condition in their evaluation
 context.

The conditions of a noexcept and explicit specifier are full expressions.
Before this patch, we would call ActOnFinishFullExpr on these in the context
of the enclosing expression, which would cause the collect of odr-used variables
(and subsequently capture attempts) in the wrong (enclosing) context.

This was observable when parsing the noexcept specifier condition of a
lambda appearing in a wider full expression odr-using variables.

Fixes #67492
---
 clang/docs/ReleaseNotes.rst   | 4 
 clang/lib/Parse/ParseDecl.cpp | 6 +-
 clang/lib/Parse/ParseDeclCXX.cpp  | 6 +-
 clang/test/SemaCXX/lambda-expressions.cpp | 5 +
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a17efab57bcdfa3..d74cd46c3bfccc6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -363,6 +363,10 @@ Bug Fixes to C++ Support
   reference. Fixes:
   (`#64162 `_)
 
+- Clang no longer tries to capture non-odr-used variables that appear
+  in the enclosing expression of a lambda expression with a noexcept specifier.
+  (`#67492 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index f5b4107cc32c1f0..735d7a861c7bead 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4162,7 +4162,11 @@ void Parser::ParseDeclarationSpecifiers(
   ExprResult ExplicitExpr(static_cast(nullptr));
   BalancedDelimiterTracker Tracker(*this, tok::l_paren);
   Tracker.consumeOpen();
-  ExplicitExpr = ParseConstantExpression();
+
+  EnterExpressionEvaluationContext ConstantEvaluated(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+
+  ExplicitExpr = ParseConstantExpressionInExprEvalContext();
   ConsumedEnd = Tok.getLocation();
   if (ExplicitExpr.isUsable()) {
 CloseParenLoc = Tok.getLocation();
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index e5a278c598cfb63..6cae537ed21e215 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -3988,7 +3988,11 @@ ExceptionSpecificationType 
Parser::tryParseExceptionSpecification(
 // There is an argument.
 BalancedDelimiterTracker T(*this, tok::l_paren);
 T.consumeOpen();
-NoexceptExpr = ParseConstantExpression();
+
+EnterExpressionEvaluationContext ConstantEvaluated(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+NoexceptExpr = ParseConstantExpressionInExprEvalContext();
+
 T.consumeClose();
 if (!NoexceptExpr.isInvalid()) {
   NoexceptExpr =
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 0c9e8584e653473..9cf81a0a195a573 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -718,3 +718,8 @@ void foo() {
 void GH48527() {
   auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
 }
+
+void GH67492() {
+  constexpr auto test = 42;
+  auto lambda = (test, []() noexcept(true) {});
+}

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