[WebKit checkers] Treat std::bit_cast as a pointer conversion#137476
Merged
[WebKit checkers] Treat std::bit_cast as a pointer conversion#137476
Conversation
WebKit repalced its use of WTF::bitwise_cast with std::bit_cast. Add the support for recognizing it as a pointer conversion.
Member
|
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) ChangesWebKit repalced its use of WTF::bitwise_cast with std::bit_cast. Add the support for recognizing it as a pointer conversion. Full diff: https://github.com/llvm/llvm-project/pull/137476.diff 4 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index d7111bcb35115..edcf8e4feae4f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -462,7 +462,7 @@ bool isPtrConversion(const FunctionDecl *F) {
const auto FunctionName = safeGetName(F);
if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
FunctionName == "dynamicDowncast" || FunctionName == "downcast" ||
- FunctionName == "checkedDowncast" ||
+ FunctionName == "checkedDowncast" || FunctionName == "bit_cast" ||
FunctionName == "uncheckedDowncast" || FunctionName == "bitwise_cast" ||
FunctionName == "bridge_cast" || FunctionName == "bridge_id_cast" ||
FunctionName == "dynamic_cf_cast" || FunctionName == "checked_cf_cast" ||
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args-checked-ptr.cpp b/clang/test/Analysis/Checkers/WebKit/call-args-checked-ptr.cpp
index 59f247d6d007c..d539891ed832d 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args-checked-ptr.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-checked-ptr.cpp
@@ -173,14 +173,14 @@ namespace param_formarding_function {
namespace casts {
- CheckedObj* downcast(CheckedObj*) { return nullptr; }
-
- template<class T>
- T* bitwise_cast(T*) { return nullptr; }
+ CheckedObj* downcast(CheckedObj*);
+ template<class T> T* bitwise_cast(T*);
+ template<class T> T* bit_cast(T*);
void foo(CheckedObj* param) {
consume_ref_countable_ptr(downcast(param));
consume_ref_countable_ptr(bitwise_cast(param));
+ consume_ref_countable_ptr(bit_cast(param));
}
}
}
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index d95ae9216edcf..1a8bde29080ac 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -173,15 +173,15 @@ namespace param_formarding_function {
namespace casts {
- RefCountable* downcast(RefCountable*) { return nullptr; }
-
- template<class T>
- T* bitwise_cast(T*) { return nullptr; }
-
- void foo(RefCountable* param) {
- consume_ref_countable_ptr(downcast(param));
- consume_ref_countable_ptr(bitwise_cast(param));
- }
+ RefCountable* downcast(RefCountable*);
+ template<class T> T* bitwise_cast(T*);
+ template<class T> T* bit_cast(T*);
+
+ void foo(RefCountable* param) {
+ consume_ref_countable_ptr(downcast(param));
+ consume_ref_countable_ptr(bitwise_cast(param));
+ consume_ref_countable_ptr(bit_cast(param));
+ }
}
}
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 69842264af56b..2c6ccb55e2ce8 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -77,6 +77,9 @@ T&& forward(T& arg);
template<typename T>
T&& move( T&& t );
+template<typename ToType, typename FromType>
+ToType bit_cast(FromType from);
+
#define offsetof(t, d) __builtin_offsetof(t, d)
} // namespace std
@@ -386,6 +389,7 @@ class RefCounted {
void trivial68() { point pt = { 1.0 }; }
unsigned trivial69() { return offsetof(OtherObj, children); }
DerivedNumber* trivial70() { [[clang::suppress]] return static_cast<DerivedNumber*>(number); }
+ unsigned trivial71() { return std::bit_cast<unsigned>(nullptr); }
static RefCounted& singleton() {
static RefCounted s_RefCounted;
@@ -577,6 +581,7 @@ class UnrelatedClass {
getFieldTrivial().trivial68(); // no-warning
getFieldTrivial().trivial69(); // no-warning
getFieldTrivial().trivial70(); // no-warning
+ getFieldTrivial().trivial71(); // no-warning
RefCounted::singleton().trivial18(); // no-warning
RefCounted::singleton().someFunction(); // no-warning
|
t-rasmud
reviewed
Apr 30, 2025
Contributor
Author
|
Thanks for the review! |
rniwa
added a commit
to rniwa/llvm-project
that referenced
this pull request
May 1, 2025
…37476) WebKit repalced its use of WTF::bitwise_cast with std::bit_cast. Add the support for recognizing it as a pointer conversion.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…37476) WebKit repalced its use of WTF::bitwise_cast with std::bit_cast. Add the support for recognizing it as a pointer conversion.
GeorgeARM
pushed a commit
to GeorgeARM/llvm-project
that referenced
this pull request
May 7, 2025
…37476) WebKit repalced its use of WTF::bitwise_cast with std::bit_cast. Add the support for recognizing it as a pointer conversion.
rniwa
added a commit
to rniwa/llvm-project
that referenced
this pull request
Aug 21, 2025
…37476) WebKit repalced its use of WTF::bitwise_cast with std::bit_cast. Add the support for recognizing it as a pointer conversion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WebKit repalced its use of WTF::bitwise_cast with std::bit_cast. Add the support for recognizing it as a pointer conversion.