File tree 5 files changed +38
-15
lines changed
lib/StaticAnalyzer/Checkers/WebKit
test/Analysis/Checkers/WebKit
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) {
462
462
const auto FunctionName = safeGetName (F);
463
463
if (FunctionName == " getPtr" || FunctionName == " WeakPtr" ||
464
464
FunctionName == " dynamicDowncast" || FunctionName == " downcast" ||
465
- FunctionName == " checkedDowncast" ||
465
+ FunctionName == " checkedDowncast" || FunctionName == " bit_cast " ||
466
466
FunctionName == " uncheckedDowncast" || FunctionName == " bitwise_cast" ||
467
467
FunctionName == " bridge_cast" || FunctionName == " bridge_id_cast" ||
468
468
FunctionName == " dynamic_cf_cast" || FunctionName == " checked_cf_cast" ||
@@ -645,6 +645,10 @@ class TrivialFunctionAnalysisVisitor
645
645
auto *Callee = CE->getDirectCallee ();
646
646
if (!Callee)
647
647
return false ;
648
+
649
+ if (isPtrConversion (Callee))
650
+ return true ;
651
+
648
652
const auto &Name = safeGetName (Callee);
649
653
650
654
if (Callee->isInStdNamespace () &&
@@ -658,7 +662,7 @@ class TrivialFunctionAnalysisVisitor
658
662
Name == " isMainThreadOrGCThread" || Name == " isMainRunLoop" ||
659
663
Name == " isWebThread" || Name == " isUIThread" ||
660
664
Name == " mayBeGCThread" || Name == " compilerFenceForCrash" ||
661
- Name == " bitwise_cast " || isTrivialBuiltinFunction (Callee))
665
+ isTrivialBuiltinFunction (Callee))
662
666
return true ;
663
667
664
668
return IsFunctionTrivial (Callee);
Original file line number Diff line number Diff line change @@ -173,14 +173,14 @@ namespace param_formarding_function {
173
173
174
174
namespace casts {
175
175
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*);
180
179
181
180
void foo (CheckedObj* param) {
182
181
consume_ref_countable_ptr (downcast (param));
183
182
consume_ref_countable_ptr (bitwise_cast (param));
183
+ consume_ref_countable_ptr (bit_cast (param));
184
184
}
185
185
}
186
186
}
Original file line number Diff line number Diff line change @@ -173,15 +173,15 @@ namespace param_formarding_function {
173
173
174
174
namespace casts {
175
175
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
+ }
185
185
}
186
186
}
187
187
Original file line number Diff line number Diff line change @@ -205,6 +205,20 @@ void foo2() {
205
205
}
206
206
} // namespace guardian_casts
207
207
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
+
208
222
namespace guardian_ref_conversion_operator {
209
223
void foo () {
210
224
Ref<RefCountable> rc;
Original file line number Diff line number Diff line change @@ -77,6 +77,9 @@ T&& forward(T& arg);
77
77
template <typename T>
78
78
T&& move( T&& t );
79
79
80
+ template <typename ToType, typename FromType>
81
+ ToType bit_cast (FromType from);
82
+
80
83
#define offsetof (t, d ) __builtin_offsetof(t, d)
81
84
82
85
} // namespace std
@@ -386,6 +389,7 @@ class RefCounted {
386
389
void trivial68 () { point pt = { 1.0 }; }
387
390
unsigned trivial69 () { return offsetof (OtherObj, children); }
388
391
DerivedNumber* trivial70 () { [[clang::suppress]] return static_cast <DerivedNumber*>(number); }
392
+ unsigned trivial71 () { return std::bit_cast<unsigned >(nullptr ); }
389
393
390
394
static RefCounted& singleton () {
391
395
static RefCounted s_RefCounted;
@@ -577,6 +581,7 @@ class UnrelatedClass {
577
581
getFieldTrivial ().trivial68 (); // no-warning
578
582
getFieldTrivial ().trivial69 (); // no-warning
579
583
getFieldTrivial ().trivial70 (); // no-warning
584
+ getFieldTrivial ().trivial71 (); // no-warning
580
585
581
586
RefCounted::singleton ().trivial18 (); // no-warning
582
587
RefCounted::singleton ().someFunction (); // no-warning
You can’t perform that action at this time.
0 commit comments