1 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
3 #include "mock-types.h"
5 RefCountable
* provide() { return nullptr; }
6 void consume_refcntbl(RefCountable
*) {}
10 consume_refcntbl(provide());
11 // expected-warning@-1{{Call argument is uncounted and unsafe}}
16 void consume_refcntbl(int, RefCountable
* foo
, bool) {}
18 consume_refcntbl(42, provide(), true);
19 // expected-warning@-1{{Call argument for parameter 'foo' is uncounted and unsafe}}
23 namespace ref_counted
{
24 Ref
<RefCountable
> provide_ref_counted() { return Ref
<RefCountable
>{}; }
25 void consume_ref_counted(Ref
<RefCountable
>) {}
28 consume_refcntbl(provide_ref_counted().get());
35 void consume_ptr(RefCountable
* ptr
) {}
36 void consume_ref(const RefCountable
& ref
) {}
42 c
.consume_ptr(provide());
43 // expected-warning@-1{{Call argument for parameter 'ptr' is uncounted and unsafe}}
44 c
.consume_ref(*provide());
45 // expected-warning@-1{{Call argument for parameter 'ref' is uncounted and unsafe}}
50 void consume(RefCountable
*) { }
53 // expected-warning@-1{{Call argument is uncounted and unsafe}}
60 void consume(RefCountable
*) { }
62 this->consume(provide());
63 // expected-warning@-1{{Call argument is uncounted and unsafe}}
70 RefCountable
* downcast(RefCountable
*) { return nullptr; }
73 consume_refcntbl(provide());
74 // expected-warning@-1{{Call argument is uncounted and unsafe}}
76 consume_refcntbl(static_cast<RefCountable
*>(provide()));
77 // expected-warning@-1{{Call argument is uncounted and unsafe}}
79 consume_refcntbl(dynamic_cast<RefCountable
*>(provide()));
80 // expected-warning@-1{{Call argument is uncounted and unsafe}}
82 consume_refcntbl(const_cast<RefCountable
*>(provide()));
83 // expected-warning@-1{{Call argument is uncounted and unsafe}}
85 consume_refcntbl(reinterpret_cast<RefCountable
*>(provide()));
86 // expected-warning@-1{{Call argument is uncounted and unsafe}}
88 consume_refcntbl(downcast(provide()));
89 // expected-warning@-1{{Call argument is uncounted and unsafe}}
92 static_cast<RefCountable
*>(
94 static_cast<RefCountable
*>(
100 // expected-warning@-8{{Call argument is uncounted and unsafe}}
106 consume_refcntbl(nullptr);
111 namespace ref_counted_lookalike
{
113 RefCountable
* get() { return nullptr; }
119 consume_refcntbl(D
.get());
120 // expected-warning@-1{{Call argument is uncounted and unsafe}}
124 namespace Ref_to_reference_conversion_operator
{
125 template<typename T
> struct Ref
{
128 T
* get() { return nullptr; }
129 operator T
& () { return t
; }
133 void consume_ref(RefCountable
&) {}
136 Ref
<RefCountable
> bar
;
141 namespace param_formarding_function
{
142 void consume_ref_countable_ref(RefCountable
&) {}
143 void consume_ref_countable_ptr(RefCountable
*) {}
146 void foo(RefCountable
* param
) {
147 consume_ref_countable_ptr(param
);
152 void foo(RefCountable
& param
) {
153 consume_ref_countable_ref(param
);
157 namespace ref_deref_operators
{
158 void foo_ref(RefCountable
& param
) {
159 consume_ref_countable_ptr(¶m
);
162 void foo_ptr(RefCountable
* param
) {
163 consume_ref_countable_ref(*param
);
169 RefCountable
* downcast(RefCountable
*) { return nullptr; }
172 T
* bitwise_cast(T
*) { return nullptr; }
174 void foo(RefCountable
* param
) {
175 consume_ref_countable_ptr(downcast(param
));
176 consume_ref_countable_ptr(bitwise_cast(param
));
181 namespace param_formarding_lambda
{
182 auto consume_ref_countable_ref
= [](RefCountable
&) {};
183 auto consume_ref_countable_ptr
= [](RefCountable
*) {};
186 void foo(RefCountable
* param
) {
187 consume_ref_countable_ptr(param
);
192 void foo(RefCountable
& param
) {
193 consume_ref_countable_ref(param
);
197 namespace ref_deref_operators
{
198 void foo_ref(RefCountable
& param
) {
199 consume_ref_countable_ptr(¶m
);
202 void foo_ptr(RefCountable
* param
) {
203 consume_ref_countable_ref(*param
);
209 RefCountable
* downcast(RefCountable
*) { return nullptr; }
212 T
* bitwise_cast(T
*) { return nullptr; }
214 void foo(RefCountable
* param
) {
215 consume_ref_countable_ptr(downcast(param
));
216 consume_ref_countable_ptr(bitwise_cast(param
));
221 namespace param_forwarding_method
{
223 void consume_ref_countable_ref(RefCountable
&) {};
224 static void consume_ref_countable_ptr(RefCountable
*) {};
228 void foo(RefCountable
* param
) {
229 methodclass::consume_ref_countable_ptr(param
);
234 void foo(RefCountable
& param
) {
236 mc
.consume_ref_countable_ref(param
);
240 namespace ref_deref_operators
{
241 void foo_ref(RefCountable
& param
) {
242 methodclass::consume_ref_countable_ptr(¶m
);
245 void foo_ptr(RefCountable
* param
) {
247 mc
.consume_ref_countable_ref(*param
);
253 RefCountable
* downcast(RefCountable
*) { return nullptr; }
256 T
* bitwise_cast(T
*) { return nullptr; }
258 void foo(RefCountable
* param
) {
259 methodclass::consume_ref_countable_ptr(downcast(param
));
260 methodclass::consume_ref_countable_ptr(bitwise_cast(param
));
266 void consume_ref_countable(RefCountable
*) {}
267 RefCountable
* downcast(RefCountable
*) { return nullptr; }
270 RefPtr
<RefCountable
> bar
;
271 consume_ref_countable( downcast(bar
.get()) );
275 namespace string_impl
{
277 RefCountable
* impl() { return nullptr; }
282 RefCountable
& impl() { return rc
; }
285 void consume_ptr(RefCountable
*) {}
286 void consume_ref(RefCountable
&) {}
292 consume_ptr(s
.impl());
293 consume_ref(as
.impl());
298 namespace default_arg
{
299 RefCountable
* global
;
301 void function_with_default_arg(RefCountable
* param
= global
) {}
302 // expected-warning@-1{{Call argument for parameter 'param' is uncounted and unsafe}}
305 function_with_default_arg();
309 namespace cxx_member_operator_call
{
310 // The hidden this-pointer argument without a corresponding parameter caused couple bugs in parameter <-> argument attribution.
312 Foo
& operator+(RefCountable
* bad
) { return *this; }
313 friend Foo
& operator-(Foo
& lhs
, RefCountable
* bad
) { return lhs
; }
314 void operator()(RefCountable
* bad
) { }
317 RefCountable
* global
;
322 // expected-warning@-1{{Call argument for parameter 'bad' is uncounted and unsafe}}
324 // expected-warning@-1{{Call argument for parameter 'bad' is uncounted and unsafe}}
326 // expected-warning@-1{{Call argument for parameter 'bad' is uncounted and unsafe}}