Skip to content

[analyzer] Ignore system headers in WebKit checkers. #91103

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
May 8, 2024
Merged
Show file tree
Hide file tree
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
Expand Up @@ -150,6 +150,9 @@ class UncountedCallArgsChecker
bool shouldSkipCall(const CallExpr *CE) const {
const auto *Callee = CE->getDirectCallee();

if (BR->getSourceManager().isInSystemHeader(CE->getExprLoc()))
return true;

if (Callee && TFA.isTrivial(Callee))
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ class UncountedLocalVarsChecker
if (!V->isLocalVarDecl())
return true;

if (BR->getSourceManager().isInSystemHeader(V->getLocation()))
return true;

return false;
}

Expand Down
17 changes: 17 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/mock-system-header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma clang system_header

template <typename T, typename CreateFunction>
void callMethod(CreateFunction createFunction) {
createFunction()->method();
}

template <typename T, typename CreateFunction>
inline void localVar(CreateFunction createFunction) {
T* obj = createFunction();
obj->method();
}

template <typename T>
struct MemberVariable {
T* obj { nullptr };
};
11 changes: 11 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedLocalVarsChecker -verify %s

#include "mock-types.h"
#include "mock-system-header.h"

void someFunction();

Expand Down Expand Up @@ -187,3 +188,13 @@ void bar() {
}

} // namespace ignore_for_if

namespace ignore_system_headers {

RefCountable *provide_ref_ctnbl();

void system_header() {
localVar<RefCountable>(provide_ref_ctnbl);
}

} // ignore_system_headers
10 changes: 10 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.NoUncountedMemberChecker -verify %s

#include "mock-types.h"
#include "mock-system-header.h"

namespace members {
struct Foo {
Expand Down Expand Up @@ -50,3 +51,12 @@ namespace ignore_unions {

void forceTmplToInstantiate(RefPtr<RefCountable>) {}
}

namespace ignore_system_header {

void foo(RefCountable* t) {
MemberVariable<RefCountable> var { t };
var.obj->method();
}

} // ignore_system_header
6 changes: 6 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s

#include "mock-types.h"
#include "mock-system-header.h"

void WTFBreakpointTrap();
void WTFCrashWithInfo(int, const char*, const char*, int);
Expand Down Expand Up @@ -147,6 +148,7 @@ class RefCounted {
void ref() const;
void deref() const;

void method();
void someFunction();
int otherFunction();

Expand Down Expand Up @@ -399,3 +401,7 @@ void someFunction(const RefCounted&);
void test2() {
someFunction(*object());
}

void system_header() {
callMethod<RefCountable>(object);
}