David Blaikie | 2dd52e3 | 2012-01-24 05:34:08 +0000 | [diff] [blame] | 1 | // 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 Carruth | 00e9cbb | 2010-05-17 23:51:52 +0000 | [diff] [blame] | 3 | |
Ted Kremenek | 8b3b3db | 2011-01-25 22:57:41 +0000 | [diff] [blame] | 4 | // A destructor may be marked noreturn and should still influence the CFG. |
Ted Kremenek | c9f8f5a | 2011-03-02 20:32:29 +0000 | [diff] [blame] | 5 | void pr6884_abort() __attribute__((noreturn)); |
Chandler Carruth | 00e9cbb | 2010-05-17 23:51:52 +0000 | [diff] [blame] | 6 | |
Ted Kremenek | c9f8f5a | 2011-03-02 20:32:29 +0000 | [diff] [blame] | 7 | struct pr6884_abort_struct { |
| 8 | pr6884_abort_struct() {} |
| 9 | ~pr6884_abort_struct() __attribute__((noreturn)) { pr6884_abort(); } |
| 10 | }; |
Ted Kremenek | 8b3b3db | 2011-01-25 22:57:41 +0000 | [diff] [blame] | 11 | |
Chandler Carruth | c8cfc74 | 2011-09-13 06:09:01 +0000 | [diff] [blame] | 12 | struct other { ~other() {} }; |
| 13 | |
Chandler Carruth | a1364be | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 14 | // 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. |
| 17 | namespace 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 Kremenek | c9f8f5a | 2011-03-02 20:32:29 +0000 | [diff] [blame] | 42 | |
Chandler Carruth | c8cfc74 | 2011-09-13 06:09:01 +0000 | [diff] [blame] | 43 | // 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 Carruth | a1364be | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 86 | switch (x) { default: { pr6884_abort_struct a; } } |
Ted Kremenek | 8b3b3db | 2011-01-25 22:57:41 +0000 | [diff] [blame] | 87 | } |
Chandler Carruth | c8cfc74 | 2011-09-13 06:09:01 +0000 | [diff] [blame] | 88 | 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 Kremenek | 8b3b3db | 2011-01-25 22:57:41 +0000 | [diff] [blame] | 100 | } |
Ted Kremenek | 697d42d | 2011-03-03 01:01:03 +0000 | [diff] [blame] | 101 | |
| 102 | // PR9380 |
| 103 | struct PR9380 { |
| 104 | ~PR9380(); |
| 105 | }; |
| 106 | struct PR9380_B : public PR9380 { |
| 107 | PR9380_B( const PR9380& str ); |
| 108 | }; |
| 109 | void test_PR9380(const PR9380& aKey) { |
| 110 | const PR9380& flatKey = PR9380_B(aKey); |
| 111 | } |
| 112 | |
Ted Kremenek | c5aff44 | 2011-03-03 01:21:32 +0000 | [diff] [blame] | 113 | // Array of objects with destructors. This is purely a coverage test case. |
| 114 | void test_array() { |
| 115 | PR9380 a[2]; |
| 116 | } |
Ted Kremenek | 9ca957a | 2011-03-03 17:07:11 +0000 | [diff] [blame] | 117 | |
| 118 | // Test classes wrapped in typedefs. This is purely a coverage test case |
| 119 | // for CFGImplictDtor::getDestructorDecl(). |
| 120 | void test_typedefs() { |
| 121 | typedef PR9380 PR9380_Ty; |
| 122 | PR9380_Ty test; |
| 123 | PR9380_Ty test2[20]; |
| 124 | } |
| 125 | |
Ted Kremenek | 6e40035 | 2011-03-07 22:04:39 +0000 | [diff] [blame] | 126 | // PR9412 - Handle CFG traversal with null successors. |
| 127 | enum PR9412_MatchType { PR9412_Exact }; |
| 128 | |
| 129 | template <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 | |
| 137 | void PR9412_f() { |
| 138 | PR9412_t<PR9412_Exact>(); // expected-note {{in instantiation of function template specialization 'PR9412_t<0>' requested here}} |
| 139 | } |
| 140 | |