1 // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-checker=core.DeadStores -verify -Wno-unreachable-code %s
2 // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -analyzer-checker=core.DeadStores -verify -Wno-unreachable-code %s
3 // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -analyzer-checker=core.DeadStores -verify -Wno-unreachable-code %s
4 // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -analyzer-checker=core.DeadStores -verify -Wno-unreachable-code %s
5 // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-checker=core.DeadStores -verify -Wno-unreachable-code %s
7 //===----------------------------------------------------------------------===//
8 // Basic dead store checking (but in C++ mode).
9 //===----------------------------------------------------------------------===//
15 x
= x
+ 1; // expected-warning{{never read}}
25 //===----------------------------------------------------------------------===//
26 // Dead store checking involving constructors.
27 //===----------------------------------------------------------------------===//
32 Test2(int &y
) : x(y
) {}
37 { Test2
a(x
); } // no-warning
41 //===----------------------------------------------------------------------===//
42 // Dead store checking involving CXXTemporaryExprs
43 //===----------------------------------------------------------------------===//
46 template<typename _Tp
>
51 template<typename _Tp
, typename _Number2
> struct _Row_base
{
52 _Row_base(const pencil
<_Tp
>& x
) {}
54 template<typename _Tp
, typename _Number2
= TestTemp::pencil
<_Tp
> >
55 class row
: protected _Row_base
<_Tp
, _Number2
> {
56 typedef _Row_base
<_Tp
, _Number2
> _Base
;
57 typedef _Number2 pencil_type
;
59 explicit row(const pencil_type
& __a
= pencil_type()) : _Base(__a
) {}
64 TestTemp::row
<const char*> x
; // no-warning
67 //===----------------------------------------------------------------------===//
69 //===----------------------------------------------------------------------===//
72 x
= x
+ 1; // expected-warning{{never read}}
75 void test3_b(int &x
) {
76 x
= x
+ 1; // no-warninge
81 // Shows the limitation of dead stores tracking. The write is really
82 // dead since the value cannot escape the function.
86 void test3_d(int &x
) {
91 void test3_e(int &x
) {
95 //===----------------------------------------------------------------------===//
96 // Dead stores involving 'new'
97 //===----------------------------------------------------------------------===//
99 static void test_new(unsigned n
) {
100 char **p
= new char* [n
]; // expected-warning{{never read}}
103 //===----------------------------------------------------------------------===//
104 // Dead stores in namespaces.
105 //===----------------------------------------------------------------------===//
109 x
= 2; // expected-warning{{Value stored to 'x' is never read}}