[Heikki Kultala] This patch contains the ABI changes for the TCE target.
[clang.git] / test / Analysis / dead-stores.cpp
blobc384f9f5ec40f455dd7fb2b0db312fa21e7de0b4
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 //===----------------------------------------------------------------------===//
11 int j;
12 void test1() {
13 int x = 4;
15 x = x + 1; // expected-warning{{never read}}
17 switch (j) {
18 case 1:
19 throw 1;
20 (void)x;
21 break;
25 //===----------------------------------------------------------------------===//
26 // Dead store checking involving constructors.
27 //===----------------------------------------------------------------------===//
29 class Test2 {
30 int &x;
31 public:
32 Test2(int &y) : x(y) {}
33 ~Test2() { ++x; }
36 int test2(int x) {
37 { Test2 a(x); } // no-warning
38 return x;
41 //===----------------------------------------------------------------------===//
42 // Dead store checking involving CXXTemporaryExprs
43 //===----------------------------------------------------------------------===//
45 namespace TestTemp {
46 template<typename _Tp>
47 class pencil {
48 public:
49 ~pencil() throw() {}
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;
58 public:
59 explicit row(const pencil_type& __a = pencil_type()) : _Base(__a) {}
63 void test2_b() {
64 TestTemp::row<const char*> x; // no-warning
67 //===----------------------------------------------------------------------===//
68 // Test references.
69 //===----------------------------------------------------------------------===//
71 void test3_a(int x) {
72 x = x + 1; // expected-warning{{never read}}
75 void test3_b(int &x) {
76 x = x + 1; // no-warninge
79 void test3_c(int x) {
80 int &y = x;
81 // Shows the limitation of dead stores tracking. The write is really
82 // dead since the value cannot escape the function.
83 ++y; // no-warning
86 void test3_d(int &x) {
87 int &y = x;
88 ++y; // no-warning
91 void test3_e(int &x) {
92 int &y = 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 //===----------------------------------------------------------------------===//
107 namespace foo {
108 int test_4(int x) {
109 x = 2; // expected-warning{{Value stored to 'x' is never read}}
110 x = 2;
111 return x;