| 1 |
// RUN: %clang_cc1 -fsyntax-only %s -verify |
| 2 |
|
| 3 |
[[noreturn]] extern void noret(); |
| 4 |
[[noreturn]] extern void noret2(); |
| 5 |
extern void ordinary(); |
| 6 |
|
| 7 |
typedef void (*func_type)(void); |
| 8 |
|
| 9 |
// Constant initialization. |
| 10 |
|
| 11 |
void (* const const_fptr)() = noret; |
| 12 |
[[noreturn]] void test_global_const() { |
| 13 |
const_fptr(); |
| 14 |
} |
| 15 |
|
| 16 |
const func_type const_fptr_cast = (func_type)noret2; |
| 17 |
[[noreturn]] void test_global_cast() { |
| 18 |
const_fptr_cast(); |
| 19 |
} |
| 20 |
|
| 21 |
void (* const const_fptr_list)() = {noret}; |
| 22 |
[[noreturn]] void test_global_list() { |
| 23 |
const_fptr_list(); |
| 24 |
} |
| 25 |
|
| 26 |
const func_type const_fptr_fcast = func_type(noret2); |
| 27 |
[[noreturn]] void test_global_fcast() { |
| 28 |
const_fptr_fcast(); |
| 29 |
} |
| 30 |
|
| 31 |
[[noreturn]] void test_local_const() { |
| 32 |
void (* const fptr)() = noret; |
| 33 |
fptr(); |
| 34 |
} |
| 35 |
|
| 36 |
// Global variable assignment. |
| 37 |
void (*global_fptr)() = noret; |
| 38 |
|
| 39 |
[[noreturn]] void test_global_noassign() { |
| 40 |
global_fptr(); |
| 41 |
} // expected-warning {{function declared 'noreturn' should not return}} |
| 42 |
|
| 43 |
[[noreturn]] void test_global_assign() { |
| 44 |
global_fptr = noret; |
| 45 |
global_fptr(); |
| 46 |
} // expected-warning {{function declared 'noreturn' should not return}} |
| 47 |
|
| 48 |
// Local variable assignment. |
| 49 |
|
| 50 |
[[noreturn]] void test_init() { |
| 51 |
func_type func_ptr = noret; |
| 52 |
func_ptr(); |
| 53 |
} |
| 54 |
|
| 55 |
[[noreturn]] void test_assign() { |
| 56 |
void (*func_ptr)(void); |
| 57 |
func_ptr = noret; |
| 58 |
func_ptr(); |
| 59 |
} |
| 60 |
|
| 61 |
[[noreturn]] void test_override() { |
| 62 |
func_type func_ptr; |
| 63 |
func_ptr = ordinary; |
| 64 |
func_ptr = noret; |
| 65 |
func_ptr(); |
| 66 |
} |
| 67 |
|
| 68 |
[[noreturn]] void test_if_all(int x) { |
| 69 |
func_type func_ptr; |
| 70 |
if (x > 0) |
| 71 |
func_ptr = noret; |
| 72 |
else |
| 73 |
func_ptr = noret2; |
| 74 |
func_ptr(); |
| 75 |
} |
| 76 |
|
| 77 |
[[noreturn]] void test_if_mix(int x) { |
| 78 |
func_type func_ptr; |
| 79 |
if (x > 0) |
| 80 |
func_ptr = noret; |
| 81 |
else |
| 82 |
func_ptr = ordinary; |
| 83 |
func_ptr(); |
| 84 |
} // expected-warning {{function declared 'noreturn' should not return}} |
| 85 |
|
| 86 |
[[noreturn]] void test_if_opt(int x) { |
| 87 |
func_type func_ptr = noret; |
| 88 |
if (x > 0) |
| 89 |
func_ptr = ordinary; |
| 90 |
func_ptr(); |
| 91 |
} // expected-warning {{function declared 'noreturn' should not return}} |
| 92 |
|
| 93 |
[[noreturn]] void test_if_opt2(int x) { |
| 94 |
func_type func_ptr = ordinary; |
| 95 |
if (x > 0) |
| 96 |
func_ptr = noret; |
| 97 |
func_ptr(); |
| 98 |
} // expected-warning {{function declared 'noreturn' should not return}} |
| 99 |
|
| 100 |
[[noreturn]] void test_if_nest_all(int x, int y) { |
| 101 |
func_type func_ptr; |
| 102 |
if (x > 0) { |
| 103 |
if (y > 0) |
| 104 |
func_ptr = noret; |
| 105 |
else |
| 106 |
func_ptr = noret2; |
| 107 |
} else { |
| 108 |
if (y < 0) |
| 109 |
func_ptr = noret2; |
| 110 |
else |
| 111 |
func_ptr = noret; |
| 112 |
} |
| 113 |
func_ptr(); |
| 114 |
} |
| 115 |
|
| 116 |
[[noreturn]] void test_if_nest_mix(int x, int y) { |
| 117 |
func_type func_ptr; |
| 118 |
if (x > 0) { |
| 119 |
if (y > 0) |
| 120 |
func_ptr = noret; |
| 121 |
else |
| 122 |
func_ptr = noret2; |
| 123 |
} else { |
| 124 |
if (y < 0) |
| 125 |
func_ptr = ordinary; |
| 126 |
else |
| 127 |
func_ptr = noret; |
| 128 |
} |
| 129 |
func_ptr(); |
| 130 |
} // expected-warning {{function declared 'noreturn' should not return}} |
| 131 |
|
| 132 |
[[noreturn]] void test_switch_all(int x) { |
| 133 |
func_type func_ptr; |
| 134 |
switch(x) { |
| 135 |
case 1: |
| 136 |
func_ptr = noret; |
| 137 |
break; |
| 138 |
default: |
| 139 |
func_ptr = noret2; |
| 140 |
break; |
| 141 |
} |
| 142 |
func_ptr(); |
| 143 |
} |
| 144 |
|
| 145 |
[[noreturn]] void test_switch_mix(int x) { |
| 146 |
func_type func_ptr; |
| 147 |
switch(x) { |
| 148 |
case 1: |
| 149 |
func_ptr = ordinary; |
| 150 |
break; |
| 151 |
default: |
| 152 |
func_ptr = noret; |
| 153 |
break; |
| 154 |
} |
| 155 |
func_ptr(); |
| 156 |
} // expected-warning {{function declared 'noreturn' should not return}} |
| 157 |
|
| 158 |
[[noreturn]] void test_switch_fall(int x) { |
| 159 |
func_type func_ptr; |
| 160 |
switch(x) { |
| 161 |
case 1: |
| 162 |
func_ptr = ordinary; |
| 163 |
default: |
| 164 |
func_ptr = noret; |
| 165 |
break; |
| 166 |
} |
| 167 |
func_ptr(); |
| 168 |
} |
| 169 |
|
| 170 |
[[noreturn]] void test_switch_all_nest(int x, int y) { |
| 171 |
func_type func_ptr; |
| 172 |
switch(x) { |
| 173 |
case 1: |
| 174 |
func_ptr = noret; |
| 175 |
break; |
| 176 |
default: |
| 177 |
if (y > 0) |
| 178 |
func_ptr = noret2; |
| 179 |
else |
| 180 |
func_ptr = noret; |
| 181 |
break; |
| 182 |
} |
| 183 |
func_ptr(); |
| 184 |
} |
| 185 |
|
| 186 |
[[noreturn]] void test_switch_mix_nest(int x, int y) { |
| 187 |
func_type func_ptr; |
| 188 |
switch(x) { |
| 189 |
case 1: |
| 190 |
func_ptr = noret; |
| 191 |
break; |
| 192 |
default: |
| 193 |
if (y > 0) |
| 194 |
func_ptr = noret2; |
| 195 |
else |
| 196 |
func_ptr = ordinary; |
| 197 |
break; |
| 198 |
} |
| 199 |
func_ptr(); |
| 200 |
} // expected-warning {{function declared 'noreturn' should not return}} |
| 201 |
|
| 202 |
// Function parameters. |
| 203 |
|
| 204 |
[[noreturn]] void test_param(void (*func_ptr)() = noret) { |
| 205 |
func_ptr(); |
| 206 |
} // expected-warning {{function declared 'noreturn' should not return}} |
| 207 |
|
| 208 |
[[noreturn]] void test_const_param(void (* const func_ptr)() = noret) { |
| 209 |
func_ptr(); |
| 210 |
} // expected-warning {{function declared 'noreturn' should not return}} |
| 211 |
|
| 212 |
// Escaped value. |
| 213 |
|
| 214 |
extern void abc_01(func_type &); |
| 215 |
extern void abc_02(func_type *); |
| 216 |
|
| 217 |
[[noreturn]] void test_escape_ref() { |
| 218 |
func_type func_ptr = noret; |
| 219 |
abc_01(func_ptr); |
| 220 |
func_ptr(); |
| 221 |
} // expected-warning {{function declared 'noreturn' should not return}} |
| 222 |
|
| 223 |
[[noreturn]] void test_escape_addr() { |
| 224 |
func_type func_ptr = noret; |
| 225 |
abc_02(&func_ptr); |
| 226 |
func_ptr(); |
| 227 |
} // expected-warning {{function declared 'noreturn' should not return}} |