Skip to content

Merge Webkit checker fixes #10038

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 49 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
52b29a7
[webkit.RefCntblBaseVirtualDtor] Make ThreadSafeRefCounted not genera…
rniwa Sep 11, 2024
705c658
[WebKit Static Analyzer] Treat WTFReportBacktrace as a trivial functi…
rniwa Sep 11, 2024
2fa4ba1
[WebKit Checkers] Allow "singleton" suffix to be camelCased. (#108257)
rniwa Sep 11, 2024
c7f0961
[alpha.webkit.UncountedCallArgsChecker] Allow protector functions in …
rniwa Sep 11, 2024
bd4a088
[alpha.webkit.UncountedCallArgsChecker] Add support for Objective-C++…
rniwa Sep 18, 2024
69bbcce
[webkit.RefCntblBaseVirtualDtor] ThreadSafeRefCounted still generates…
rniwa Sep 18, 2024
f5d4535
[alpha.webkit.UncountedCallArgsChecker] Use canonical type (#109393)
rniwa Sep 27, 2024
be1eac1
WebKit Checkers should set DeclWithIssue. (#109389)
rniwa Sep 27, 2024
f6c5b46
[alpha.webkit.NoUncheckedPtrMemberChecker] Introduce member variable …
rniwa Sep 27, 2024
d3f17ae
[alpha.webkit.UncountedCallArgsChecker] Skip std::forward in tryToFin…
rniwa Oct 10, 2024
f91b736
[alpha.webkit.UncountedCallArgsChecker] Add the support for trivial C…
rniwa Oct 10, 2024
cca5259
isUncountedPtr should take QualType as an argument. (#110213)
rniwa Oct 10, 2024
bafe96a
[alpha.webkit.UncountedLocalVarsChecker] Recursive functions are erro…
rniwa Oct 17, 2024
1e106d8
[WebKit Checkers] Allow a guardian CheckedPtr/CheckedRef (#110222)
rniwa Oct 25, 2024
73a4f81
[alpha.webkit.UncountedLocalVarsChecker] Warn the use of a raw pointe…
rniwa Oct 30, 2024
a7141f2
Introduce a new WebKit checker for a unchecked local variable (#113708)
rniwa Nov 1, 2024
71be385
Update clang static analyzers per rename of member functions in CanMa…
rniwa Nov 5, 2024
d8d6d11
Introduce a new WebKit checker for a unchecked call arguments (#11370…
rniwa Nov 7, 2024
cf6b7bd
[webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and …
rniwa Nov 12, 2024
2942942
[WebKit Checkers] Make TrivialFunctionAnalysis recognize std::array::…
t-rasmud Oct 24, 2024
f4a2542
[WebKit checkers] Treat ref() and incrementCheckedPtrCount() as trivi…
rniwa Nov 14, 2024
e980007
[Webkit Checkers] Treat const member variables as a safe origin (#115…
rniwa Nov 15, 2024
1e61f30
[webkit.UncountedLambdaCapturesChecker] Fix debug assertion failure. …
rniwa Nov 21, 2024
ca7ae4e
[webkit.UncountedLambdaCapturesChecker] Ignore lambda invocation with…
rniwa Nov 23, 2024
cb4a48d
[ASTMatchers] AST matcher support for ObjC pointers (#117021)
t-rasmud Dec 3, 2024
7599261
[Webkit Checkers] Introduce a Webkit checker for memory unsafe casts …
t-rasmud Dec 5, 2024
a06f0bd
UncountedLocalVarsChecker and UncheckedLocalVarsChecker should recogn…
rniwa Dec 10, 2024
0dc0498
Fix a bug that CXXConstructExpr wasn't recognized by tryToFindPtrOrig…
rniwa Dec 12, 2024
17cea60
[WebKit checkers] Recognize ensureFoo functions (#119681)
rniwa Dec 13, 2024
f0a358e
[webkit.UncountedLambdaCapturesChecker] Add a fallback for checking l…
rniwa Dec 15, 2024
946e837
[WebKit checkers] Recognize adoptRef as a safe function (#120629)
rniwa Dec 20, 2024
f55b40e
[webkit.UncountedLambdaCapturesChecker] Detect protectedThis pattern.…
rniwa Dec 20, 2024
37fde4b
[webkit.UncountedLambdaCapturesChecker] Fix a nullptr deference. (#12…
rniwa Dec 20, 2024
623e1b4
[Static analysis] Encodes a filename before inserting it into a URL. …
rniwa Jan 17, 2025
03431c0
[webkit.UncountedLambdaCapturesChecker] Fix a bug that the checker di…
rniwa Feb 5, 2025
338625d
[webkit.UncountedLambdaCapturesChecker] Fix a regression that [[noesc…
rniwa Feb 7, 2025
69d9462
[WebKit checkers] Treat an implicit value initialization as trivial (…
rniwa Feb 11, 2025
38cf7a2
[WebKit Checkers] Treat const Objective-C ivar as a safe origin (#126…
rniwa Feb 11, 2025
ec65ecf
[WebKit Checkers] Allow operator T&() in a const member function (#12…
rniwa Feb 11, 2025
8881a46
[NFC] [clang] fix unused variable warning (#126796)
fmayer Feb 11, 2025
7a17516
[NFC] [clang] Use isa instead of dyn_cast
fmayer Feb 11, 2025
d109d96
[WebKit Checkers] Treat offsetof as a trivial expression. (#126996)
rniwa Feb 14, 2025
69edf7f
[webkit.UncountedLambdaCapturesChecker] Support [[clang::noescape]] o…
rniwa Feb 14, 2025
d99a480
[alpha.webkit.UncountedCallArgsChecker] Allow ArrayInitLoopExpr and O…
rniwa Feb 14, 2025
3926bc2
[webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThi…
rniwa Feb 15, 2025
5e36c55
[WebKit Checkers] Treat attributes as trivial (#127289)
rniwa Feb 15, 2025
09f00b8
[webkit.UncountedLambdaCapturesChecker] Fix a crash in declProtectsTh…
rniwa Feb 15, 2025
6adc720
center-endpath-html.patch
rniwa Feb 19, 2025
f811649
Check the type of Objective-C++ instance variables in WebKit member v…
rniwa Feb 19, 2025
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
Prev Previous commit
Next Next commit
WebKit Checkers should set DeclWithIssue. (llvm#109389)
Set DeclWithIssue in alpha.webkit.UncountedCallArgsChecker and
alpha.webkit.UncountedLocalVarsChecker.
  • Loading branch information
rniwa committed Feb 7, 2025
commit be1eac1c4b036b86fb986ccb6566f648bf3db304
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/SaveAndRestore.h"
#include <optional>

using namespace clang;
Expand All @@ -44,7 +46,11 @@ class UncountedCallArgsChecker
// visit template instantiations or lambda classes. We
// want to visit those, so we make our own RecursiveASTVisitor.
struct LocalVisitor : public RecursiveASTVisitor<LocalVisitor> {
using Base = RecursiveASTVisitor<LocalVisitor>;

const UncountedCallArgsChecker *Checker;
Decl *DeclWithIssue{nullptr};

explicit LocalVisitor(const UncountedCallArgsChecker *Checker)
: Checker(Checker) {
assert(Checker);
Expand All @@ -56,12 +62,18 @@ class UncountedCallArgsChecker
bool TraverseClassTemplateDecl(ClassTemplateDecl *Decl) {
if (isRefType(safeGetName(Decl)))
return true;
return RecursiveASTVisitor<LocalVisitor>::TraverseClassTemplateDecl(
Decl);
return Base::TraverseClassTemplateDecl(Decl);
}

bool TraverseDecl(Decl *D) {
llvm::SaveAndRestore SavedDecl(DeclWithIssue);
if (D && (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)))
DeclWithIssue = D;
return Base::TraverseDecl(D);
}

bool VisitCallExpr(const CallExpr *CE) {
Checker->visitCallExpr(CE);
Checker->visitCallExpr(CE, DeclWithIssue);
return true;
}
};
Expand All @@ -70,7 +82,7 @@ class UncountedCallArgsChecker
visitor.TraverseDecl(const_cast<TranslationUnitDecl *>(TUD));
}

void visitCallExpr(const CallExpr *CE) const {
void visitCallExpr(const CallExpr *CE, const Decl *D) const {
if (shouldSkipCall(CE))
return;

Expand All @@ -89,7 +101,7 @@ class UncountedCallArgsChecker
QualType ArgType = MemberCallExpr->getObjectType().getCanonicalType();
std::optional<bool> IsUncounted = isUncounted(ArgType);
if (IsUncounted && *IsUncounted && !isPtrOriginSafe(E))
reportBugOnThis(E);
reportBugOnThis(E, D);
}

for (auto P = F->param_begin();
Expand Down Expand Up @@ -120,7 +132,7 @@ class UncountedCallArgsChecker
if (isPtrOriginSafe(Arg))
continue;

reportBug(Arg, *P);
reportBug(Arg, *P, D);
}
}
}
Expand Down Expand Up @@ -241,7 +253,8 @@ class UncountedCallArgsChecker
ClsName.ends_with("String"));
}

void reportBug(const Expr *CallArg, const ParmVarDecl *Param) const {
void reportBug(const Expr *CallArg, const ParmVarDecl *Param,
const Decl *DeclWithIssue) const {
assert(CallArg);

SmallString<100> Buf;
Expand All @@ -262,10 +275,11 @@ class UncountedCallArgsChecker
PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
Report->addRange(CallArg->getSourceRange());
Report->setDeclWithIssue(DeclWithIssue);
BR->emitReport(std::move(Report));
}

void reportBugOnThis(const Expr *CallArg) const {
void reportBugOnThis(const Expr *CallArg, const Decl *DeclWithIssue) const {
assert(CallArg);

const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin();
Expand All @@ -275,6 +289,7 @@ class UncountedCallArgsChecker
Bug, "Call argument for 'this' parameter is uncounted and unsafe.",
BSLoc);
Report->addRange(CallArg->getSourceRange());
Report->setDeclWithIssue(DeclWithIssue);
BR->emitReport(std::move(Report));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class UncountedLocalVarsChecker
// want to visit those, so we make our own RecursiveASTVisitor.
struct LocalVisitor : public RecursiveASTVisitor<LocalVisitor> {
const UncountedLocalVarsChecker *Checker;
Decl *DeclWithIssue{nullptr};

TrivialFunctionAnalysis TFA;

Expand All @@ -134,18 +135,25 @@ class UncountedLocalVarsChecker
bool shouldVisitTemplateInstantiations() const { return true; }
bool shouldVisitImplicitCode() const { return false; }

bool TraverseDecl(Decl *D) {
llvm::SaveAndRestore SavedDecl(DeclWithIssue);
if (D && (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)))
DeclWithIssue = D;
return Base::TraverseDecl(D);
}

bool VisitVarDecl(VarDecl *V) {
auto *Init = V->getInit();
if (Init && V->isLocalVarDecl())
Checker->visitVarDecl(V, Init);
Checker->visitVarDecl(V, Init, DeclWithIssue);
return true;
}

bool VisitBinaryOperator(const BinaryOperator *BO) {
if (BO->isAssignmentOp()) {
if (auto *VarRef = dyn_cast<DeclRefExpr>(BO->getLHS())) {
if (auto *V = dyn_cast<VarDecl>(VarRef->getDecl()))
Checker->visitVarDecl(V, BO->getRHS());
Checker->visitVarDecl(V, BO->getRHS(), DeclWithIssue);
}
}
return true;
Expand Down Expand Up @@ -186,7 +194,8 @@ class UncountedLocalVarsChecker
visitor.TraverseDecl(const_cast<TranslationUnitDecl *>(TUD));
}

void visitVarDecl(const VarDecl *V, const Expr *Value) const {
void visitVarDecl(const VarDecl *V, const Expr *Value,
const Decl *DeclWithIssue) const {
if (shouldSkipVarDecl(V))
return;

Expand Down Expand Up @@ -240,7 +249,7 @@ class UncountedLocalVarsChecker
}))
return;

reportBug(V, Value);
reportBug(V, Value, DeclWithIssue);
}
}

Expand All @@ -249,7 +258,8 @@ class UncountedLocalVarsChecker
return BR->getSourceManager().isInSystemHeader(V->getLocation());
}

void reportBug(const VarDecl *V, const Expr *Value) const {
void reportBug(const VarDecl *V, const Expr *Value,
const Decl *DeclWithIssue) const {
assert(V);
SmallString<100> Buf;
llvm::raw_svector_ostream Os(Buf);
Expand Down Expand Up @@ -278,6 +288,7 @@ class UncountedLocalVarsChecker
PathDiagnosticLocation BSLoc(V->getLocation(), BR->getSourceManager());
auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
Report->addRange(V->getSourceRange());
Report->setDeclWithIssue(DeclWithIssue);
BR->emitReport(std::move(Report));
}
}
Expand Down