Skip to content

Commit 4781941

Browse files
authored
[alpha.webkit.UncountedCallArgsChecker] os_log functions should be treated as safe. (#131500)
…os_log functions should be treated as safe in call arguments checkers. Also treat __builtin_* functions and __libcpp_verbose_abort functions as "trivial" for the purpose in call argument checkers.
1 parent 2f808dd commit 4781941

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,14 @@ bool isPtrConversion(const FunctionDecl *F) {
424424
return false;
425425
}
426426

427+
bool isTrivialBuiltinFunction(const FunctionDecl *F) {
428+
if (!F || !F->getDeclName().isIdentifier())
429+
return false;
430+
auto Name = F->getName();
431+
return Name.starts_with("__builtin") || Name == "__libcpp_verbose_abort" ||
432+
Name.starts_with("os_log") || Name.starts_with("_os_log");
433+
}
434+
427435
bool isSingleton(const FunctionDecl *F) {
428436
assert(F);
429437
// FIXME: check # of params == 1
@@ -601,8 +609,7 @@ class TrivialFunctionAnalysisVisitor
601609
Name == "isMainThreadOrGCThread" || Name == "isMainRunLoop" ||
602610
Name == "isWebThread" || Name == "isUIThread" ||
603611
Name == "mayBeGCThread" || Name == "compilerFenceForCrash" ||
604-
Name == "bitwise_cast" || Name.find("__builtin") == 0 ||
605-
Name == "__libcpp_verbose_abort")
612+
Name == "bitwise_cast" || isTrivialBuiltinFunction(Callee))
606613
return true;
607614

608615
return IsFunctionTrivial(Callee);

clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ std::optional<bool> isGetterOfSafePtr(const clang::CXXMethodDecl *Method);
142142
/// pointer types.
143143
bool isPtrConversion(const FunctionDecl *F);
144144

145+
/// \returns true if \p F is a builtin function which is considered trivial.
146+
bool isTrivialBuiltinFunction(const FunctionDecl *F);
147+
145148
/// \returns true if \p F is a static singleton function.
146149
bool isSingleton(const FunctionDecl *F);
147150

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ class RawPtrRefCallArgsChecker
246246
if (Callee && TFA.isTrivial(Callee) && !Callee->isVirtualAsWritten())
247247
return true;
248248

249+
if (isTrivialBuiltinFunction(Callee))
250+
return true;
251+
249252
if (CE->getNumArgs() == 0)
250253
return false;
251254

clang/test/Analysis/Checkers/WebKit/mock-system-header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ enum os_log_type_t : uint8_t {
2828

2929
typedef struct os_log_s *os_log_t;
3030
os_log_t os_log_create(const char *subsystem, const char *category);
31-
void os_log_msg(os_log_t oslog, os_log_type_t type, const char *msg);
31+
void os_log_msg(os_log_t oslog, os_log_type_t type, const char *msg, ...);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,13 @@ RefPtr<RefCounted> object();
695695
void someFunction(const RefCounted&);
696696

697697
void test2() {
698-
someFunction(*object());
698+
someFunction(*object());
699699
}
700700

701701
void system_header() {
702702
callMethod<RefCountable>(object);
703703
}
704+
705+
void log(RefCountable* obj) {
706+
os_log_msg(os_log_create("WebKit", "DOM"), OS_LOG_TYPE_INFO, "obj: %p next: %p", obj, obj->next());
707+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ @interface WrapperObj : NSObject
5050
static void foo(WrapperObj *configuration) {
5151
configuration._protectedWebExtensionControllerConfiguration->copy();
5252
}
53+
54+
void log(RefCountable* obj) {
55+
os_log_msg(os_log_create("WebKit", "DOM"), OS_LOG_TYPE_INFO, "obj: %p next: %p", obj, obj->next());
56+
}

0 commit comments

Comments
 (0)