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