Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Sema/SemaStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions clang/test/Parser/gh48527.cpp
Original file line number Diff line number Diff line change
@@ -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 '}'}}
4 changes: 4 additions & 0 deletions clang/test/SemaCXX/lambda-expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}