[clang] [clang] Fix null dereference on return in lambda attribute statement expr (PR #66643)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 18 06:13:58 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
<details>
<summary>Changes</summary>
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<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/SemaCXX/gh48527.cpp b/clang/test/SemaCXX/gh48527.cpp
new file mode 100644
index 000000000000000..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 at +2 {{expected ')'}}
+// expected-error at +1 {{expected body of lambda expression}}
+// expected-error {{expected '}'}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/66643
More information about the cfe-commits
mailing list