msg_217.c revision 1.12 1 /* $NetBSD: msg_217.c,v 1.12 2023/07/07 19:45:22 rillig Exp $ */
2 # 3 "msg_217.c"
3
4 // Test for message: function '%s' falls off bottom without returning value [217]
5
6 /* lint1-extra-flags: -X 351 */
7
8 int
9 random(int n)
10 {
11 if (n < 0)
12 return -3;
13 }
14 /* expect-1: warning: function 'random' falls off bottom without returning value [217] */
15
16 /*
17 * The pattern 'do { } while (0)' is often used in statement macros.
18 * Putting a 'return' at the end of such a macro is legitimate, the embracing
19 * 'do { } while (0)' is probably there to conform to a coding standard or
20 * to otherwise reduce confusion.
21 *
22 * Seen in external/bsd/libevent/dist/event_tagging.c, function
23 * encode_int_internal.
24 *
25 * Before tree.c 1.243 from 2021-03-21, lint wrongly reported that the
26 * 'while 0' was unreachable. This has been fixed by allowing the 'while 0'
27 * in a do-while-false loop to be unreachable. The same could be useful for a
28 * do-while-true.
29 *
30 * Before func.c 1.83 from 2021-03-21, lint wrongly reported that the function
31 * would fall off the bottom.
32 */
33 int
34 do_while_return(int i)
35 {
36 do {
37 return i;
38 } while (0);
39 }
40
41 /*
42 * C99 5.1.2.2.3 "Program termination" p1 defines that as a special exception,
43 * the function 'main' does not have to return a value, reaching the bottom
44 * is equivalent to returning 0.
45 *
46 * Before func.c 1.72 from 2021-02-21, lint had wrongly warned about this.
47 */
48 int
49 main(void)
50 {
51 }
52
53 int
54 reachable_continue_leads_to_endless_loop(void)
55 {
56 for (;;) {
57 if (1)
58 continue;
59 break;
60 }
61 }
62
63 int
64 unreachable_continue_falls_through(void)
65 {
66 for (;;) {
67 if (0)
68 /* expect+1: warning: statement not reached [193] */
69 continue;
70 break;
71 }
72 }
73 /* expect-1: warning: function 'unreachable_continue_falls_through' falls off bottom without returning value [217] */
74