Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 May 2020 02:08:34 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r361315 - in stable/12/sys: ddb dev/nvdimm dev/ow net sys
Message-ID:  <202005210208.04L28Y5u068587@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Thu May 21 02:08:34 2020
New Revision: 361315
URL: https://svnweb.freebsd.org/changeset/base/361315

Log:
  MFC r361011: kernel: provide panicky version of __unreachable
  
  __builtin_unreachable doesn't raise any compile-time warnings/errors on its
  own, so problems with its usage can't be easily detected. While it would be
  nice for this situation to change and compilers to at least add a warning
  for trivial cases where local state means the instruction can't be reached,
  this isn't the case at the moment and likely will not happen.
  
  This commit adds an __assert_unreachable, whose intent is incredibly clear:
  it asserts that this instruction is unreachable. On INVARIANTS builds, it's
  a panic(), and on non-INVARIANTS it expands to  __unreachable().
  
  Existing users of __unreachable() are converted to __assert_unreachable,
  to improve debuggability if this assumption is violated.

Modified:
  stable/12/sys/ddb/db_expr.c
  stable/12/sys/dev/nvdimm/nvdimm.c
  stable/12/sys/dev/ow/ow.c
  stable/12/sys/net/mppcc.c
  stable/12/sys/sys/systm.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/ddb/db_expr.c
==============================================================================
--- stable/12/sys/ddb/db_expr.c	Thu May 21 02:04:10 2020	(r361314)
+++ stable/12/sys/ddb/db_expr.c	Thu May 21 02:08:34 2020	(r361315)
@@ -34,6 +34,7 @@
 __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
+#include <sys/systm.h>
 
 #include <ddb/ddb.h>
 #include <ddb/db_lex.h>
@@ -229,7 +230,7 @@ db_add_expr(db_expr_t *valuep)
 		lhs |= rhs;
 		break;
 	    default:
-		__unreachable();
+		__assert_unreachable();
 	    }
 	    t = db_read_token();
 	}
@@ -313,7 +314,7 @@ db_logical_relation_expr(
 		    lhs = (lhs <= rhs);
 		    break;
 		default:
-		    __unreachable();
+		    __assert_unreachable();
 	    }
 	    t = db_read_token();
 	}

Modified: stable/12/sys/dev/nvdimm/nvdimm.c
==============================================================================
--- stable/12/sys/dev/nvdimm/nvdimm.c	Thu May 21 02:04:10 2020	(r361314)
+++ stable/12/sys/dev/nvdimm/nvdimm.c	Thu May 21 02:08:34 2020	(r361315)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include "opt_ddb.h"
 
 #include <sys/param.h>
+#include <sys/systm.h>
 #include <sys/bio.h>
 #include <sys/bitstring.h>
 #include <sys/bus.h>
@@ -235,7 +236,7 @@ read_label(struct nvdimm_dev *nv, int num)
 			return (0);
 		}
 	}
-	__unreachable();
+	__assert_unreachable();
 }
 
 static int

Modified: stable/12/sys/dev/ow/ow.c
==============================================================================
--- stable/12/sys/dev/ow/ow.c	Thu May 21 02:04:10 2020	(r361314)
+++ stable/12/sys/dev/ow/ow.c	Thu May 21 02:08:34 2020	(r361315)
@@ -505,7 +505,7 @@ again:
 					return (EIO);
 				goto again;
 			default: /* NOTREACHED */
-				__unreachable();
+				__assert_unreachable();
 			}
 			if (dir) {
 				OWLL_WRITE_ONE(lldev, &timing_regular);

Modified: stable/12/sys/net/mppcc.c
==============================================================================
--- stable/12/sys/net/mppcc.c	Thu May 21 02:04:10 2020	(r361314)
+++ stable/12/sys/net/mppcc.c	Thu May 21 02:08:34 2020	(r361315)
@@ -232,7 +232,7 @@ int MPPC_Compress(u_char **src, u_char **dst, u_long *
 	} else if (off < 8192) {	/* 16-bit offset; 320 <= offset < 8192 */
 	    putbits16(*dst, 0xc000|(off-320), 16, &olen, &l);
 	} else {		/* NOTREACHED */
-	    __unreachable();
+	    __assert_unreachable();
 	    rtn &= ~MPPC_OK;
 	    return (rtn);
 	}

Modified: stable/12/sys/sys/systm.h
==============================================================================
--- stable/12/sys/sys/systm.h	Thu May 21 02:04:10 2020	(r361314)
+++ stable/12/sys/sys/systm.h	Thu May 21 02:08:34 2020	(r361315)
@@ -108,12 +108,16 @@ void	kassert_panic(const char *fmt, ...)  __printflike
 		kassert_panic msg;					\
 	}								\
 } while (0)
+#define	__assert_unreachable() \
+	panic("executing segment marked as unreachable at %s:%d (%s)\n", \
+	    __FILE__, __LINE__, __func__)
 #else
 #define	KASSERT(exp,msg) do { \
 } while (0)
 
 #define	VNASSERT(exp, vp, msg) do { \
 } while (0)
+#define	__assert_unreachable()	__unreachable()
 #endif
 
 #ifndef CTASSERT	/* Allow lint to override */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005210208.04L28Y5u068587>