[clang] c724ac9 - [clang] Fix null dereference on return in lambda attribute statement expr (#66643)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 18 19:02:08 PDT 2023
Author: Piotr Fusik
Date: 2023-09-19T04:02:04+02:00
New Revision: c724ac9330cb77d9557178fbe3893485264376d9
URL: https://github.com/llvm/llvm-project/commit/c724ac9330cb77d9557178fbe3893485264376d9
DIFF: https://github.com/llvm/llvm-project/commit/c724ac9330cb77d9557178fbe3893485264376d9.diff
LOG: [clang] Fix null dereference on return in lambda attribute statement expr (#66643)
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
Added:
clang/test/Parser/gh48527.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaStmt.cpp
clang/test/SemaCXX/lambda-expressions.cpp
Removed:
################################################################################
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 <https://github.com/llvm/llvm-project/issues/66324>`_)
+- Fix crash for a lambda attribute with a statement expression
+ that contains a `return`.
+ (`#48527 <https://github.com/llvm/llvm-project/issues/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<CapturingScopeInfo>(getCurFunction());
QualType FnRetType = CurCap->ReturnType;
LambdaScopeInfo *CurLambda = dyn_cast<LambdaScopeInfo>(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 000000000000000..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 at +2 {{expected ')'}}
+// expected-error at +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}}
+}
More information about the cfe-commits
mailing list