From 51286ec006a8f1b41a2a759d92f8ae68fd89c1ee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 8 Nov 2018 22:38:46 +0700 Subject: [PATCH] Add unreachable.spatch coccinelle recipe and run it in precheck CI phase --- cocci/.gitignore | 1 + cocci/unreachable.spatch | 6 ++++++ lib/lwres/getipnode.c | 3 +++ lib/lwres/getnameinfo.c | 2 ++ lib/lwres/unreachable_p.h | 18 ++++++++++++++++++ util/check-cocci | 15 +++++++++++++++ util/copyrights | 3 +++ 7 files changed, 48 insertions(+) create mode 100644 cocci/.gitignore create mode 100644 cocci/unreachable.spatch create mode 100644 lib/lwres/unreachable_p.h create mode 100755 util/check-cocci diff --git a/cocci/.gitignore b/cocci/.gitignore new file mode 100644 index 00000000000..faacba5004d --- /dev/null +++ b/cocci/.gitignore @@ -0,0 +1 @@ +/*.patch diff --git a/cocci/unreachable.spatch b/cocci/unreachable.spatch new file mode 100644 index 00000000000..0cc368a5164 --- /dev/null +++ b/cocci/unreachable.spatch @@ -0,0 +1,6 @@ +@@ +@@ + + INSIST(0); ++ ISC_UNREACHABLE(); + ... when != ISC_UNREACHABLE(); diff --git a/lib/lwres/getipnode.c b/lib/lwres/getipnode.c index f0c0ae655f9..1d7934f4b72 100644 --- a/lib/lwres/getipnode.c +++ b/lib/lwres/getipnode.c @@ -126,6 +126,7 @@ #include /* XXX #include */ #include "assert_p.h" +#include "unreachable_p.h" #ifndef INADDRSZ #define INADDRSZ 4 @@ -1023,6 +1024,7 @@ hostfromaddr(lwres_gnbaresponse_t *addr, int af, const void *src) { break; default: INSIST(0); + ISC_UNREACHABLE(); } /* @@ -1100,6 +1102,7 @@ hostfromname(lwres_gabnresponse_t *name, int af) { break; default: INSIST(0); + ISC_UNREACHABLE(); } /* diff --git a/lib/lwres/getnameinfo.c b/lib/lwres/getnameinfo.c index 9951f4cf7ec..8a02a2a72a7 100644 --- a/lib/lwres/getnameinfo.c +++ b/lib/lwres/getnameinfo.c @@ -117,6 +117,7 @@ #include "print_p.h" #include "assert_p.h" +#include "unreachable_p.h" #define SUCCESS 0 @@ -299,6 +300,7 @@ lwres_getnameinfo(const struct sockaddr *sa, size_t salen, char *host, break; default: INSIST(0); + ISC_UNREACHABLE(); } n = lwres_context_create(&lwrctx, NULL, NULL, NULL, 0); diff --git a/lib/lwres/unreachable_p.h b/lib/lwres/unreachable_p.h new file mode 100644 index 00000000000..525fe6d3d78 --- /dev/null +++ b/lib/lwres/unreachable_p.h @@ -0,0 +1,18 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +#pragma once + +#ifdef HAVE_BUILTIN_UNREACHABLE +#define ISC_UNREACHABLE() __builtin_unreachable(); +#else +#define ISC_UNREACHABLE() +#endif diff --git a/util/check-cocci b/util/check-cocci new file mode 100755 index 00000000000..61792bd12e3 --- /dev/null +++ b/util/check-cocci @@ -0,0 +1,15 @@ +#!/bin/sh + +ret=0 +for spatch in cocci/*.spatch; do + patch="$(dirname "$spatch")/$(basename "$spatch" .spatch).patch" + spatch --sp-file="$spatch" --use-gitgrep --dir . --very-quiet > "$patch"; + if [ "$(< "$patch" wc -l)" -gt "0" ]; then + cat "$patch" + ret=1 + else + rm "$patch" + fi +done + +exit $ret diff --git a/util/copyrights b/util/copyrights index cd13cc1fc4b..61ea7577f40 100644 --- a/util/copyrights +++ b/util/copyrights @@ -2627,6 +2627,7 @@ ./bin/win32/BINDInstall/resource.h X 2001,2005,2009,2018 ./bind.keys X 2009,2010,2011,2017,2018 ./bind.keys.h X 2009,2010,2011,2012,2014,2017,2018 +./cocci/unreachable.spatch X 2018 ./config.guess X 1998,1999,2000,2001,2004,2009,2013,2018 ./config.h.in X 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018 ./config.h.win32 C 1999,2000,2001,2004,2006,2007,2008,2009,2011,2012,2013,2014,2015,2016,2017,2018 @@ -4319,6 +4320,7 @@ ./lib/lwres/unix/include/Makefile.in MAKE 2001,2004,2007,2012,2016,2018 ./lib/lwres/unix/include/lwres/Makefile.in MAKE 2001,2004,2007,2012,2016,2018 ./lib/lwres/unix/include/lwres/net.h C 2000,2001,2002,2004,2005,2007,2016,2018 +./lib/lwres/unreachable_p.h C 2018 ./lib/lwres/version.c C 2000,2001,2004,2005,2007,2016,2018 ./lib/lwres/win32/DLLMain.c C 2001,2004,2007,2016,2018 ./lib/lwres/win32/Makefile.in MAKE 2001,2004,2007,2012,2016,2018 @@ -4415,6 +4417,7 @@ ./util/branchsync.sh SH 2013,2016,2018 ./util/check-categories.sh SH 2015,2016,2017,2018 ./util/check-changes PERL 2002,2004,2007,2012,2016,2018 +./util/check-cocci X 2018 ./util/check-includes.pl PERL 2000,2001,2004,2007,2012,2016,2018 ./util/check-instincludes.sh SH 2000,2001,2004,2007,2012,2016,2018 ./util/check-pullups.pl PERL 2001,2002,2003,2004,2007,2012,2016,2018 -- 2.47.3