blob: 617de0089585d3d35e6b6bbf4e25d84809b349eb [file] [log] [blame]
David Blaikie2dd52e32012-01-24 05:34:08 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify -Wreturn-type -Wmissing-noreturn -Wno-unreachable-code -Wno-covered-switch-default
2// RUN: %clang_cc1 %s -fsyntax-only -std=c++11 -verify -Wreturn-type -Wmissing-noreturn -Wno-unreachable-code -Wno-covered-switch-default
Chandler Carruth00e9cbb2010-05-17 23:51:52 +00003
Ted Kremenek8b3b3db2011-01-25 22:57:41 +00004// A destructor may be marked noreturn and should still influence the CFG.
Ted Kremenekc9f8f5a2011-03-02 20:32:29 +00005void pr6884_abort() __attribute__((noreturn));
Chandler Carruth00e9cbb2010-05-17 23:51:52 +00006
Ted Kremenekc9f8f5a2011-03-02 20:32:29 +00007struct pr6884_abort_struct {
8 pr6884_abort_struct() {}
9 ~pr6884_abort_struct() __attribute__((noreturn)) { pr6884_abort(); }
10};
Ted Kremenek8b3b3db2011-01-25 22:57:41 +000011
Chandler Carruthc8cfc742011-09-13 06:09:01 +000012struct other { ~other() {} };
13
Chandler Carrutha1364be2011-09-10 00:02:34 +000014// Ensure that destructors from objects are properly modeled in the CFG despite
15// the presence of switches, case statements, labels, and blocks. These tests
16// try to cover bugs reported in both PR6884 and PR10063.
17namespace abort_struct_complex_cfgs {
18 int basic(int x) {
19 switch (x) { default: pr6884_abort(); }
20 }
21 int f1(int x) {
22 switch (x) default: pr6884_abort_struct();
23 }
24 int f2(int x) {
25 switch (x) { default: pr6884_abort_struct(); }
26 }
27 int f2_positive(int x) {
28 switch (x) { default: ; }
29 } // expected-warning {{control reaches end of non-void function}}
30 int f3(int x) {
31 switch (x) { default: { pr6884_abort_struct(); } }
32 }
33 int f4(int x) {
34 switch (x) default: L1: L2: case 4: pr6884_abort_struct();
35 }
36 int f5(int x) {
37 switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); }
38 }
39 int f6(int x) {
40 switch (x) default: L1: L2: case 4: { pr6884_abort_struct(); }
41 }
Ted Kremenekc9f8f5a2011-03-02 20:32:29 +000042
Chandler Carruthc8cfc742011-09-13 06:09:01 +000043 // Test that these constructs work even when extraneous blocks are created
44 // before and after the switch due to implicit destructors.
45 int g1(int x) {
46 other o;
47 switch (x) default: pr6884_abort_struct();
48 }
49 int g2(int x) {
50 other o;
51 switch (x) { default: pr6884_abort_struct(); }
52 }
53 int g2_positive(int x) {
54 other o;
55 switch (x) { default: ; }
56 } // expected-warning {{control reaches end of non-void function}}
57 int g3(int x) {
58 other o;
59 switch (x) { default: { pr6884_abort_struct(); } }
60 }
61 int g4(int x) {
62 other o;
63 switch (x) default: L1: L2: case 4: pr6884_abort_struct();
64 }
65 int g5(int x) {
66 other o;
67 switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); }
68 }
69 int g6(int x) {
70 other o;
71 switch (x) default: L1: L2: case 4: { pr6884_abort_struct(); }
72 }
73
74 // Test that these constructs work even with variables carrying the no-return
75 // destructor instead of temporaries.
76 int h1(int x) {
77 other o;
78 switch (x) default: pr6884_abort_struct a;
79 }
80 int h2(int x) {
81 other o;
82 switch (x) { default: pr6884_abort_struct a; }
83 }
84 int h3(int x) {
85 other o;
Chandler Carrutha1364be2011-09-10 00:02:34 +000086 switch (x) { default: { pr6884_abort_struct a; } }
Ted Kremenek8b3b3db2011-01-25 22:57:41 +000087 }
Chandler Carruthc8cfc742011-09-13 06:09:01 +000088 int h4(int x) {
89 other o;
90 switch (x) default: L1: L2: case 4: pr6884_abort_struct a;
91 }
92 int h5(int x) {
93 other o;
94 switch (x) default: L1: { L2: case 4: pr6884_abort_struct a; }
95 }
96 int h6(int x) {
97 other o;
98 switch (x) default: L1: L2: case 4: { pr6884_abort_struct a; }
99 }
Ted Kremenek8b3b3db2011-01-25 22:57:41 +0000100}
Ted Kremenek697d42d2011-03-03 01:01:03 +0000101
102// PR9380
103struct PR9380 {
104 ~PR9380();
105};
106struct PR9380_B : public PR9380 {
107 PR9380_B( const PR9380& str );
108};
109void test_PR9380(const PR9380& aKey) {
110 const PR9380& flatKey = PR9380_B(aKey);
111}
112
Ted Kremenekc5aff442011-03-03 01:21:32 +0000113// Array of objects with destructors. This is purely a coverage test case.
114void test_array() {
115 PR9380 a[2];
116}
Ted Kremenek9ca957a2011-03-03 17:07:11 +0000117
118// Test classes wrapped in typedefs. This is purely a coverage test case
119// for CFGImplictDtor::getDestructorDecl().
120void test_typedefs() {
121 typedef PR9380 PR9380_Ty;
122 PR9380_Ty test;
123 PR9380_Ty test2[20];
124}
125
Ted Kremenek6e400352011-03-07 22:04:39 +0000126// PR9412 - Handle CFG traversal with null successors.
127enum PR9412_MatchType { PR9412_Exact };
128
129template <PR9412_MatchType type> int PR9412_t() {
130 switch (type) {
131 case PR9412_Exact:
132 default:
133 break;
134 }
135} // expected-warning {{control reaches end of non-void function}}
136
137void PR9412_f() {
138 PR9412_t<PR9412_Exact>(); // expected-note {{in instantiation of function template specialization 'PR9412_t<0>' requested here}}
139}
140