1 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -fsyntax-only -Wignored-qualifiers -Wno-error=return-type -verify -fblocks -Wno-unreachable-code -Wno-unused-value
3 // clang emits the following warning by default.
4 // With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the
7 return; // expected-warning {{non-void function 't14' should return a value}}
11 return 1; // expected-warning {{void function 't15' should not return a value}}
20 } // expected-warning {{control reaches end of non-void function}}
29 } // expected-warning {{control reaches end of non-void function}}
36 void halt2() __attribute__((noreturn));
51 int unknown_nohalt() {
57 } // expected-warning {{control reaches end of non-void function}}
60 (void)(1 + unknown());
61 } // expected-warning {{control reaches end of non-void function}}
63 int halt3() __attribute__((noreturn));
66 (void)(halt3() + unknown());
70 (void)(unknown() || halt3());
71 } // expected-warning {{control may reach end of non-void function}}
74 (void)(unknown() && halt3());
75 } // expected-warning {{control may reach end of non-void function}}
78 (void)(halt3() || unknown());
82 (void)(halt3() && unknown());
86 (void)(1 || unknown());
87 } // expected-warning {{control reaches end of non-void function}}
90 (void)(0 || unknown());
91 } // expected-warning {{control reaches end of non-void function}}
94 (void)(0 && unknown());
95 } // expected-warning {{control reaches end of non-void function}}
98 (void)(1 && unknown());
99 } // expected-warning {{control reaches end of non-void function}}
102 (void)(unknown_nohalt() && halt3());
103 } // expected-warning {{control may reach end of non-void function}}
106 (void)(unknown_nohalt() && unknown());
107 } // expected-warning {{control reaches end of non-void function}}
115 } // expected-warning {{control may reach end of non-void function}}
127 switch (i) default: ;
128 } // expected-warning {{control reaches end of non-void function}}
138 } // expected-warning {{control may reach end of non-void function}}
153 1 ? halt3() : unknown();
157 0 ? halt3() : unknown();
158 } // expected-warning {{control reaches end of non-void function}}
161 void (*fptr)() __attribute__((noreturn));
177 while (0) { goto done; }
180 while (1) { return 1; }
192 void test28() __attribute__((noreturn));
193 void test28(x) { while (1) { } }
200 // Include these declarations here explicitly so we don't depend on system headers.
201 typedef struct __jmp_buf_tag{} jmp_buf[1];
203 extern void longjmp (struct __jmp_buf_tag __env[1], int __val) __attribute__ ((noreturn));
204 extern void _longjmp (struct __jmp_buf_tag __env[1], int __val) __attribute__ ((noreturn));
210 longjmp(test30_j, 1);
212 #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
213 longjmp(test30_j, 2);
215 _longjmp(test30_j, 1);
219 typedef void test31_t(int status);
220 void test31(test31_t *callback __attribute__((noreturn)));
223 ^ (void) { while (1) { } }();
224 ^ (void) { if (j) while (1) { } }();
232 // Test that 'static inline' functions are only analyzed for CFG-based warnings
233 // when they are used.
234 static inline int si_has_missing_return() {} // expected-warning{{control reaches end of non-void function}}
235 static inline int si_has_missing_return_2() {}; // expected-warning{{control reaches end of non-void function}}
236 static inline int si_forward();
237 static inline int si_has_missing_return_3(int x) {
239 return si_has_missing_return_3(x+1);
240 } // expected-warning{{control may reach end of non-void function}}
242 int test_static_inline(int x) {
244 return x ? si_has_missing_return_2() : si_has_missing_return_3(x);
246 static inline int si_forward() {} // expected-warning{{control reaches end of non-void function}}
248 // Test warnings on ignored qualifiers on return types.
249 const int ignored_c_quals(); // expected-warning{{'const' type qualifier on return type has no effect}}
250 const volatile int ignored_cv_quals(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
251 char* const volatile restrict ignored_cvr_quals(); // expected-warning{{'const volatile restrict' type qualifiers on return type have no effect}}
253 typedef const int CI;
254 CI ignored_quals_typedef();
256 const CI ignored_quals_typedef_2(); // expected-warning{{'const' type qualifier}}
258 // Test that for switch(enum) that if the switch statement covers all the cases
259 // that we don't consider that for -Wreturn-type.
260 enum Cases { C1, C2, C3, C4 };
261 int test_enum_cases(enum Cases C) {
270 // PR12318 - Don't give a may reach end of non-void function warning.
274 } else if ( x == 2 || 1) {
287 void abort(void) __attribute__((noreturn));
288 #define av_assert0(cond) do {\
303 int PR19074_positive(int x) {
310 } // expected-warning {{control may reach end of non-void function}}
312 // sizeof(long) test.
314 if (sizeof(long) == 4)
316 if (sizeof(long) == 8)