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