Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / Checkers / WebKit / uncounted-local-vars.cpp
blob8694d5fb85b8b49e22ebe3eccee7f9ebd179c48a
1 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedLocalVarsChecker -verify %s
3 #include "mock-types.h"
5 namespace raw_ptr {
6 void foo() {
7 RefCountable *bar;
8 // FIXME: later on we might warn on uninitialized vars too
11 void bar(RefCountable *) {}
12 } // namespace raw_ptr
14 namespace reference {
15 void foo_ref() {
16 RefCountable automatic;
17 RefCountable &bar = automatic;
18 // expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
21 void bar_ref(RefCountable &) {}
22 } // namespace reference
24 namespace guardian_scopes {
25 void foo1() {
26 RefPtr<RefCountable> foo;
27 { RefCountable *bar = foo.get(); }
30 void foo2() {
31 RefPtr<RefCountable> foo;
32 // missing embedded scope here
33 RefCountable *bar = foo.get();
34 // expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
37 void foo3() {
38 RefPtr<RefCountable> foo;
40 { RefCountable *bar = foo.get(); }
44 void foo4() {
46 RefPtr<RefCountable> foo;
47 { RefCountable *bar = foo.get(); }
50 } // namespace guardian_scopes
52 namespace auto_keyword {
53 class Foo {
54 RefCountable *provide_ref_ctnbl() { return nullptr; }
56 void evil_func() {
57 RefCountable *bar = provide_ref_ctnbl();
58 // expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
59 auto *baz = provide_ref_ctnbl();
60 // expected-warning@-1{{Local variable 'baz' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
61 auto *baz2 = this->provide_ref_ctnbl();
62 // expected-warning@-1{{Local variable 'baz2' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
65 } // namespace auto_keyword
67 namespace guardian_casts {
68 void foo1() {
69 RefPtr<RefCountable> foo;
70 { RefCountable *bar = downcast<RefCountable>(foo.get()); }
73 void foo2() {
74 RefPtr<RefCountable> foo;
76 RefCountable *bar =
77 static_cast<RefCountable *>(downcast<RefCountable>(foo.get()));
80 } // namespace guardian_casts
82 namespace guardian_ref_conversion_operator {
83 void foo() {
84 Ref<RefCountable> rc;
85 { RefCountable &rr = rc; }
87 } // namespace guardian_ref_conversion_operator
89 namespace ignore_for_if {
90 RefCountable *provide_ref_ctnbl() { return nullptr; }
92 void foo() {
93 // no warnings
94 if (RefCountable *a = provide_ref_ctnbl()) { }
95 for (RefCountable *a = provide_ref_ctnbl(); a != nullptr;) { }
96 RefCountable *array[1];
97 for (RefCountable *a : array) { }
99 } // namespace ignore_for_if