Skip to content

Commit c76e861

Browse files
committed
[WebKit checkers] Treat std::bit_cast as a pointer conversion
WebKit repalced its use of WTF::bitwise_cast with std::bit_cast. Add the support for recognizing it as a pointer conversion.
1 parent 70e303f commit c76e861

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ bool isPtrConversion(const FunctionDecl *F) {
462462
const auto FunctionName = safeGetName(F);
463463
if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
464464
FunctionName == "dynamicDowncast" || FunctionName == "downcast" ||
465-
FunctionName == "checkedDowncast" ||
465+
FunctionName == "checkedDowncast" || FunctionName == "bit_cast" ||
466466
FunctionName == "uncheckedDowncast" || FunctionName == "bitwise_cast" ||
467467
FunctionName == "bridge_cast" || FunctionName == "bridge_id_cast" ||
468468
FunctionName == "dynamic_cf_cast" || FunctionName == "checked_cf_cast" ||

clang/test/Analysis/Checkers/WebKit/call-args-checked-ptr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ namespace param_formarding_function {
173173

174174
namespace casts {
175175

176-
CheckedObj* downcast(CheckedObj*) { return nullptr; }
177-
178-
template<class T>
179-
T* bitwise_cast(T*) { return nullptr; }
176+
CheckedObj* downcast(CheckedObj*);
177+
template<class T> T* bitwise_cast(T*);
178+
template<class T> T* bit_cast(T*);
180179

181180
void foo(CheckedObj* param) {
182181
consume_ref_countable_ptr(downcast(param));
183182
consume_ref_countable_ptr(bitwise_cast(param));
183+
consume_ref_countable_ptr(bit_cast(param));
184184
}
185185
}
186186
}

clang/test/Analysis/Checkers/WebKit/call-args.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ namespace param_formarding_function {
173173

174174
namespace casts {
175175

176-
RefCountable* downcast(RefCountable*) { return nullptr; }
177-
178-
template<class T>
179-
T* bitwise_cast(T*) { return nullptr; }
180-
181-
void foo(RefCountable* param) {
182-
consume_ref_countable_ptr(downcast(param));
183-
consume_ref_countable_ptr(bitwise_cast(param));
184-
}
176+
RefCountable* downcast(RefCountable*);
177+
template<class T> T* bitwise_cast(T*);
178+
template<class T> T* bit_cast(T*);
179+
180+
void foo(RefCountable* param) {
181+
consume_ref_countable_ptr(downcast(param));
182+
consume_ref_countable_ptr(bitwise_cast(param));
183+
consume_ref_countable_ptr(bit_cast(param));
184+
}
185185
}
186186
}
187187

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ T&& forward(T& arg);
7777
template<typename T>
7878
T&& move( T&& t );
7979

80+
template<typename ToType, typename FromType>
81+
ToType bit_cast(FromType from);
82+
8083
#define offsetof(t, d) __builtin_offsetof(t, d)
8184

8285
} // namespace std
@@ -386,6 +389,7 @@ class RefCounted {
386389
void trivial68() { point pt = { 1.0 }; }
387390
unsigned trivial69() { return offsetof(OtherObj, children); }
388391
DerivedNumber* trivial70() { [[clang::suppress]] return static_cast<DerivedNumber*>(number); }
392+
unsigned trivial71() { return std::bit_cast<unsigned>(nullptr); }
389393

390394
static RefCounted& singleton() {
391395
static RefCounted s_RefCounted;
@@ -577,6 +581,7 @@ class UnrelatedClass {
577581
getFieldTrivial().trivial68(); // no-warning
578582
getFieldTrivial().trivial69(); // no-warning
579583
getFieldTrivial().trivial70(); // no-warning
584+
getFieldTrivial().trivial71(); // no-warning
580585

581586
RefCounted::singleton().trivial18(); // no-warning
582587
RefCounted::singleton().someFunction(); // no-warning

0 commit comments

Comments
 (0)