Debian Codegraph @

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

raw
1 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2
3 #include "mock-types.h"
4
5 class Base {
6 public:
7 void ref();
8 void deref();
9 void doWork();
10 };
11
12 class Derived : public Base {
13 public:
14 virtual ~Derived();
15
16 void ref() const;
17 void deref() const;
18 };
19
20 class SubDerived final : public Derived {
21 };
22
23 class OtherObject {
24 public:
25 Derived* obj();
26 Base* base();
27 };
28
29 class String {
30 };
31
32 template<typename Target, typename Source>
33 inline Target* dynamicDowncast(Source* source)
34 {
35 return static_cast<Target*>(source);
36 }
37
38 template<typename Target, typename Source>
39 inline Target* checkedDowncast(Source* source)
40 {
41 return static_cast<Target*>(source);
42 }
43
44 template<typename Target, typename Source>
45 inline Target* uncheckedDowncast(Source* source)
46 {
47 return static_cast<Target*>(source);
48 }
49
50 template<typename Target, typename Source>
51 Target* [[clang::annotate_type("webkit.pointerconversion")]] newCastFunction(Source*);
52
53 template<typename Target, typename Source>
54 Target* [[clang::annotate_type("unrelated-annotation")]] badCastFunction(Source*);
55
56 template<typename... Types>
57 String toString(const Types&... values);
58
59 void foo(OtherObject* other)
60 {
61 dynamicDowncast<SubDerived>(other->obj());
62 checkedDowncast<SubDerived>(other->obj());
63 uncheckedDowncast<SubDerived>(other->obj());
64 newCastFunction<SubDerived>(other->obj());
65 badCastFunction<SubDerived>(other->obj());
66 // expected-warning@-1{{Call argument is uncounted and unsafe}}
67 toString(other->obj());
68 }
69
70 struct SomeStruct {
71 Derived* [[clang::annotate_type("webkit.pointerconversion")]] ptrConversion(Base*);
72
73 void foo(OtherObject& otherObj) {
74 RefPtr ptr = otherObj.base();
75 ptrConversion(ptr.get())->doWork();
76 }
77 };