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