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: for shift in C99 mode, do not warn...



details:   https://anonhg.NetBSD.org/src/rev/7e375657d47a
branches:  trunk
changeset: 954388:7e375657d47a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Apr 06 21:59:58 2021 +0000

description:
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.

diffstat:

 tests/usr.bin/xlint/lint1/msg_118.c |   6 +++---
 usr.bin/xlint/lint1/tree.c          |  10 +++++-----
 2 files changed, 8 insertions(+), 8 deletions(-)

diffs (61 lines):

diff -r ec42245f808e -r 7e375657d47a tests/usr.bin/xlint/lint1/msg_118.c
--- a/tests/usr.bin/xlint/lint1/msg_118.c       Tue Apr 06 21:44:12 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_118.c       Tue Apr 06 21:59:58 2021 +0000
@@ -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)
diff -r ec42245f808e -r 7e375657d47a usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Tue Apr 06 21:44:12 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Tue Apr 06 21:59:58 2021 +0000
@@ -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 @@
                 * 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 @@
                 * 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 @@
                 * 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);
        }



Home | Main Index | Thread Index | Old Index