Skip to content

Commit c724ac9

Browse files
authored
[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 #48527
1 parent 7db4a6f commit c724ac9

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

clang/docs/ReleaseNotes.rst

+4
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ Bug Fixes to C++ Support
301301
makes an invalid call to an immediate function.
302302
(`#66324 <https://github.com/llvm/llvm-project/issues/66324>`_)
303303

304+
- Fix crash for a lambda attribute with a statement expression
305+
that contains a `return`.
306+
(`#48527 <https://github.com/llvm/llvm-project/issues/48527>`_)
307+
304308
Bug Fixes to AST Handling
305309
^^^^^^^^^^^^^^^^^^^^^^^^^
306310
- Fixed an import failure of recursive friend class template.

clang/lib/Sema/SemaStmt.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3577,6 +3577,8 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc,
35773577
CapturingScopeInfo *CurCap = cast<CapturingScopeInfo>(getCurFunction());
35783578
QualType FnRetType = CurCap->ReturnType;
35793579
LambdaScopeInfo *CurLambda = dyn_cast<LambdaScopeInfo>(CurCap);
3580+
if (CurLambda && CurLambda->CallOperator->getType().isNull())
3581+
return StmtError();
35803582
bool HasDeducedReturnType =
35813583
CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
35823584

clang/test/Parser/gh48527.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
3+
int main() { // expected-note {{to match this '{'}}
4+
auto a = [](void)__attribute__((b(({ // expected-note {{to match this '('}}
5+
return 0;
6+
} // expected-error 3 {{expected ')'}} \
7+
// expected-error {{expected ';' at end of declaration}}
8+
// expected-error@+2 {{expected ')'}}
9+
// expected-error@+1 {{expected body of lambda expression}}
10+
// expected-error {{expected '}'}}

clang/test/SemaCXX/lambda-expressions.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -714,3 +714,7 @@ void foo() {
714714
// CHECK-NEXT: ConstantExpr
715715
// CHECK-NEXT: value: Int 2
716716
}
717+
718+
void GH48527() {
719+
auto a = []()__attribute__((b(({ return 0; })))){}; // expected-warning {{unknown attribute 'b' ignored}}
720+
}

0 commit comments

Comments
 (0)