Mike Stump | 4617191 | 2010-01-23 20:12:18 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn -Wno-unreachable-code |
Mike Stump | 4d9d51a | 2009-07-28 23:11:12 +0000 | [diff] [blame] | 2 | |
| 3 | int j; |
Chandler Carruth | b0656ec | 2011-08-31 09:01:53 +0000 | [diff] [blame] | 4 | void test1() { // expected-warning {{function 'test1' could be declared with attribute 'noreturn'}} |
| 5 | ^ (void) { while (1) { } }(); // expected-warning {{block could be declared with attribute 'noreturn'}} |
Mike Stump | 4d9d51a | 2009-07-28 23:11:12 +0000 | [diff] [blame] | 6 | ^ (void) { if (j) while (1) { } }(); |
| 7 | while (1) { } |
| 8 | } |
| 9 | |
| 10 | void test2() { |
| 11 | if (j) while (1) { } |
| 12 | } |
Ted Kremenek | f679a98 | 2009-09-26 03:48:56 +0000 | [diff] [blame] | 13 | |
Ted Kremenek | e7c9645 | 2009-09-26 03:54:06 +0000 | [diff] [blame] | 14 | __attribute__((__noreturn__)) |
| 15 | void test2_positive() { |
| 16 | if (j) while (1) { } |
| 17 | } // expected-warning{{function declared 'noreturn' should not return}} |
| 18 | |
| 19 | |
Ted Kremenek | f679a98 | 2009-09-26 03:48:56 +0000 | [diff] [blame] | 20 | // This test case illustrates that we don't warn about the missing return |
| 21 | // because the function is marked noreturn and there is an infinite loop. |
| 22 | extern int foo_test_3(); |
Anders Carlsson | 5d1d7ae | 2010-09-03 00:25:02 +0000 | [diff] [blame] | 23 | __attribute__((__noreturn__)) void* test3(int arg) { |
Ted Kremenek | f679a98 | 2009-09-26 03:48:56 +0000 | [diff] [blame] | 24 | while (1) foo_test_3(); |
| 25 | } |
| 26 | |
Anders Carlsson | 5d1d7ae | 2010-09-03 00:25:02 +0000 | [diff] [blame] | 27 | __attribute__((__noreturn__)) void* test3_positive(int arg) { |
Ted Kremenek | f679a98 | 2009-09-26 03:48:56 +0000 | [diff] [blame] | 28 | while (0) foo_test_3(); |
| 29 | } // expected-warning{{function declared 'noreturn' should not return}} |
Chris Lattner | 7a128e8 | 2009-10-25 22:43:07 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | // PR5298 - -Wmissing-noreturn shouldn't warn if the function is already |
| 33 | // declared noreturn. |
| 34 | void __attribute__((noreturn)) |
| 35 | test4() { |
| 36 | test2_positive(); |
| 37 | } |