Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: fix wrong warning about main falli...
details: https://anonhg.NetBSD.org/src/rev/803439c7c957
branches: trunk
changeset: 959654:803439c7c957
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Feb 21 09:17:55 2021 +0000
description:
lint: fix wrong warning about main falling off the bottom in C99 mode
This gets lint a small step closer to implementing C99.
diffstat:
tests/usr.bin/xlint/lint1/d_cvt_constant.c | 6 ++----
tests/usr.bin/xlint/lint1/d_cvt_constant.exp | 1 -
tests/usr.bin/xlint/lint1/msg_217.c | 14 +++++++++++++-
usr.bin/xlint/lint1/func.c | 26 +++++++++++++++++++-------
4 files changed, 34 insertions(+), 13 deletions(-)
diffs (102 lines):
diff -r 2bb336d237cf -r 803439c7c957 tests/usr.bin/xlint/lint1/d_cvt_constant.c
--- a/tests/usr.bin/xlint/lint1/d_cvt_constant.c Sun Feb 21 09:07:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_cvt_constant.c Sun Feb 21 09:17:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: d_cvt_constant.c,v 1.4 2021/02/21 09:07:58 rillig Exp $ */
+/* $NetBSD: d_cvt_constant.c,v 1.5 2021/02/21 09:17:55 rillig Exp $ */
# 3 "d_cvt_constant.c"
/* the second assignment assumes failed before */
@@ -9,6 +9,4 @@
int foo = 0;
if (foo)
x = 1;
-} /* expect: 217 */
-// FIXME: Since C99, main may fall off the bottom without returning a value.
-// Therefore there should be no warning 217.
+}
diff -r 2bb336d237cf -r 803439c7c957 tests/usr.bin/xlint/lint1/d_cvt_constant.exp
--- a/tests/usr.bin/xlint/lint1/d_cvt_constant.exp Sun Feb 21 09:07:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_cvt_constant.exp Sun Feb 21 09:17:55 2021 +0000
@@ -1,2 +1,1 @@
d_cvt_constant.c(8): warning: x set but not used in function main [191]
-d_cvt_constant.c(12): warning: function main falls off bottom without returning value [217]
diff -r 2bb336d237cf -r 803439c7c957 tests/usr.bin/xlint/lint1/msg_217.c
--- a/tests/usr.bin/xlint/lint1/msg_217.c Sun Feb 21 09:07:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_217.c Sun Feb 21 09:17:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_217.c,v 1.3 2021/01/31 13:33:10 rillig Exp $ */
+/* $NetBSD: msg_217.c,v 1.4 2021/02/21 09:17:55 rillig Exp $ */
# 3 "msg_217.c"
// Test for message: function %s falls off bottom without returning value [217]
@@ -30,3 +30,15 @@
return i;
} while (/*CONSTCOND*/0); /*FIXME*//* expect: 193 */
} /*FIXME*//* expect: 217 */
+
+/*
+ * C99 5.1.2.2.3 "Program termination" p1 defines that as a special exception,
+ * the function 'main' does not have to return a value, reaching the bottom
+ * is equivalent to returning 0.
+ *
+ * Before func.c 1.72 from 2021-02-21, lint had wrongly warned about this.
+ */
+int
+main(void)
+{
+}
diff -r 2bb336d237cf -r 803439c7c957 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c Sun Feb 21 09:07:58 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c Sun Feb 21 09:17:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.71 2021/02/19 22:27:49 rillig Exp $ */
+/* $NetBSD: func.c,v 1.72 2021/02/21 09:17:55 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.71 2021/02/19 22:27:49 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.72 2021/02/21 09:17:55 rillig Exp $");
#endif
#include <stdlib.h>
@@ -337,6 +337,22 @@
reached = true;
}
+static void
+check_missing_return_value(void)
+{
+ if (funcsym->s_type->t_subt->t_tspec == VOID)
+ return;
+ if (funcsym->s_return_type_implicit_int)
+ return;
+
+ /* C99 5.1.2.2.3 "Program termination" p1 */
+ if (Sflag && strcmp(funcsym->s_name, "main") == 0)
+ return;
+
+ /* function %s falls off bottom without returning value */
+ warning(217, funcsym->s_name);
+}
+
/*
* Called at the end of a function definition.
*/
@@ -348,11 +364,7 @@
if (reached) {
cstmt->c_had_return_noval = true;
- if (funcsym->s_type->t_subt->t_tspec != VOID &&
- !funcsym->s_return_type_implicit_int) {
- /* func. %s falls off bottom without returning value */
- warning(217, funcsym->s_name);
- }
+ check_missing_return_value();
}
/*
Home |
Main Index |
Thread Index |
Old Index