Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make: fix lint warnings



details:   https://anonhg.NetBSD.org/src/rev/a52b25c19090
branches:  trunk
changeset: 984913:a52b25c19090
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 31 09:30:17 2021 +0000

description:
make: fix lint warnings

The string functions from str.h are declared as 'static __unused' when
compiled with GCC, but lint explicitly undefines __GCC__ during
preprocessing.  Therefore, make those functions inline, to prevent
warnings that they are unused.

The macro UNCONST is used in a few places, and (again) since lint
undefines __GCC__, that macro expanded to a simple type cast, which lint
warned about.  To prevent this warning, implement UNCONST as a function
that works everywhere and hides the type cast.

In filemon_open, the code for closing F->in was obviously unreachable.

No functional change.

diffstat:

 usr.bin/make/Makefile                 |   3 ++-
 usr.bin/make/filemon/filemon_ktrace.c |   3 +--
 usr.bin/make/make.h                   |  26 +++++++++++++++-----------
 usr.bin/make/suff.c                   |   5 +++--
 usr.bin/make/var.c                    |   6 ++++--
 5 files changed, 25 insertions(+), 18 deletions(-)

diffs (135 lines):

diff -r 0686436e1f1c -r a52b25c19090 usr.bin/make/Makefile
--- a/usr.bin/make/Makefile     Sat Jul 31 09:14:47 2021 +0000
+++ b/usr.bin/make/Makefile     Sat Jul 31 09:30:17 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.115 2021/05/30 21:03:08 rillig Exp $
+#      $NetBSD: Makefile,v 1.116 2021/07/31 09:30:17 rillig Exp $
 #      @(#)Makefile    5.2 (Berkeley) 12/28/90
 
 PROG=  make
@@ -117,6 +117,7 @@
 .endif
 
 LINTFLAGS+=    -T      # strict bool mode, available since 2021-01-11
+LINTFLAGS+=    -w      # treat warnings as errors
 CLEANFILES+=   *.o     # for filemon objects
 
 COPTS.arch.c+= ${GCC_NO_FORMAT_TRUNCATION}
diff -r 0686436e1f1c -r a52b25c19090 usr.bin/make/filemon/filemon_ktrace.c
--- a/usr.bin/make/filemon/filemon_ktrace.c     Sat Jul 31 09:14:47 2021 +0000
+++ b/usr.bin/make/filemon/filemon_ktrace.c     Sat Jul 31 09:30:17 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: filemon_ktrace.c,v 1.14 2021/02/01 21:34:41 rillig Exp $       */
+/*     $NetBSD: filemon_ktrace.c,v 1.15 2021/07/31 09:30:17 rillig Exp $       */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -227,7 +227,6 @@
        /* Success!  */
        return F;
 
-       (void)fclose(F->in);
 fail1: (void)close(ktrpipe[0]);
        (void)close(ktrpipe[1]);
 fail0: free(F);
diff -r 0686436e1f1c -r a52b25c19090 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sat Jul 31 09:14:47 2021 +0000
+++ b/usr.bin/make/make.h       Sat Jul 31 09:30:17 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.263 2021/06/21 10:33:11 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.264 2021/07/31 09:30:17 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,14 @@
 #endif
 
 #define MAKE_INLINE static inline MAKE_ATTR_UNUSED
+
+/* MAKE_STATIC marks a function that may or may not be inlined. */
+#if defined(lint)
+/* As of 2021-07-31, NetBSD lint ignores __attribute__((unused)). */
+#define MAKE_STATIC MAKE_INLINE
+#else
 #define MAKE_STATIC static MAKE_ATTR_UNUSED
+#endif
 
 #if __STDC_VERSION__ >= 199901L || defined(lint) || defined(USE_C99_BOOLEAN)
 #include <stdbool.h>
@@ -742,16 +749,13 @@
 MAKE_INLINE const char *
 GNode_VarMember(GNode *gn) { return GNode_ValueDirect(gn, MEMBER); }
 
-#if defined(__GNUC__) && __STDC_VERSION__ >= 199901L
-#define UNCONST(ptr)   ({              \
-    union __unconst {                  \
-       const void *__cp;               \
-       void *__p;                      \
-    } __d;                             \
-    __d.__cp = ptr, __d.__p; })
-#else
-#define UNCONST(ptr)   (void *)(ptr)
-#endif
+MAKE_INLINE void *
+UNCONST(const void *ptr)
+{
+       void *ret;
+       memcpy(&ret, &ptr, sizeof(ret));
+       return ret;
+}
 
 /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
 #include <limits.h>
diff -r 0686436e1f1c -r a52b25c19090 usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Jul 31 09:14:47 2021 +0000
+++ b/usr.bin/make/suff.c       Sat Jul 31 09:30:17 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.350 2021/04/04 10:05:08 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.351 2021/07/31 09:30:17 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -115,7 +115,7 @@
 #include "dir.h"
 
 /*     "@(#)suff.c     8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.350 2021/04/04 10:05:08 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.351 2021/07/31 09:30:17 rillig Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -619,6 +619,7 @@
                /* TODO: Avoid the redundant parsing here. */
                bool ok = ParseTransform(name, &srcSuff, &targSuff);
                assert(ok);
+               /* LINTED 129 *//* expression has null effect */
                (void)ok;
        }
 
diff -r 0686436e1f1c -r a52b25c19090 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Jul 31 09:14:47 2021 +0000
+++ b/usr.bin/make/var.c        Sat Jul 31 09:30:17 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.944 2021/07/31 00:17:04 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.945 2021/07/31 09:30:17 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.944 2021/07/31 00:17:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.945 2021/07/31 09:30:17 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4019,6 +4019,8 @@
     char endc          /* ')' or '}'; or '\0' for indirect modifiers */
 )
 {
+       /* LINTED 115 *//* warning: left operand of '=' must be modifiable lvalue */
+       /* That's a bug in lint; see tests/usr.bin/xlint/lint1/msg_115.c. */
        ModChain ch = ModChain_Literal(expr, startc, endc, ' ', false);
        const char *p;
        const char *mod;



Home | Main Index | Thread Index | Old Index