Skip to content

Commit 49f3566

Browse files
committed
Also fix TrivialFunctionAnalysisVisitor to recognize std::bit_cast as trivial
1 parent c76e861 commit 49f3566

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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);

clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
208222
namespace guardian_ref_conversion_operator {
209223
void foo() {
210224
Ref<RefCountable> rc;

0 commit comments

Comments
 (0)