Skip to content

[webkit.UncountedLambdaCapturesChecker] Fix a crash in declProtectsThis #127309

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 2 commits into from
Feb 15, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -267,6 +267,8 @@ class UncountedLambdaCapturesChecker
auto OpCode = OpCE->getOperator();
if (OpCode == OO_Star || OpCode == OO_Amp) {
auto *Callee = OpCE->getDirectCallee();
if (!Callee)
return false;
auto clsName = safeGetName(Callee->getParent());
if (!isRefType(clsName) || !OpCE->getNumArgs())
return false;
@@ -276,9 +278,10 @@ class UncountedLambdaCapturesChecker
}
if (auto *UO = dyn_cast<UnaryOperator>(Arg)) {
auto OpCode = UO->getOpcode();
if (OpCode == UO_Deref || OpCode == UO_AddrOf)
if (OpCode == UO_Deref || OpCode == UO_AddrOf) {
Arg = UO->getSubExpr()->IgnoreParenCasts();
continue;
continue;
}
}
break;
} while (Arg);
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s

struct Foo {
int x;
int y;
Foo(int x, int y) : x(x) , y(y) { }
};

template <typename T>
struct Baz {
void ref() const;
void deref() const;
Foo operator*();
bool operator!();
};

inline Foo operator*(const Foo& a, const Foo& b);

Baz<Foo> someFunction();
template <typename CallbackType> void bar(CallbackType callback) {
auto baz = someFunction();
callback(baz);
}

struct Obj {
void ref() const;
void deref() const;

void foo(Foo foo) {
bar([this](auto baz) {
// expected-warning@-1{{Captured raw-pointer 'this' to ref-counted type or CheckedPtr-capable type is unsafe [webkit.UncountedLambdaCapturesChecker]}}
bar([this, foo = *baz, foo2 = !baz](auto&&) {
// expected-warning@-1{{Captured raw-pointer 'this' to ref-counted type or CheckedPtr-capable type is unsafe [webkit.UncountedLambdaCapturesChecker]}}
someFunction();
});
});
}
};