1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedLocalVarsChecker -verify %s
#include "mock-types.h"
namespace raw_ptr {
void foo() {
RefCountable *bar;
// FIXME: later on we might warn on uninitialized vars too
}
void bar(RefCountable *) {}
} // namespace raw_ptr
namespace reference {
void foo_ref() {
RefCountable automatic;
RefCountable &bar = automatic;
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
}
void bar_ref(RefCountable &) {}
} // namespace reference
namespace guardian_scopes {
void foo1() {
RefPtr<RefCountable> foo;
{ RefCountable *bar = foo.get(); }
}
void foo2() {
RefPtr<RefCountable> foo;
// missing embedded scope here
RefCountable *bar = foo.get();
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
}
void foo3() {
RefPtr<RefCountable> foo;
{
{ RefCountable *bar = foo.get(); }
}
}
void foo4() {
{
RefPtr<RefCountable> foo;
{ RefCountable *bar = foo.get(); }
}
}
} // namespace guardian_scopes
namespace auto_keyword {
class Foo {
RefCountable *provide_ref_ctnbl() { return nullptr; }
void evil_func() {
RefCountable *bar = provide_ref_ctnbl();
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
auto *baz = provide_ref_ctnbl();
// expected-warning@-1{{Local variable 'baz' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
auto *baz2 = this->provide_ref_ctnbl();
// expected-warning@-1{{Local variable 'baz2' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
}
};
} // namespace auto_keyword
namespace guardian_casts {
void foo1() {
RefPtr<RefCountable> foo;
{ RefCountable *bar = downcast<RefCountable>(foo.get()); }
}
void foo2() {
RefPtr<RefCountable> foo;
{
RefCountable *bar =
static_cast<RefCountable *>(downcast<RefCountable>(foo.get()));
}
}
} // namespace guardian_casts
namespace guardian_ref_conversion_operator {
void foo() {
Ref<RefCountable> rc;
{ RefCountable &rr = rc; }
}
} // namespace guardian_ref_conversion_operator
namespace ignore_for_if {
RefCountable *provide_ref_ctnbl() { return nullptr; }
void foo() {
// no warnings
if (RefCountable *a = provide_ref_ctnbl()) { }
for (RefCountable *a = provide_ref_ctnbl(); a != nullptr;) { }
RefCountable *array[1];
for (RefCountable *a : array) { }
}
} // namespace ignore_for_if
|