[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Piotr Fusik via cfe-commits

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Piotr Fusik via cfe-commits

https://github.com/pfusik updated 
https://github.com/llvm/llvm-project/pull/66643

>From 4545c9c691a7affcab6cfe4e1b9b2a7715ab3f8b Mon Sep 17 00:00:00 2001
From: Piotr Fusik 
Date: Mon, 18 Sep 2023 19:56:10 +0200
Subject: [PATCH] [clang] Fix null dereference on return in lambda attribute
 statement expr

clang was crashing on a lambda attribute with a statement expression
that contained a `return`.
It attempted to access the lambda type which was unknown at that point.

Fixes https://github.com/llvm/llvm-project/issues/48527
---
 clang/docs/ReleaseNotes.rst   |  4 
 clang/lib/Sema/SemaStmt.cpp   |  2 ++
 clang/test/Parser/gh48527.cpp | 10 ++
 clang/test/SemaCXX/lambda-expressions.cpp |  4 
 4 files changed, 20 insertions(+)
 create mode 100644 clang/test/Parser/gh48527.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9b1578762e301f6..172818114c3b92b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -301,6 +301,10 @@ Bug Fixes to C++ Support
   makes an invalid call to an immediate function.
   (`#66324 `_)
 
+- Fix crash for a lambda attribute with a statement expression
+  that contains a `return`.
+  (`#48527 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 7cc509542d5381d..10adfbc406dfbb5 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3577,6 +3577,8 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation 
ReturnLoc,
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+  if (CurLambda && CurLambda->CallOperator->getType().isNull())
+return StmtError();
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 
diff --git a/clang/test/Parser/gh48527.cpp b/clang/test/Parser/gh48527.cpp
new file mode 100644
index 000..420c35be37f5191
--- /dev/null
+++ b/clang/test/Parser/gh48527.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int main() { // expected-note {{to match this '{'}}
+auto a = [](void)__attribute__((b(({ // expected-note {{to match this '('}}
+return 0;
+} // expected-error 3 {{expected ')'}} \
+  // expected-error {{expected ';' at end of declaration}}
+// expected-error@+2 {{expected ')'}}
+// expected-error@+1 {{expected body of lambda expression}}
+// expected-error {{expected '}'}}
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 23745dc14154747..0c9e8584e653473 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -714,3 +714,7 @@ void foo() {
   // CHECK-NEXT: ConstantExpr
   // CHECK-NEXT: value: Int 2
 }
+
+void GH48527() {
+  auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
+}

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

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

shafik wrote:

LGTM

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Piotr Fusik via cfe-commits

pfusik wrote:

Rebased resolving the conflict in release notes.

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Piotr Fusik via cfe-commits

https://github.com/pfusik updated 
https://github.com/llvm/llvm-project/pull/66643

>From c313074ca50cae80698154991273717e5a8cc13a Mon Sep 17 00:00:00 2001
From: Piotr Fusik 
Date: Mon, 18 Sep 2023 19:56:10 +0200
Subject: [PATCH] [clang] Fix null dereference on return in lambda attribute
 statement expr

clang was crashing on a lambda attribute with a statement expression
that contained a `return`.
It attempted to access the lambda type which was unknown at that point.

Fixes https://github.com/llvm/llvm-project/issues/48527
---
 clang/docs/ReleaseNotes.rst   |  4 
 clang/lib/Sema/SemaStmt.cpp   |  2 ++
 clang/test/Parser/gh48527.cpp | 10 ++
 clang/test/SemaCXX/lambda-expressions.cpp |  4 
 4 files changed, 20 insertions(+)
 create mode 100644 clang/test/Parser/gh48527.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e964f6eb435bb0..ef4e9c792bec05c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -297,6 +297,10 @@ Bug Fixes to C++ Support
   definition the specialization was instantiated from.
   (`#26057 `_`)
 
+- Fix crash for a lambda attribute with a statement expression
+  that contains a `return`.
+  (`#48527 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 7cc509542d5381d..10adfbc406dfbb5 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3577,6 +3577,8 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation 
ReturnLoc,
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+  if (CurLambda && CurLambda->CallOperator->getType().isNull())
+return StmtError();
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 
diff --git a/clang/test/Parser/gh48527.cpp b/clang/test/Parser/gh48527.cpp
new file mode 100644
index 000..420c35be37f5191
--- /dev/null
+++ b/clang/test/Parser/gh48527.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int main() { // expected-note {{to match this '{'}}
+auto a = [](void)__attribute__((b(({ // expected-note {{to match this '('}}
+return 0;
+} // expected-error 3 {{expected ')'}} \
+  // expected-error {{expected ';' at end of declaration}}
+// expected-error@+2 {{expected ')'}}
+// expected-error@+1 {{expected body of lambda expression}}
+// expected-error {{expected '}'}}
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 23745dc14154747..0c9e8584e653473 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -714,3 +714,7 @@ void foo() {
   // CHECK-NEXT: ConstantExpr
   // CHECK-NEXT: value: Int 2
 }
+
+void GH48527() {
+  auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
+}

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread via cfe-commits

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

LGTM, thanks!

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Piotr Fusik via cfe-commits

https://github.com/pfusik updated 
https://github.com/llvm/llvm-project/pull/66643

>From b84e2a821a3121fa3597e710da341de66746bb46 Mon Sep 17 00:00:00 2001
From: Piotr Fusik 
Date: Mon, 18 Sep 2023 19:56:10 +0200
Subject: [PATCH] [clang] Fix null dereference on return in lambda attribute
 statement expr

clang was crashing on a lambda attribute with a statement expression
that contained a `return`.
It attempted to access the lambda type which was unknown at that point.

Fixes https://github.com/llvm/llvm-project/issues/48527
---
 clang/docs/ReleaseNotes.rst   |  4 
 clang/lib/Sema/SemaStmt.cpp   |  2 ++
 clang/test/Parser/gh48527.cpp | 10 ++
 clang/test/SemaCXX/lambda-expressions.cpp |  4 
 4 files changed, 20 insertions(+)
 create mode 100644 clang/test/Parser/gh48527.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 500f9c9a0cda741..c6f258991c85a79 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -291,6 +291,10 @@ Bug Fixes to C++ Support
   pointers on win32.
   (`#62594 `_)
 
+- Fix crash for a lambda attribute with a statement expression
+  that contains a `return`.
+  (`#48527 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 7cc509542d5381d..10adfbc406dfbb5 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3577,6 +3577,8 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation 
ReturnLoc,
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+  if (CurLambda && CurLambda->CallOperator->getType().isNull())
+return StmtError();
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 
diff --git a/clang/test/Parser/gh48527.cpp b/clang/test/Parser/gh48527.cpp
new file mode 100644
index 000..420c35be37f5191
--- /dev/null
+++ b/clang/test/Parser/gh48527.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int main() { // expected-note {{to match this '{'}}
+auto a = [](void)__attribute__((b(({ // expected-note {{to match this '('}}
+return 0;
+} // expected-error 3 {{expected ')'}} \
+  // expected-error {{expected ';' at end of declaration}}
+// expected-error@+2 {{expected ')'}}
+// expected-error@+1 {{expected body of lambda expression}}
+// expected-error {{expected '}'}}
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 23745dc14154747..0c9e8584e653473 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -714,3 +714,7 @@ void foo() {
   // CHECK-NEXT: ConstantExpr
   // CHECK-NEXT: value: Int 2
 }
+
+void GH48527() {
+  auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
+}

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Piotr Fusik via cfe-commits

https://github.com/pfusik updated 
https://github.com/llvm/llvm-project/pull/66643

>From 81281e52ac76d0c10ddadaf7d75a544eccce39a5 Mon Sep 17 00:00:00 2001
From: Piotr Fusik 
Date: Mon, 18 Sep 2023 19:54:16 +0200
Subject: [PATCH] [clang] Fix null dereference on return in lambda attribute
 statement expr

clang was crashing on a lambda attribute with a statement expression
that contained a `return`.
It attempted to access the lambda type which was unknown at that point.

Fixes https://github.com/llvm/llvm-project/issues/48527
---
 clang/docs/ReleaseNotes.rst   |  4 
 clang/lib/Sema/SemaStmt.cpp   |  2 ++
 clang/test/Parser/gh48527.cpp | 10 ++
 clang/test/SemaCXX/lambda-expressions.cpp |  4 
 4 files changed, 20 insertions(+)
 create mode 100644 clang/test/Parser/gh48527.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 500f9c9a0cda741..c6f258991c85a79 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -291,6 +291,10 @@ Bug Fixes to C++ Support
   pointers on win32.
   (`#62594 `_)
 
+- Fix crash for a lambda attribute with a statement expression
+  that contains a `return`.
+  (`#48527 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 7cc509542d5381d..10adfbc406dfbb5 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3577,6 +3577,8 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation 
ReturnLoc,
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+  if (CurLambda && CurLambda->CallOperator->getType().isNull())
+return StmtError();
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 
diff --git a/clang/test/Parser/gh48527.cpp b/clang/test/Parser/gh48527.cpp
new file mode 100644
index 000..420c35be37f5191
--- /dev/null
+++ b/clang/test/Parser/gh48527.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int main() { // expected-note {{to match this '{'}}
+auto a = [](void)__attribute__((b(({ // expected-note {{to match this '('}}
+return 0;
+} // expected-error 3 {{expected ')'}} \
+  // expected-error {{expected ';' at end of declaration}}
+// expected-error@+2 {{expected ')'}}
+// expected-error@+1 {{expected body of lambda expression}}
+// expected-error {{expected '}'}}
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 23745dc14154747..269a1e1040ee96f 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -714,3 +714,7 @@ void foo() {
   // CHECK-NEXT: ConstantExpr
   // CHECK-NEXT: value: Int 2
 }
+
+void GH48527() {
+auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
+}

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread via cfe-commits


@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int main() {
+auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
+return 0;
+}

cor3ntin wrote:

This can move to `clang/test/SemaCXX/lambda-expressions.cpp`
(the name of the function can have the number of the GH issue)

We try to limit the number of test files

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Piotr Fusik via cfe-commits

https://github.com/pfusik updated 
https://github.com/llvm/llvm-project/pull/66643

>From 33c94d5bedf8889ab7b7fe2442fa0a3196223c91 Mon Sep 17 00:00:00 2001
From: Piotr Fusik 
Date: Mon, 18 Sep 2023 18:41:54 +0200
Subject: [PATCH] [clang] Fix null dereference on return in lambda attribute
 statement expr

clang was crashing on a lambda attribute with a statement expression
that contained a `return`.
It attempted to access the lambda type which was unknown at that point.

Fixes https://github.com/llvm/llvm-project/issues/48527
---
 clang/docs/ReleaseNotes.rst  |  4 
 clang/lib/Sema/SemaStmt.cpp  |  2 ++
 clang/test/Parser/gh48527.cpp| 10 ++
 clang/test/SemaCXX/gh48527-2.cpp |  6 ++
 4 files changed, 22 insertions(+)
 create mode 100644 clang/test/Parser/gh48527.cpp
 create mode 100644 clang/test/SemaCXX/gh48527-2.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 500f9c9a0cda741..c6f258991c85a79 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -291,6 +291,10 @@ Bug Fixes to C++ Support
   pointers on win32.
   (`#62594 `_)
 
+- Fix crash for a lambda attribute with a statement expression
+  that contains a `return`.
+  (`#48527 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 7cc509542d5381d..10adfbc406dfbb5 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3577,6 +3577,8 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation 
ReturnLoc,
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+  if (CurLambda && CurLambda->CallOperator->getType().isNull())
+return StmtError();
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 
diff --git a/clang/test/Parser/gh48527.cpp b/clang/test/Parser/gh48527.cpp
new file mode 100644
index 000..420c35be37f5191
--- /dev/null
+++ b/clang/test/Parser/gh48527.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int main() { // expected-note {{to match this '{'}}
+auto a = [](void)__attribute__((b(({ // expected-note {{to match this '('}}
+return 0;
+} // expected-error 3 {{expected ')'}} \
+  // expected-error {{expected ';' at end of declaration}}
+// expected-error@+2 {{expected ')'}}
+// expected-error@+1 {{expected body of lambda expression}}
+// expected-error {{expected '}'}}
diff --git a/clang/test/SemaCXX/gh48527-2.cpp b/clang/test/SemaCXX/gh48527-2.cpp
new file mode 100644
index 000..c5d45f29252ca6b
--- /dev/null
+++ b/clang/test/SemaCXX/gh48527-2.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int main() {
+auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
+return 0;
+}

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread via cfe-commits

cor3ntin wrote:

`test/Parser`. `CXX` is for tests that map very directly to a paragraph in the 
standard

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Piotr Fusik via cfe-commits

pfusik wrote:

@cor3ntin to `test/CXX/what` or `test/Parser` ?

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread via cfe-commits

cor3ntin wrote:

I would still move the original test, things in sema usually at least parse 
(ie, this has unbalanced parens). I won't insist though

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Piotr Fusik via cfe-commits

https://github.com/pfusik updated 
https://github.com/llvm/llvm-project/pull/66643

>From 88028509d7e5b5eaf38075c18abba498cb00087a Mon Sep 17 00:00:00 2001
From: Piotr Fusik 
Date: Mon, 18 Sep 2023 18:07:44 +0200
Subject: [PATCH] [clang] Fix null dereference on return in lambda attribute
 statement expr

clang was crashing on a lambda attribute with a statement expression
that contained a `return`.
It attempted to access the lambda type which was unknown at that point.

Fixes https://github.com/llvm/llvm-project/issues/48527
---
 clang/docs/ReleaseNotes.rst  |  4 
 clang/lib/Sema/SemaStmt.cpp  |  2 ++
 clang/test/SemaCXX/gh48527-2.cpp |  6 ++
 clang/test/SemaCXX/gh48527.cpp   | 10 ++
 4 files changed, 22 insertions(+)
 create mode 100644 clang/test/SemaCXX/gh48527-2.cpp
 create mode 100644 clang/test/SemaCXX/gh48527.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 500f9c9a0cda741..c6f258991c85a79 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -291,6 +291,10 @@ Bug Fixes to C++ Support
   pointers on win32.
   (`#62594 `_)
 
+- Fix crash for a lambda attribute with a statement expression
+  that contains a `return`.
+  (`#48527 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 7cc509542d5381d..10adfbc406dfbb5 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3577,6 +3577,8 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation 
ReturnLoc,
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+  if (CurLambda && CurLambda->CallOperator->getType().isNull())
+return StmtError();
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 
diff --git a/clang/test/SemaCXX/gh48527-2.cpp b/clang/test/SemaCXX/gh48527-2.cpp
new file mode 100644
index 000..c5d45f29252ca6b
--- /dev/null
+++ b/clang/test/SemaCXX/gh48527-2.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int main() {
+auto a = []()__attribute__((b(({ return 0; }{}; // expected-warning 
{{unknown attribute 'b' ignored}}
+return 0;
+}
diff --git a/clang/test/SemaCXX/gh48527.cpp b/clang/test/SemaCXX/gh48527.cpp
new file mode 100644
index 000..420c35be37f5191
--- /dev/null
+++ b/clang/test/SemaCXX/gh48527.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int main() { // expected-note {{to match this '{'}}
+auto a = [](void)__attribute__((b(({ // expected-note {{to match this '('}}
+return 0;
+} // expected-error 3 {{expected ')'}} \
+  // expected-error {{expected ';' at end of declaration}}
+// expected-error@+2 {{expected ')'}}
+// expected-error@+1 {{expected body of lambda expression}}
+// expected-error {{expected '}'}}

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Piotr Fusik via cfe-commits

pfusik wrote:

> I'd be inclined to move the test to clang/test/Parser/ because even though 
> the fix is in Sema, it's testing a wrong parse.

It's an ICE in Sema. The test is identical to the bug report, but it doesn't 
mean the issue is limited to syntax errors.

```cpp
int main() {
[]()__attribute__((b(({ return 0; }{};
}
```

g++ accepts the above while Clang crashes. I'll add this as a second test.

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread via cfe-commits

cor3ntin wrote:

@Fznamznon I think so too, although I'd be inclined to move the test to 
`clang/test/Parser/` because even though the fix is in Sema, it's testing a 
wrong parse.

The commit message also could do with a longer description.

Otherwise LGTM

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

The change needs a release note, otherwise looks good.
Right, @cor3ntin  ?

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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

Fixes https://github.com/llvm/llvm-project/issues/48527
---
Full diff: https://github.com/llvm/llvm-project/pull/66643.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaStmt.cpp (+2) 
- (added) clang/test/SemaCXX/gh48527.cpp (+10) 


``diff
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 7cc509542d5381d..10adfbc406dfbb5 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3577,6 +3577,8 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation 
ReturnLoc,
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+  if (CurLambda && CurLambda->CallOperator->getType().isNull())
+return StmtError();
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 
diff --git a/clang/test/SemaCXX/gh48527.cpp b/clang/test/SemaCXX/gh48527.cpp
new file mode 100644
index 000..420c35be37f5191
--- /dev/null
+++ b/clang/test/SemaCXX/gh48527.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int main() { // expected-note {{to match this '{'}}
+auto a = [](void)__attribute__((b(({ // expected-note {{to match this '('}}
+return 0;
+} // expected-error 3 {{expected ')'}} \
+  // expected-error {{expected ';' at end of declaration}}
+// expected-error@+2 {{expected ')'}}
+// expected-error@+1 {{expected body of lambda expression}}
+// expected-error {{expected '}'}}

``




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


[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)

2023-09-18 Thread Piotr Fusik via cfe-commits

https://github.com/pfusik created 
https://github.com/llvm/llvm-project/pull/66643

Fixes https://github.com/llvm/llvm-project/issues/48527

>From ea731b4d3d553f42cbaaec2079adeec3927b4150 Mon Sep 17 00:00:00 2001
From: Piotr Fusik 
Date: Mon, 18 Sep 2023 15:10:58 +0200
Subject: [PATCH] [clang] Fix null dereference on return in lambda attribute
 statement expr

Fixes https://github.com/llvm/llvm-project/issues/48527
---
 clang/lib/Sema/SemaStmt.cpp|  2 ++
 clang/test/SemaCXX/gh48527.cpp | 10 ++
 2 files changed, 12 insertions(+)
 create mode 100644 clang/test/SemaCXX/gh48527.cpp

diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 7cc509542d5381d..10adfbc406dfbb5 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3577,6 +3577,8 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation 
ReturnLoc,
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+  if (CurLambda && CurLambda->CallOperator->getType().isNull())
+return StmtError();
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 
diff --git a/clang/test/SemaCXX/gh48527.cpp b/clang/test/SemaCXX/gh48527.cpp
new file mode 100644
index 000..420c35be37f5191
--- /dev/null
+++ b/clang/test/SemaCXX/gh48527.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int main() { // expected-note {{to match this '{'}}
+auto a = [](void)__attribute__((b(({ // expected-note {{to match this '('}}
+return 0;
+} // expected-error 3 {{expected ')'}} \
+  // expected-error {{expected ';' at end of declaration}}
+// expected-error@+2 {{expected ')'}}
+// expected-error@+1 {{expected body of lambda expression}}
+// expected-error {{expected '}'}}

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