Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp271030ybl; Mon, 12 Aug 2019 16:08:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqztRxhXf3OWDkHXfLQtqJoDDfvP7R9vEFiuJuKMLFMfC/cpzDqRW1rvw7SZc43f7vPb9YK+ X-Received: by 2002:a17:90a:ab0b:: with SMTP id m11mr1513494pjq.73.1565651284186; Mon, 12 Aug 2019 16:08:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565651284; cv=none; d=google.com; s=arc-20160816; b=Qpo8v3PV+la3jGonmfUkM+GXhyZwFOmR/6Ntl7I7BitAJE/jFUaHk5Q9e0moX6aNHA OZA0id/LWVCclnCrRWawenDK9quKqF3UCTQXde+65+9M3E3XRASVVEBasFZoMA59lURz Ey+Mu7QxMjQxQx6fgbi1Z01HPn8i4To9lWN/nv3S48y5kKy7xJzhlKVgOp0crphKuf73 IaYj/JzdtX/Ryh9ev77bumNUh3DVFlFpw6mfV6XJOvDv8BuVQ09CI8EaJrxJ7hXCfMWw 2cQa8USJV1omKE7aQzmzhp04N4PSn0QTp2JvI9c93yWdlQeWtvp7AnaDd3Ipi4Z9sJQv 2nFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=De9jcsYouvXHLh29bhHmb3kbddcyyiH/H6Cd5fLJLXA=; b=ReTCwC3JSztjU5hehN5E8Vjx812RX+29rq39zwJGNrCo5Gtmgk2JEjl7yuplAmI4Td 7NaGeOg2ORWV+uBMSjAyxYUmswR214c3lPnGPnHCJU7iCsmjKDOhiNeEvlKtk/AF36/J 3SGfvn1pJqMvH5PcfS9ut47sX0h+SblnlDNjyXVhY6fi9x5ezW0IR1L3CuC3Ems9nzTh IAf78c10BVVTo5FJ8LMIUqcu/sWp1Ng+h2gJJzEb/CkpKj6NqNvGYoUau/yK9/T7S7AA TzBO/fd2HzI1XJyREGshGn3WHCSXsp6GH3D7F6F5aUc8/4mFpL1tb3J3jk3ubYlgiXL5 MmUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RV02ssHx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x18si60676576plm.292.2019.08.12.16.07.48; Mon, 12 Aug 2019 16:08:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RV02ssHx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726631AbfHLXGc (ORCPT + 99 others); Mon, 12 Aug 2019 19:06:32 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41224 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbfHLXGc (ORCPT ); Mon, 12 Aug 2019 19:06:32 -0400 Received: by mail-pf1-f194.google.com with SMTP id 196so3289545pfz.8 for ; Mon, 12 Aug 2019 16:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=De9jcsYouvXHLh29bhHmb3kbddcyyiH/H6Cd5fLJLXA=; b=RV02ssHxjFrVVEupasCBV/t3807qEtv7FnIlZqUgUyOfO/9nwFM4mHRIhmByK+HbvU QvFUeCZF/PA0ZEx8HUQpYievndAv0tJk9n86shTgvHg6esAJTNY3T+WkhZ3DFTTwpJj0 PUBCCnay7zNjKrIpgHccEN1YlUhrIZ5RhJGq2NmLlI5g6/0uQbQ2fefizb23xyI7ALek bbMKGwJelXNTrNnVh/0HVoLgJXWxwUoZUWRUDUj6rRG+5/oP1JbuvAOb8m3EWyiZm8+c YZWKT5boCQAWy7jgWM1Oce62ET6srHIz0NTkLvyJ4b37TesY7g/m7t/i1xR26tSc72wl oa/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=De9jcsYouvXHLh29bhHmb3kbddcyyiH/H6Cd5fLJLXA=; b=nbpRoGddUUY9LHvAzJhk9b5JN6HOakgtcDPNKrTdPsxeMT3ilOLdfE/kDuUBiKzthJ VfYQwlsLohGBkVgJF4CLptI+cHNBDwESY7fhbCsZsjbxtkKNp5AaY5/t0rXBDIR85spI XCKd4Vd/kR8LnuoleHbq6fMJKgmQBP07AM5s+PgLHcXrjIviJAhr0+KPp77ceXVQ5az0 CfLAy6HdR7kB0adJHcLnsqjUecSORbxa0/UprNV4CmSLP9o+Y+2dL/jHltZc3eia3r9H NeXnuEEd+hrJ1UPYz2rQcsXrJoygnqGEynD0xEanqRVCp6hjuSdtkmMqTbGmNCqjyYyw epaw== X-Gm-Message-State: APjAAAVeHCv39KbkFrklUC4D66wY81K4XbUZ4APXFZxiQBFVbNi97cw4 gS99DWbEqLy/SWp7LH0dZlK3qcH4YcLO3wBzrdWggA== X-Received: by 2002:aa7:8085:: with SMTP id v5mr20736102pff.165.1565651191125; Mon, 12 Aug 2019 16:06:31 -0700 (PDT) MIME-Version: 1.0 References: <20190812214711.83710-1-nhuck@google.com> In-Reply-To: <20190812214711.83710-1-nhuck@google.com> From: Nick Desaulniers Date: Mon, 12 Aug 2019 16:06:20 -0700 Message-ID: Subject: Re: [PATCH] kbuild: Change fallthrough comments to attributes To: Nathan Huckleberry Cc: Masahiro Yamada , Michal Marek , Linux Kbuild mailing list , LKML , Linux Memory Management List , clang-built-linux Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 12, 2019 at 2:48 PM 'Nathan Huckleberry' via Clang Built Linux wrote: > > Clang does not support the use of comments to label > intentional fallthrough. This patch replaces some uses > of comments to attributesto cut down a significant number > of warnings on clang (from ~50000 to ~200). Only comments > in commonly used header files have been replaced. > > Since there is still quite a bit of noise, this > patch moves -Wimplicit-fallthrough to > Makefile.extrawarn if you are compiling with > clang. > > Signed-off-by: Nathan Huckleberry > --- > Makefile | 4 +++ > include/linux/jhash.h | 60 ++++++++++++++++++++++++++++---------- > include/linux/mm.h | 9 ++++-- > include/linux/signal.h | 14 +++++---- > include/linux/skbuff.h | 12 ++++---- > lib/zstd/bitstream.h | 10 +++---- > scripts/Makefile.extrawarn | 3 ++ > 7 files changed, 77 insertions(+), 35 deletions(-) > > diff --git a/Makefile b/Makefile > index c391fbb07195..875930c19619 100644 > --- a/Makefile > +++ b/Makefile > @@ -847,7 +847,11 @@ NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) > KBUILD_CFLAGS += -Wdeclaration-after-statement > > # Warn about unmarked fall-throughs in switch statement. > +# If the compiler is clang, this warning is only enabled if W=1 in > +# Makefile.extrawarn > +ifndef CONFIG_CC_IS_CLANG > KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough,) This should go in the block higher up (see line 739) that already exists for CONFIG_CC_IS_CLANG. > +endif > > # Variable Length Arrays (VLAs) should not be used anywhere in the kernel > KBUILD_CFLAGS += -Wvla > diff --git a/include/linux/jhash.h b/include/linux/jhash.h > index ba2f6a9776b6..6cb2381501d1 100644 > --- a/include/linux/jhash.h > +++ b/include/linux/jhash.h Probably should split this patch into: 1. Makefile and scripts/Makefile.extrawarn hunks 2. hunks for each other file that can be applied individually (as makes sense for the maintainers' trees). > @@ -86,19 +86,43 @@ static inline u32 jhash(const void *key, u32 length, u32 initval) > } > /* Last block: affect all 32 bits of (c) */ > switch (length) { > - case 12: c += (u32)k[11]<<24; /* fall through */ > - case 11: c += (u32)k[10]<<16; /* fall through */ > - case 10: c += (u32)k[9]<<8; /* fall through */ > - case 9: c += k[8]; /* fall through */ > - case 8: b += (u32)k[7]<<24; /* fall through */ > - case 7: b += (u32)k[6]<<16; /* fall through */ > - case 6: b += (u32)k[5]<<8; /* fall through */ > - case 5: b += k[4]; /* fall through */ > - case 4: a += (u32)k[3]<<24; /* fall through */ > - case 3: a += (u32)k[2]<<16; /* fall through */ > - case 2: a += (u32)k[1]<<8; /* fall through */ > - case 1: a += k[0]; > + case 12: > + c += (u32)k[11]<<24; > + __attribute__((fallthrough)); > + case 11: > + c += (u32)k[10]<<16; > + __attribute__((fallthrough)); > + case 10: > + c += (u32)k[9]<<8; > + __attribute__((fallthrough)); > + case 9: > + c += k[8]; > + __attribute__((fallthrough)); > + case 8: > + b += (u32)k[7]<<24; > + __attribute__((fallthrough)); > + case 7: > + b += (u32)k[6]<<16; > + __attribute__((fallthrough)); > + case 6: > + b += (u32)k[5]<<8; > + __attribute__((fallthrough)); > + case 5: > + b += k[4]; > + __attribute__((fallthrough)); > + case 4: > + a += (u32)k[3]<<24; > + __attribute__((fallthrough)); > + case 3: > + a += (u32)k[2]<<16; > + __attribute__((fallthrough)); > + case 2: > + a += (u32)k[1]<<8; > + __attribute__((fallthrough)); > + case 1: > + a += k[0]; > __jhash_final(a, b, c); > + break; > case 0: /* Nothing left to add */ > break; > } > @@ -132,10 +156,16 @@ static inline u32 jhash2(const u32 *k, u32 length, u32 initval) > > /* Handle the last 3 u32's */ > switch (length) { > - case 3: c += k[2]; /* fall through */ > - case 2: b += k[1]; /* fall through */ > - case 1: a += k[0]; > + case 3: > + c += k[2]; > + __attribute__((fallthrough)); > + case 2: > + b += k[1]; > + __attribute__((fallthrough)); > + case 1: > + a += k[0]; > __jhash_final(a, b, c); > + break; > case 0: /* Nothing left to add */ > break; > } > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 0334ca97c584..52d99f263ca3 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -158,11 +158,14 @@ static inline void __mm_zero_struct_page(struct page *page) > > switch (sizeof(struct page)) { > case 80: > - _pp[9] = 0; /* fallthrough */ > + _pp[9] = 0; > + __attribute__((fallthrough)); > case 72: > - _pp[8] = 0; /* fallthrough */ > + _pp[8] = 0; > + __attribute__((fallthrough)); > case 64: > - _pp[7] = 0; /* fallthrough */ > + _pp[7] = 0; > + __attribute__((fallthrough)); > case 56: > _pp[6] = 0; > _pp[5] = 0; > diff --git a/include/linux/signal.h b/include/linux/signal.h > index b5d99482d3fe..4fb0a0041a37 100644 > --- a/include/linux/signal.h > +++ b/include/linux/signal.h > @@ -129,11 +129,11 @@ static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \ > b3 = b->sig[3]; b2 = b->sig[2]; \ > r->sig[3] = op(a3, b3); \ > r->sig[2] = op(a2, b2); \ > - /* fall through */ \ > + __attribute__((fallthrough)); \ > case 2: \ > a1 = a->sig[1]; b1 = b->sig[1]; \ > r->sig[1] = op(a1, b1); \ > - /* fall through */ \ > + __attribute__((fallthrough)); \ > case 1: \ > a0 = a->sig[0]; b0 = b->sig[0]; \ > r->sig[0] = op(a0, b0); \ > @@ -163,9 +163,9 @@ static inline void name(sigset_t *set) \ > switch (_NSIG_WORDS) { \ > case 4: set->sig[3] = op(set->sig[3]); \ > set->sig[2] = op(set->sig[2]); \ > - /* fall through */ \ > + __attribute__((fallthrough)); \ > case 2: set->sig[1] = op(set->sig[1]); \ > - /* fall through */ \ > + __attribute__((fallthrough)); \ > case 1: set->sig[0] = op(set->sig[0]); \ > break; \ > default: \ > @@ -186,7 +186,7 @@ static inline void sigemptyset(sigset_t *set) > memset(set, 0, sizeof(sigset_t)); > break; > case 2: set->sig[1] = 0; > - /* fall through */ > + __attribute__((fallthrough)); > case 1: set->sig[0] = 0; > break; > } > @@ -199,7 +199,7 @@ static inline void sigfillset(sigset_t *set) > memset(set, -1, sizeof(sigset_t)); > break; > case 2: set->sig[1] = -1; > - /* fall through */ > + __attribute__((fallthrough)); > case 1: set->sig[0] = -1; > break; > } > @@ -230,6 +230,7 @@ static inline void siginitset(sigset_t *set, unsigned long mask) > memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1)); > break; > case 2: set->sig[1] = 0; > + __attribute__((fallthrough)); > case 1: ; > } > } > @@ -242,6 +243,7 @@ static inline void siginitsetinv(sigset_t *set, unsigned long mask) > memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1)); > break; > case 2: set->sig[1] = -1; > + __attribute__((fallthrough)); > case 1: ; > } > } > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h > index d8af86d995d6..4a1df6714dfe 100644 > --- a/include/linux/skbuff.h > +++ b/include/linux/skbuff.h > @@ -3639,19 +3639,19 @@ static inline bool __skb_metadata_differs(const struct sk_buff *skb_a, > #define __it(x, op) (x -= sizeof(u##op)) > #define __it_diff(a, b, op) (*(u##op *)__it(a, op)) ^ (*(u##op *)__it(b, op)) > case 32: diffs |= __it_diff(a, b, 64); > - /* fall through */ > + __attribute__((fallthrough)); > case 24: diffs |= __it_diff(a, b, 64); > - /* fall through */ > + __attribute__((fallthrough)); > case 16: diffs |= __it_diff(a, b, 64); > - /* fall through */ > + __attribute__((fallthrough)); > case 8: diffs |= __it_diff(a, b, 64); > break; > case 28: diffs |= __it_diff(a, b, 64); > - /* fall through */ > + __attribute__((fallthrough)); > case 20: diffs |= __it_diff(a, b, 64); > - /* fall through */ > + __attribute__((fallthrough)); > case 12: diffs |= __it_diff(a, b, 64); > - /* fall through */ > + __attribute__((fallthrough)); > case 4: diffs |= __it_diff(a, b, 32); > break; > } > diff --git a/lib/zstd/bitstream.h b/lib/zstd/bitstream.h > index 3a49784d5c61..cc311bae44da 100644 > --- a/lib/zstd/bitstream.h > +++ b/lib/zstd/bitstream.h > @@ -259,15 +259,15 @@ ZSTD_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, s > bitD->bitContainer = *(const BYTE *)(bitD->start); > switch (srcSize) { > case 7: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[6]) << (sizeof(bitD->bitContainer) * 8 - 16); > - /* fall through */ > + __attribute__((fallthrough)); > case 6: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[5]) << (sizeof(bitD->bitContainer) * 8 - 24); > - /* fall through */ > + __attribute__((fallthrough)); > case 5: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[4]) << (sizeof(bitD->bitContainer) * 8 - 32); > - /* fall through */ > + __attribute__((fallthrough)); > case 4: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[3]) << 24; > - /* fall through */ > + __attribute__((fallthrough)); > case 3: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[2]) << 16; > - /* fall through */ > + __attribute__((fallthrough)); > case 2: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[1]) << 8; > default:; > } > diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn > index a74ce2e3c33e..e12359d69bb7 100644 > --- a/scripts/Makefile.extrawarn > +++ b/scripts/Makefile.extrawarn > @@ -30,6 +30,9 @@ warning-1 += $(call cc-option, -Wunused-but-set-variable) > warning-1 += $(call cc-option, -Wunused-const-variable) > warning-1 += $(call cc-option, -Wpacked-not-aligned) > warning-1 += $(call cc-option, -Wstringop-truncation) > +ifdef CONFIG_CC_IS_CLANG > +KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough,) copy+pasta? Should this be: warning-1 += ... further, there's a block at the end of this file already for CONFIG_CC_IS_CLANG that this should go in. Unlike the rest of the items there, you SHOULD keep the call to cc-option since older versions of Clang won't support the warning. Thanks for the patch! -- Thanks, ~Nick Desaulniers