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