Source-Changes-HG archive

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

[.joined/src/trunk]: .joined/src/sys libkern: Make KASSERT verify expression ...



details:   https://anonhg.NetBSD.org/.joined/src/rev/e03b62c72cb9
branches:  trunk
changeset: 359331:e03b62c72cb9
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Dec 31 14:19:57 2021 +0000

description:
libkern: Make KASSERT verify expression is valid if !DIAGNOSTIC.

This way it is no longer necessary to mark variables __diagused if
they are used in KASSERT conditions.

Fix fallout from this by removing now-unnecessary and `#ifdef
DIAGNOSTIC'.

Don't do the same for KDASSERT if !DEBUG -- unlike KASSERT and
DIAGNOSTIC, variables needed by KDASSERT and DEBUG are likely to be
expensive to compute (and potentially difficult for a compiler to
prove flushable), so we don't want to require them under !DEBUG.

diffstat:

 sys/dev/wscons/wsdisplay.c |   6 ++----
 sys/kern/subr_autoconf.c   |   6 ++----
 sys/kern/subr_psref.c      |   6 ++----
 sys/kern/subr_thmap.c      |   6 ++----
 sys/lib/libkern/libkern.h  |  12 +++++++++---
 5 files changed, 17 insertions(+), 19 deletions(-)

diffs (155 lines):

diff -r aa3b90ac7994 -r e03b62c72cb9 sys/dev/wscons/wsdisplay.c
--- a/sys/dev/wscons/wsdisplay.c        Fri Dec 31 13:15:00 2021 +0000
+++ b/sys/dev/wscons/wsdisplay.c        Fri Dec 31 14:19:57 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wsdisplay.c,v 1.162 2020/12/27 16:09:33 tsutsui Exp $ */
+/* $NetBSD: wsdisplay.c,v 1.163 2021/12/31 14:19:57 riastradh Exp $ */
 
 /*
  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsdisplay.c,v 1.162 2020/12/27 16:09:33 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsdisplay.c,v 1.163 2021/12/31 14:19:57 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_wsdisplay_compat.h"
@@ -115,10 +115,8 @@
 
        struct wsdisplay_softc *sc;
 
-#ifdef DIAGNOSTIC
        /* XXX this is to support a hack in emulinput, see comment below */
        int scr_in_ttyoutput;
-#endif
 };
 
 static struct wsscreen *wsscreen_attach(struct wsdisplay_softc *, int,
diff -r aa3b90ac7994 -r e03b62c72cb9 sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Fri Dec 31 13:15:00 2021 +0000
+++ b/sys/kern/subr_autoconf.c  Fri Dec 31 14:19:57 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.290 2021/10/11 10:59:09 jmcneill Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.291 2021/12/31 14:19:57 riastradh Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.290 2021/10/11 10:59:09 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.291 2021/12/31 14:19:57 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -838,7 +838,6 @@
        return 0;
 }
 
-#if defined(DIAGNOSTIC)
 static int
 cfdriver_iattr_count(const struct cfdriver *cd)
 {
@@ -853,7 +852,6 @@
        }
        return i;
 }
-#endif /* DIAGNOSTIC */
 
 /*
  * Lookup an interface attribute description by name.
diff -r aa3b90ac7994 -r e03b62c72cb9 sys/kern/subr_psref.c
--- a/sys/kern/subr_psref.c     Fri Dec 31 13:15:00 2021 +0000
+++ b/sys/kern/subr_psref.c     Fri Dec 31 14:19:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_psref.c,v 1.15 2021/07/21 06:35:45 skrll Exp $    */
+/*     $NetBSD: subr_psref.c,v 1.16 2021/12/31 14:19:57 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.15 2021/07/21 06:35:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.16 2021/12/31 14:19:57 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -170,7 +170,6 @@
        return class;
 }
 
-#ifdef DIAGNOSTIC
 static void
 psref_cpu_drained_p(void *p, void *cookie, struct cpu_info *ci __unused)
 {
@@ -190,7 +189,6 @@
 
        return ret;
 }
-#endif /* DIAGNOSTIC */
 
 /*
  * psref_class_destroy(class)
diff -r aa3b90ac7994 -r e03b62c72cb9 sys/kern/subr_thmap.c
--- a/sys/kern/subr_thmap.c     Fri Dec 31 13:15:00 2021 +0000
+++ b/sys/kern/subr_thmap.c     Fri Dec 31 14:19:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_thmap.c,v 1.7 2020/08/31 20:22:57 riastradh Exp $ */
+/*     $NetBSD: subr_thmap.c,v 1.8 2021/12/31 14:19:57 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2018 Mindaugas Rasiukevicius <rmind at noxt eu>
@@ -112,7 +112,7 @@
 #include "utils.h"
 #endif
 
-THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.7 2020/08/31 20:22:57 riastradh Exp $");
+THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.8 2021/12/31 14:19:57 riastradh Exp $");
 
 #include <crypto/blake2/blake2s.h>
 
@@ -256,13 +256,11 @@
  * NODE LOCKING.
  */
 
-#ifdef DIAGNOSTIC
 static inline bool
 node_locked_p(thmap_inode_t *node)
 {
        return (atomic_load_relaxed(&node->state) & NODE_LOCKED) != 0;
 }
-#endif
 
 static void
 lock_node(thmap_inode_t *node)
diff -r aa3b90ac7994 -r e03b62c72cb9 sys/lib/libkern/libkern.h
--- a/sys/lib/libkern/libkern.h Fri Dec 31 13:15:00 2021 +0000
+++ b/sys/lib/libkern/libkern.h Fri Dec 31 14:19:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: libkern.h,v 1.143 2021/05/17 08:50:36 mrg Exp $        */
+/*     $NetBSD: libkern.h,v 1.144 2021/12/31 14:19:57 riastradh Exp $  */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -269,8 +269,14 @@
 #define        KASSERTMSG(e, msg, ...) /* NOTHING */
 #define        KASSERT(e)              /* NOTHING */
 #else /* !lint */
-#define        KASSERTMSG(e, msg, ...) ((void)0)
-#define        KASSERT(e)              ((void)0)
+/*
+ * Make sure the expression compiles, but don't evaluate any of it.  We
+ * use sizeof to inhibit evaluation, and cast to long so the expression
+ * can be integer- or pointer-valued without bringing in other header
+ * files.
+ */
+#define        KASSERTMSG(e, msg, ...) ((void)sizeof((long)(e)))
+#define        KASSERT(e)              ((void)sizeof((long)(e)))
 #endif /* !lint */
 #else /* DIAGNOSTIC */
 #define _DIAGASSERT(a) assert(a)



Home | Main Index | Thread Index | Old Index