lint: fix wrong 'statement not reached' in do-while loop

This commit is contained in:
rillig 2021-03-21 11:48:04 +00:00
parent 299565f1d9
commit 85a09d20fa
3 changed files with 11 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: msg_217.c,v 1.4 2021/02/21 09:17:55 rillig Exp $ */
/* $NetBSD: msg_217.c,v 1.5 2021/03/21 11:48:04 rillig Exp $ */
# 3 "msg_217.c"
// Test for message: function %s falls off bottom without returning value [217]
@ -19,16 +19,17 @@ random(int n)
* Seen in external/bsd/libevent/dist/event_tagging.c, function
* encode_int_internal.
*
* As of 2021-01-31, lint wrongly reports that the function would fall off
* the bottom, but it cannot reach the bottom since every path contains the
* 'return i'.
* Before tree.c 1.243 from 2021-03-21, lint wrongly reported that the
* 'while 0' was unreachable. This has been fixed by allowing the 'while 0'
* in a do-while-false loop to be unreachable. The same could be useful for a
* do-while-true.
*/
int
do_while_return(int i)
{
do {
return i;
} while (/*CONSTCOND*/0); /*FIXME*//* expect: 193 */
} while (0);
} /*FIXME*//* expect: 217 */
/*

View File

@ -1,3 +1,2 @@
msg_217.c(11): warning: function random falls off bottom without returning value [217]
msg_217.c(31): warning: statement not reached [193]
msg_217.c(32): warning: function do_while_return falls off bottom without returning value [217]
msg_217.c(33): warning: function do_while_return falls off bottom without returning value [217]

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.242 2021/03/20 21:08:09 rillig Exp $ */
/* $NetBSD: tree.c,v 1.243 2021/03/21 11:48:04 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: tree.c,v 1.242 2021/03/20 21:08:09 rillig Exp $");
__RCSID("$NetBSD: tree.c,v 1.243 2021/03/21 11:48:04 rillig Exp $");
#endif
#include <float.h>
@ -3777,7 +3777,8 @@ expr(tnode_t *tn, bool vctx, bool tctx, bool dofreeblk, bool constcond_false_ok)
}
/* expr() is also called in global initializations */
if (dcs->d_ctx != EXTERN)
/* TODO: rename constcond_false_ok */
if (dcs->d_ctx != EXTERN && !constcond_false_ok)
check_statement_reachable();
check_expr_misc(tn, vctx, tctx, !tctx, false, false, false);