Module Name: src
Committed By: rillig
Date: Tue Apr 6 21:59:58 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_118.c
src/usr.bin/xlint/lint1: tree.c
Log Message:
lint: for shift in C99 mode, do not warn about difference to pre-C90
C99 is too far away from traditional C to make this warning useful.
There are 3 different situations in which this warning is generated:
For '1 << (unsigned char)1', the result type is 'unsigned int' in
traditional C. The result type is unsigned because at least 1 of the
operators is unsigned, and it is 'unsigned int' because the usual
arithmetic promotions are applied.
For '1 >> (long)1', as well as for '1 << (long)1', the result type is
'long' in traditional C since the usual arithmetic promotions are
applied.
Omitting this warning in C99 mode reduces the amount of lint warnings in
a typical NetBSD release build by approximately 6800 of 107000 total.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_118.c
cvs rdiff -u -r1.270 -r1.271 src/usr.bin/xlint/lint1/tree.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/msg_118.c
diff -u src/tests/usr.bin/xlint/lint1/msg_118.c:1.3 src/tests/usr.bin/xlint/lint1/msg_118.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_118.c:1.3 Sun Feb 28 01:22:02 2021
+++ src/tests/usr.bin/xlint/lint1/msg_118.c Tue Apr 6 21:59:58 2021
@@ -1,9 +1,9 @@
-/* $NetBSD: msg_118.c,v 1.3 2021/02/28 01:22:02 rillig Exp $ */
+/* $NetBSD: msg_118.c,v 1.4 2021/04/06 21:59:58 rillig Exp $ */
# 3 "msg_118.c"
-// Test for message: semantics of '%s' change in ANSI C; use explicit cast [118]
+/* Test for message: semantics of '%s' change in ANSI C; use explicit cast [118] */
-/* lint1-extra-flags: -h */
+/* lint1-flags: -hsw */
int
int_shl_uint(int i, unsigned int u)
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.270 src/usr.bin/xlint/lint1/tree.c:1.271
--- src/usr.bin/xlint/lint1/tree.c:1.270 Tue Apr 6 21:35:25 2021
+++ src/usr.bin/xlint/lint1/tree.c Tue Apr 6 21:59:58 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.270 2021/04/06 21:35:25 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.271 2021/04/06 21:59:58 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.270 2021/04/06 21:35:25 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.271 2021/04/06 21:59:58 rillig Exp $");
#endif
#include <float.h>
@@ -855,7 +855,7 @@ typeok_shr(const mod_t *mp,
* The left operand would become unsigned in
* traditional C.
*/
- if (hflag &&
+ if (hflag && !Sflag &&
(ln->tn_op != CON || ln->tn_val->v_quad < 0)) {
/* semantics of '%s' change in ANSI C; use ... */
warning(118, mp->m_name);
@@ -866,7 +866,7 @@ typeok_shr(const mod_t *mp,
* In traditional C the left operand would be extended,
* possibly with 1, and then shifted.
*/
- if (hflag &&
+ if (hflag && !Sflag &&
(ln->tn_op != CON || ln->tn_val->v_quad < 0)) {
/* semantics of '%s' change in ANSI C; use ... */
warning(118, mp->m_name);
@@ -891,7 +891,7 @@ typeok_shl(const mod_t *mp, tspec_t lt,
* that there is really a difference between
* ANSI C and traditional C.
*/
- if (hflag)
+ if (hflag && !Sflag)
/* semantics of '%s' change in ANSI C; use ... */
warning(118, mp->m_name);
}