blob: 448fce77cd858dcb37e59df365e11dec819ac1cd [file] [log] [blame]
Mike Stump46171912010-01-23 20:12:18 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn -Wno-unreachable-code
Mike Stump4d9d51a2009-07-28 23:11:12 +00002
3int j;
Chandler Carruthb0656ec2011-08-31 09:01:53 +00004void 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 Stump4d9d51a2009-07-28 23:11:12 +00006 ^ (void) { if (j) while (1) { } }();
7 while (1) { }
8}
9
10void test2() {
11 if (j) while (1) { }
12}
Ted Kremenekf679a982009-09-26 03:48:56 +000013
Ted Kremeneke7c96452009-09-26 03:54:06 +000014__attribute__((__noreturn__))
15void test2_positive() {
16 if (j) while (1) { }
17} // expected-warning{{function declared 'noreturn' should not return}}
18
19
Ted Kremenekf679a982009-09-26 03:48:56 +000020// 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.
22extern int foo_test_3();
Anders Carlsson5d1d7ae2010-09-03 00:25:02 +000023__attribute__((__noreturn__)) void* test3(int arg) {
Ted Kremenekf679a982009-09-26 03:48:56 +000024 while (1) foo_test_3();
25}
26
Anders Carlsson5d1d7ae2010-09-03 00:25:02 +000027__attribute__((__noreturn__)) void* test3_positive(int arg) {
Ted Kremenekf679a982009-09-26 03:48:56 +000028 while (0) foo_test_3();
29} // expected-warning{{function declared 'noreturn' should not return}}
Chris Lattner7a128e82009-10-25 22:43:07 +000030
31
32// PR5298 - -Wmissing-noreturn shouldn't warn if the function is already
33// declared noreturn.
34void __attribute__((noreturn))
35test4() {
36 test2_positive();
37}