-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[clang] Fix null dereference on return in lambda attribute statement expr #66643
Conversation
@llvm/pr-subscribers-clang ChangesFixes #48527Full diff: https://github.com/llvm/llvm-project/pull/66643.diff 2 Files Affected:
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@+2 {{expected ')'}}
+// expected-error@+1 {{expected body of lambda expression}}
+// expected-error {{expected '}'}}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change needs a release note, otherwise looks good.
Right, @cor3ntin ?
@Fznamznon I think so too, although I'd be inclined to move the test to The commit message also could do with a longer description. Otherwise LGTM |
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. int main() {
[]()__attribute__((b(({ return 0; })))){};
} g++ accepts the above while Clang crashes. I'll add this as a second test. |
I would still move the original test, things in sema usually at least parse (ie, this has unbalanced parens). I won't insist though |
@cor3ntin to |
|
clang/test/SemaCXX/gh48527-2.cpp
Outdated
int main() { | ||
auto a = []()__attribute__((b(({ return 0; })))){}; // expected-warning {{unknown attribute 'b' ignored}} | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
81281e5
to
b84e2a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Rebased resolving the conflict in release notes. |
LGTM |
…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 llvm#48527
…expr (llvm#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 llvm#48527
Fixes #48527