blob: 45f750688f422226f49e374df3a299fb7ac924bf [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -warn-dead-stores -verify %s
2// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -warn-dead-stores -verify %s
3// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -warn-dead-stores -verify %s
4// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -warn-dead-stores -verify %s
5// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -warn-dead-stores -verify %s
Mike Stump0979d802009-07-22 22:56:04 +00006
Ted Kremenek43f19e32009-12-15 04:12:12 +00007//===----------------------------------------------------------------------===//
8// Basic dead store checking (but in C++ mode).
9//===----------------------------------------------------------------------===//
10
Mike Stump0979d802009-07-22 22:56:04 +000011int j;
Ted Kremenek852274d2009-12-16 03:18:58 +000012void test1() {
Mike Stump0979d802009-07-22 22:56:04 +000013 int x = 4;
14
15 ++x; // expected-warning{{never read}}
16
17 switch (j) {
18 case 1:
19 throw 1;
20 (void)x;
21 break;
22 }
23}
Ted Kremenek43f19e32009-12-15 04:12:12 +000024
25//===----------------------------------------------------------------------===//
26// Dead store checking involving constructors.
27//===----------------------------------------------------------------------===//
28
Ted Kremenek852274d2009-12-16 03:18:58 +000029class Test2 {
Ted Kremenek43f19e32009-12-15 04:12:12 +000030 int &x;
31public:
Ted Kremenek852274d2009-12-16 03:18:58 +000032 Test2(int &y) : x(y) {}
33 ~Test2() { ++x; }
Ted Kremenek43f19e32009-12-15 04:12:12 +000034};
35
Ted Kremenek852274d2009-12-16 03:18:58 +000036int test2(int x) {
37 { Test2 a(x); } // no-warning
Ted Kremenek43f19e32009-12-15 04:12:12 +000038 return x;
39}
Ted Kremenek852274d2009-12-16 03:18:58 +000040
41//===----------------------------------------------------------------------===//
42// Test references.
43//===----------------------------------------------------------------------===//
44
45void test3_a(int x) {
46 ++x; // expected-warning{{never read}}
47}
48
49void test3_b(int &x) {
50 ++x; // no-warninge
51}
52
53void test3_c(int x) {
54 int &y = x;
55 // Shows the limitation of dead stores tracking. The write is really
56 // dead since the value cannot escape the function.
57 ++y; // no-warning
58}
59
60void test3_d(int &x) {
61 int &y = x;
62 ++y; // no-warning
63}
64
65void test3_e(int &x) {
66 int &y = x;
67}
68