File tree Expand file tree Collapse file tree 5 files changed +38
-15
lines changed
lib/StaticAnalyzer/Checkers/WebKit
test/Analysis/Checkers/WebKit Expand file tree Collapse file tree 5 files changed +38
-15
lines changed Original file line number Diff line number Diff 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" ||
@@ -645,6 +645,10 @@ class TrivialFunctionAnalysisVisitor
645645 auto *Callee = CE->getDirectCallee ();
646646 if (!Callee)
647647 return false ;
648+
649+ if (isPtrConversion (Callee))
650+ return true ;
651+
648652 const auto &Name = safeGetName (Callee);
649653
650654 if (Callee->isInStdNamespace () &&
@@ -658,7 +662,7 @@ class TrivialFunctionAnalysisVisitor
658662 Name == " isMainThreadOrGCThread" || Name == " isMainRunLoop" ||
659663 Name == " isWebThread" || Name == " isUIThread" ||
660664 Name == " mayBeGCThread" || Name == " compilerFenceForCrash" ||
661- Name == " bitwise_cast " || isTrivialBuiltinFunction (Callee))
665+ isTrivialBuiltinFunction (Callee))
662666 return true ;
663667
664668 return IsFunctionTrivial (Callee);
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -205,6 +205,20 @@ void foo2() {
205205}
206206} // namespace guardian_casts
207207
208+ namespace casts {
209+
210+ RefCountable* provide () { return nullptr ; }
211+ RefCountable* downcast (RefCountable*);
212+ template <class T > T* bitwise_cast (T*);
213+ template <class T > T* bit_cast (T*);
214+
215+ void foo () {
216+ auto * cast1 = downcast (provide ());
217+ auto * cast2 = bitwise_cast (provide ());
218+ auto * cast3 = bit_cast (provide ());
219+ }
220+ } // namespace casts
221+
208222namespace guardian_ref_conversion_operator {
209223void foo () {
210224 Ref<RefCountable> rc;
Original file line number Diff line number Diff line change @@ -77,6 +77,9 @@ T&& forward(T& arg);
7777template <typename T>
7878T&& 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
You can’t perform that action at this time.
0 commit comments