Skip to content

Commit bb01b89

Browse files
authored
[analyzer] Ignore system headers in WebKit checkers. (#91103)
1 parent d085b42 commit bb01b89

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ class UncountedCallArgsChecker
150150
bool shouldSkipCall(const CallExpr *CE) const {
151151
const auto *Callee = CE->getDirectCallee();
152152

153+
if (BR->getSourceManager().isInSystemHeader(CE->getExprLoc()))
154+
return true;
155+
153156
if (Callee && TFA.isTrivial(Callee))
154157
return true;
155158

clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ class UncountedLocalVarsChecker
230230
if (!V->isLocalVarDecl())
231231
return true;
232232

233+
if (BR->getSourceManager().isInSystemHeader(V->getLocation()))
234+
return true;
235+
233236
return false;
234237
}
235238

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma clang system_header
2+
3+
template <typename T, typename CreateFunction>
4+
void callMethod(CreateFunction createFunction) {
5+
createFunction()->method();
6+
}
7+
8+
template <typename T, typename CreateFunction>
9+
inline void localVar(CreateFunction createFunction) {
10+
T* obj = createFunction();
11+
obj->method();
12+
}
13+
14+
template <typename T>
15+
struct MemberVariable {
16+
T* obj { nullptr };
17+
};

clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedLocalVarsChecker -verify %s
22

33
#include "mock-types.h"
4+
#include "mock-system-header.h"
45

56
void someFunction();
67

@@ -187,3 +188,13 @@ void bar() {
187188
}
188189

189190
} // namespace ignore_for_if
191+
192+
namespace ignore_system_headers {
193+
194+
RefCountable *provide_ref_ctnbl();
195+
196+
void system_header() {
197+
localVar<RefCountable>(provide_ref_ctnbl);
198+
}
199+
200+
} // ignore_system_headers

clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.NoUncountedMemberChecker -verify %s
22

33
#include "mock-types.h"
4+
#include "mock-system-header.h"
45

56
namespace members {
67
struct Foo {
@@ -50,3 +51,12 @@ namespace ignore_unions {
5051

5152
void forceTmplToInstantiate(RefPtr<RefCountable>) {}
5253
}
54+
55+
namespace ignore_system_header {
56+
57+
void foo(RefCountable* t) {
58+
MemberVariable<RefCountable> var { t };
59+
var.obj->method();
60+
}
61+
62+
} // ignore_system_header

clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
22

33
#include "mock-types.h"
4+
#include "mock-system-header.h"
45

56
void WTFBreakpointTrap();
67
void WTFCrashWithInfo(int, const char*, const char*, int);
@@ -147,6 +148,7 @@ class RefCounted {
147148
void ref() const;
148149
void deref() const;
149150

151+
void method();
150152
void someFunction();
151153
int otherFunction();
152154

@@ -399,3 +401,7 @@ void someFunction(const RefCounted&);
399401
void test2() {
400402
someFunction(*object());
401403
}
404+
405+
void system_header() {
406+
callMethod<RefCountable>(object);
407+
}

0 commit comments

Comments
 (0)