llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) <details> <summary>Changes</summary> This PR aligns webkit.UncountedLambdaCapturesChecker and its variant's warning message with the new warning format in other checkers. --- Patch is 43.26 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/209198.diff 6 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp (+4-18) - (modified) clang/test/Analysis/Checkers/WebKit/unchecked-lambda-captures.cpp (+26-26) - (modified) clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp (+2-2) - (modified) clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp (+25-25) - (modified) clang/test/Analysis/Checkers/WebKit/unretained-lambda-captures-arc.mm (+7-7) - (modified) clang/test/Analysis/Checkers/WebKit/unretained-lambda-captures.mm (+24-24) ``````````diff diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp index 013608c0ff32c..8fec7823f623b 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp @@ -562,20 +562,6 @@ class RawPtrRefLambdaCapturesChecker BR->emitReport(std::move(Report)); } - ObjCInterfaceDecl *getObjCDecl(const Type *TypePtr) const { - auto *PointeeType = TypePtr->getPointeeType().getTypePtrOrNull(); - if (!PointeeType) - return nullptr; - auto *Desugared = PointeeType->getUnqualifiedDesugaredType(); - if (!Desugared) - return nullptr; - if (auto *ObjCType = dyn_cast<ObjCInterfaceType>(Desugared)) - return ObjCType->getDecl(); - if (auto *ObjCType = dyn_cast<ObjCObjectType>(Desugared)) - return ObjCType->getInterface(); - return nullptr; - } - void reportBugOnThisPtr(const LambdaCapture &Capture, const QualType T) const { SmallString<100> Buf; @@ -608,7 +594,7 @@ class RawPtrRefLambdaCapturesChecker if (auto *RD = T->getPointeeType()->getAsRecordDecl()) { Os << " "; printQuotedQualifiedName(Os, RD); - } else if (auto *ObjCDecl = getObjCDecl(T)) { + } else if (auto *ObjCDecl = getObjCDeclFromObjCPtr(T)) { Os << " "; printQuotedQualifiedName(Os, ObjCDecl); } @@ -629,7 +615,7 @@ class UncountedLambdaCapturesChecker : public RawPtrRefLambdaCapturesChecker { return isRefType(Name); } - const char *typeName() const final { return "ref-countable type"; } + const char *typeName() const final { return "RefPtr-capable type"; } }; class UncheckedLambdaCapturesChecker : public RawPtrRefLambdaCapturesChecker { @@ -646,7 +632,7 @@ class UncheckedLambdaCapturesChecker : public RawPtrRefLambdaCapturesChecker { return isCheckedPtr(Name); } - const char *typeName() const final { return "CheckedPtr capable type"; } + const char *typeName() const final { return "CheckedPtr-capable type"; } }; class UnretainedLambdaCapturesChecker : public RawPtrRefLambdaCapturesChecker { @@ -667,7 +653,7 @@ class UnretainedLambdaCapturesChecker : public RawPtrRefLambdaCapturesChecker { return isRetainPtrOrOSPtr(Name); } - const char *typeName() const final { return "retainable type"; } + const char *typeName() const final { return "RetainPtr-capable type"; } void printPointer(llvm::raw_svector_ostream &Os, const Type *T) const final { if (auto *ObjCPtr = dyn_cast<ObjCObjectPointerType>(T)) { diff --git a/clang/test/Analysis/Checkers/WebKit/unchecked-lambda-captures.cpp b/clang/test/Analysis/Checkers/WebKit/unchecked-lambda-captures.cpp index 611c62063db0a..6bd2fa710bcd0 100644 --- a/clang/test/Analysis/Checkers/WebKit/unchecked-lambda-captures.cpp +++ b/clang/test/Analysis/Checkers/WebKit/unchecked-lambda-captures.cpp @@ -18,22 +18,22 @@ void callAsync(const WTF::Function<void()>&); void raw_ptr() { CheckedObj* checked_ptr_capable = make_obj(); auto foo1 = [checked_ptr_capable](){ - // expected-warning@-1{{Captured variable 'checked_ptr_capable' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'checked_ptr_capable' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} checked_ptr_capable->method(); }; auto foo2 = [&checked_ptr_capable](){ - // expected-warning@-1{{Captured variable 'checked_ptr_capable' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'checked_ptr_capable' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} checked_ptr_capable->method(); }; auto foo3 = [&](){ checked_ptr_capable->method(); - // expected-warning@-1{{Implicitly captured variable 'checked_ptr_capable' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'checked_ptr_capable' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} checked_ptr_capable = nullptr; }; auto foo4 = [=](){ checked_ptr_capable->method(); - // expected-warning@-1{{Implicitly captured variable 'checked_ptr_capable' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'checked_ptr_capable' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }; call(foo1); @@ -53,9 +53,9 @@ void references() { CheckedObj& checked_ptr_capable_ref = automatic; auto foo1 = [checked_ptr_capable_ref](){ checked_ptr_capable_ref.constMethod(); }; auto foo2 = [&checked_ptr_capable_ref](){ checked_ptr_capable_ref.method(); }; - // expected-warning@-1{{Captured variable 'checked_ptr_capable_ref' is a raw reference to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'checked_ptr_capable_ref' is a raw reference to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} auto foo3 = [&](){ checked_ptr_capable_ref.method(); }; - // expected-warning@-1{{Implicitly captured variable 'checked_ptr_capable_ref' is a raw reference to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'checked_ptr_capable_ref' is a raw reference to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} auto foo4 = [=](){ checked_ptr_capable_ref.constMethod(); }; call(foo1); @@ -109,7 +109,7 @@ void noescape_lambda() { otherObj->method(); }, [&](CheckedObj& obj) { otherObj->method(); - // expected-warning@-1{{Implicitly captured variable 'otherObj' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'otherObj' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }); ([&] { someObj->method(); @@ -139,7 +139,7 @@ struct CheckedObjWithLambdaCapturingThis { void method_captures_this_unsafe() { auto lambda = [&]() { nonTrivial(); - // expected-warning@-1{{Implicitly captured variable 'this' is a raw pointer to CheckedPtr capable type 'CheckedObjWithLambdaCapturingThis' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'this' is a raw pointer to CheckedPtr-capable type 'CheckedObjWithLambdaCapturingThis' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }; call(lambda); } @@ -147,7 +147,7 @@ struct CheckedObjWithLambdaCapturingThis { void method_captures_this_unsafe_capture_local_var_explicitly() { CheckedObj* x = make_obj(); call([this, protectedThis = CheckedPtr { this }, x]() { - // expected-warning@-1{{Captured variable 'x' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'x' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} nonTrivial(); x->method(); }); @@ -156,7 +156,7 @@ struct CheckedObjWithLambdaCapturingThis { void method_captures_this_with_other_protected_var() { CheckedObj* x = make_obj(); call([this, protectedX = CheckedPtr { x }]() { - // expected-warning@-1{{Captured variable 'this' is a raw pointer to CheckedPtr capable type 'CheckedObjWithLambdaCapturingThis' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'this' is a raw pointer to CheckedPtr-capable type 'CheckedObjWithLambdaCapturingThis' [alpha.webkit.UncheckedLambdaCapturesChecker]}} nonTrivial(); protectedX->method(); }); @@ -165,7 +165,7 @@ struct CheckedObjWithLambdaCapturingThis { void method_captures_this_unsafe_capture_local_var_explicitly_with_deref() { CheckedObj* x = make_obj(); call([this, protectedThis = CheckedRef { *this }, x]() { - // expected-warning@-1{{Captured variable 'x' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'x' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} nonTrivial(); x->method(); }); @@ -174,7 +174,7 @@ struct CheckedObjWithLambdaCapturingThis { void method_captures_this_unsafe_local_var_via_vardecl() { CheckedObj* x = make_obj(); auto lambda = [this, protectedThis = CheckedRef { *this }, x]() { - // expected-warning@-1{{Captured variable 'x' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'x' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} nonTrivial(); x->method(); }; @@ -252,7 +252,7 @@ struct CheckedObjWithLambdaCapturingThis { void method_nested_lambda3() { callAsync([this, protectedThis = CheckedPtr { this }] { callAsync([this] { - // expected-warning@-1{{Captured variable 'this' is a raw pointer to CheckedPtr capable type 'CheckedObjWithLambdaCapturingThis' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'this' is a raw pointer to CheckedPtr-capable type 'CheckedObjWithLambdaCapturingThis' [alpha.webkit.UncheckedLambdaCapturesChecker]}} nonTrivial(); }); }); @@ -321,11 +321,11 @@ void lambda_converted_to_function(CheckedObj* obj) { callFunction([&]() { obj->method(); - // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }); callFunctionOpaque([&]() { obj->method(); - // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }); } @@ -335,7 +335,7 @@ void capture_copy_in_lambda(CheckedObj& checked) { }); auto* ptr = &checked; callFunctionOpaque([ptr]() mutable { - // expected-warning@-1{{Captured variable 'ptr' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'ptr' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} ptr->method(); }); } @@ -436,7 +436,7 @@ void doWhateverWith(WTF::ScopeExit& obj); void scope_exit_with_side_effect(CheckedObj* obj) { auto scope = WTF::makeScopeExit([&] { obj->method(); - // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }); doWhateverWith(scope); } @@ -444,14 +444,14 @@ void scope_exit_with_side_effect(CheckedObj* obj) { void scope_exit_static(CheckedObj* obj) { static auto scope = WTF::makeScopeExit([&] { obj->method(); - // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }); } WTF::Function<void()> scope_exit_take_lambda(CheckedObj* obj) { auto scope = WTF::makeScopeExit([&] { obj->method(); - // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }); return scope.take(); } @@ -460,7 +460,7 @@ WTF::Function<void()> scope_exit_take_lambda(CheckedObj* obj) { void scope_exit_release(CheckedObj* obj) { auto scope = WTF::makeScopeExit([&] { obj->method(); - // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }); scope.release(); } @@ -486,7 +486,7 @@ void bad_visit(Visitor&, ObjectType*) { void static_visitor(CheckedObj* obj) { static auto visitor = WTF::makeVisitor([&] { obj->method(); - // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }); } @@ -494,10 +494,10 @@ void make_visitor_with_multiple_lambdas(CheckedObj* obj) { auto* otherObj = make_obj(); auto visitor = WTF::makeVisitor([&] { obj->method(); - // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }, [&] { otherObj->method(); - // expected-warning@-1{{Implicitly captured variable 'otherObj' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'otherObj' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }); bad_visit(visitor, obj); } @@ -505,7 +505,7 @@ void make_visitor_with_multiple_lambdas(CheckedObj* obj) { void bad_use_visitor(CheckedObj* obj) { auto visitor = WTF::makeVisitor([&] { obj->method(); - // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'obj' is a raw pointer to CheckedPtr-capable type 'CheckedObj' [alpha.webkit.UncheckedLambdaCapturesChecker]}} }); bad_visit(visitor, obj); } @@ -514,14 +514,14 @@ class LambdaInConstructorDestructor { public: LambdaInConstructorDestructor() { call([this]() { - // expected-warning@-1{{Captured variable 'this' is a raw pointer to CheckedPtr capable type 'LambdaInConstructorDestructor' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'this' is a raw pointer to CheckedPtr-capable type 'LambdaInConstructorDestructor' [alpha.webkit.UncheckedLambdaCapturesChecker]}} doWork(); }); } ~LambdaInConstructorDestructor() { call([this]() { - // expected-warning@-1{{Captured variable 'this' is a raw pointer to CheckedPtr capable type 'LambdaInConstructorDestructor' [alpha.webkit.UncheckedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'this' is a raw pointer to CheckedPtr-capable type 'LambdaInConstructorDestructor' [alpha.webkit.UncheckedLambdaCapturesChecker]}} doWork(); }); } diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp index 1afbd0df93f18..b46377371547d 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp @@ -28,9 +28,9 @@ struct Obj { void foo(Foo foo) { bar([this](auto baz) { - // expected-warning@-1{{Captured variable 'this' is a raw pointer to ref-countable type 'Obj' [webkit.UncountedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'this' is a raw pointer to RefPtr-capable type 'Obj' [webkit.UncountedLambdaCapturesChecker]}} bar([this, foo = *baz, foo2 = !baz](auto&&) { - // expected-warning@-1{{Captured variable 'this' is a raw pointer to ref-countable type 'Obj' [webkit.UncountedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'this' is a raw pointer to RefPtr-capable type 'Obj' [webkit.UncountedLambdaCapturesChecker]}} someFunction(); }); }); diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp index fc8230838c5cb..3609014deedd8 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp @@ -18,22 +18,22 @@ void callAsync(const WTF::Function<void()>&); void raw_ptr() { RefCountable* ref_countable = make_obj(); auto foo1 = [ref_countable](){ - // expected-warning@-1{{Captured variable 'ref_countable' is a raw pointer to ref-countable type 'RefCountable' [webkit.UncountedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'ref_countable' is a raw pointer to RefPtr-capable type 'RefCountable' [webkit.UncountedLambdaCapturesChecker]}} ref_countable->method(); }; auto foo2 = [&ref_countable](){ - // expected-warning@-1{{Captured variable 'ref_countable' is a raw pointer to ref-countable type 'RefCountable' [webkit.UncountedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'ref_countable' is a raw pointer to RefPtr-capable type 'RefCountable' [webkit.UncountedLambdaCapturesChecker]}} ref_countable->method(); }; auto foo3 = [&](){ ref_countable->method(); - // expected-warning@-1{{Implicitly captured variable 'ref_countable' is a raw pointer to ref-countable type 'RefCountable' [webkit.UncountedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'ref_countable' is a raw pointer to RefPtr-capable type 'RefCountable' [webkit.UncountedLambdaCapturesChecker]}} ref_countable = nullptr; }; auto foo4 = [=](){ ref_countable->method(); - // expected-warning@-1{{Implicitly captured variable 'ref_countable' is a raw pointer to ref-countable type 'RefCountable' [webkit.UncountedLambdaCapturesChecker]}} + // expected-warning@-1{{Implicitly captured variable 'ref_countable' is a raw pointer to RefPtr-capable type 'RefCountable' [webkit.UncountedLambdaCapturesChecker]}} }; call(foo1); @@ -53,9 +53,9 @@ void references() { RefCountable& ref_countable_ref = automatic; auto foo1 = [ref_countable_ref](){ ref_countable_ref.constMethod(); }; auto foo2 = [&ref_countable_ref](){ ref_countable_ref.method(); }; - // expected-warning@-1{{Captured variable 'ref_countable_ref' is a raw reference to ref-countable type 'RefCountable' [webkit.UncountedLambdaCapturesChecker]}} + // expected-warning@-1{{Captured variable 'ref_countable_ref' is a raw reference to RefPtr-capable type 'RefCountable' [webkit.UncountedLambdaCapturesChecker]}} ... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/209198 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
