Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1526582ybl; Wed, 28 Aug 2019 16:29:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvgxLc3Oy1T+447ZodcOqlJa/o4aFIpYmc4IuG+TtN9BH6L8fc8JMRug3gUTim117xmUYf X-Received: by 2002:aa7:8edd:: with SMTP id b29mr7877509pfr.173.1567034993206; Wed, 28 Aug 2019 16:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567034993; cv=none; d=google.com; s=arc-20160816; b=f3lO38ZbY0xub+3gXgr9LrKWG5HpUbuV0OSMuFxG0rSKOczh0fkiRvU4Vok1HJO8Rn 1DmtnSvAG0gsYHKE9b/toEJfnR0ObutapjitWGtYG2NAdU9MQtAqtZOtt387E3J576iK HbUK41df32+g0FyZ805MOrdVoxyLinoSzka1rC5kfQt4JIujnaxkNxS7s0Eaoc+g8379 0Y9SteujNNQdR/02Iz1hQM4QL6W8+1fvOVUINPtQoPG6EQcD3ABliUNJM2DMh9238ezB vHXaSZdJuMQMjOpJ0ugiOZcbQMnPq6l/XTvBFBLfp0aBuosXQfCRm4Rg5DZi5d/9bVMY dQvg== 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=+XyfWMjZjslCIkbHpIEJO6yFk4GM8tJmlHzY8WN3VpE=; b=NjhO4IWv77AydM3GyvzT0JENr8lDfom+wLN1SrjWRI5dAyWgNiJ1m9XbwlnzKY5SDk WPR4KS21nIOBk6YKURUskwDJTT79Z4KkVXhg7W1nyNeekivOTS+AsnaZViE2+trwareB Vnoh0pY0RVaz38pWuFuiy1jzGxpe2o8iLJaM8OgRR3E2YpbH8Jf1CeQFW43DuQMMQ6/0 fB7lB660Ycz7YgP2AjEl/jfAg1bYoii7TIwDrUQMi3kacownQ0EqyuZmJd2GPfye0JVL zTwJeZs9/cfGAauDI6zYCpx5QH3Tbwu6igPhhddqfQ0YE6faKDTys0ma9alZ3+kya3T5 nqfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XMtLwACj; 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 q11si582324pjb.84.2019.08.28.16.29.37; Wed, 28 Aug 2019 16:29:53 -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=XMtLwACj; 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 S1727005AbfH1X2n (ORCPT + 99 others); Wed, 28 Aug 2019 19:28:43 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38715 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726926AbfH1X2n (ORCPT ); Wed, 28 Aug 2019 19:28:43 -0400 Received: by mail-pf1-f196.google.com with SMTP id o70so759983pfg.5 for ; Wed, 28 Aug 2019 16:28:42 -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=+XyfWMjZjslCIkbHpIEJO6yFk4GM8tJmlHzY8WN3VpE=; b=XMtLwACj6fCFbm6guyZbm9jzJBOyNJEoTy7r2/RB7UJhbFEszjyOEmVaFj5OGiCRBf qcwmnxKJjdE3lGkxDWEMahPwvr5c+YAxRrI8cG5n+zOmmLrJahXlDwAXq5+wA2AcHz76 WaqGsJGM5nuCtZLonWi9OvF2Be8jS7WGn5Pj+hQ3v8aaJNepAwK5xj2I2cDfQs1zW9+J 6fOyt8MXAbfwKRkBaz4NpP54uDc6X2cszk53YroJpf9X30zWd6WkFvyuoGVuxG5eiDeZ UT/Wp8nZ/3iNs+YQhwOb4rgch1ZUzr9bu/mva13GF1CqV2Kf0BJjYbYGwYFGPGpdcRD3 m1Bw== 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=+XyfWMjZjslCIkbHpIEJO6yFk4GM8tJmlHzY8WN3VpE=; b=kAtRiBENSwfltnLH4bbonziYAb7pMbZv+A2ZjfqHHrYLNMclkMQiYBlHo1VXUnPg+H C8Ab6D3trEzWf7R2s0ygTINmmDa9QhOn13pxUc6+SFcJhSBXL2SQixlY9sBm4B6mLwLJ CensMoNBXWwZfGdoi/dm+ir+V6pqSOOQ+/lki+DC4LucRMXHhPfByM4g/BqVazKqHkHc 1JEQzs5Ncv/DBeC4Vcft35n9RYHH5VHetbvEHFK7wz+O3UFe8TGwTDWE3FwUAVAaMsEg 8P9az/Uuyw+DNfkzcFpFojQsXoWbrtQyS3M8z7KeLml6Ol/0r0ln+AqtztyQDa55UX9X mCug== X-Gm-Message-State: APjAAAWqP4h4krMHwgVrFhztyCwt8sTJ1me+A/8KHbzKcZcbYWy+klXR gfsbazsLe1ANzrzrG0FohFVscJL1QLwnhvo3+w2DqA== X-Received: by 2002:a63:61cd:: with SMTP id v196mr5724062pgb.263.1567034921605; Wed, 28 Aug 2019 16:28:41 -0700 (PDT) MIME-Version: 1.0 References: <20190828055425.24765-1-yamada.masahiro@socionext.com> <20190828055425.24765-2-yamada.masahiro@socionext.com> <20190828182017.GB127646@archlinux-threadripper> In-Reply-To: <20190828182017.GB127646@archlinux-threadripper> From: Nick Desaulniers Date: Wed, 28 Aug 2019 16:28:30 -0700 Message-ID: Subject: Re: [PATCH 2/2] kbuild: allow Clang to find unused static inline functions for W=1 build To: Nathan Chancellor Cc: Masahiro Yamada , Linux Kbuild mailing list , Miguel Ojeda , Arnd Bergmann , Kees Cook , Luc Van Oostenryck , Michal Marek , Sven Schnelle , Xiaozhou Liu , clang-built-linux , LKML 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 Wed, Aug 28, 2019 at 11:20 AM Nathan Chancellor wrote: > > On Wed, Aug 28, 2019 at 02:54:25PM +0900, Masahiro Yamada wrote: > > GCC and Clang have different policy for -Wunused-function; GCC does not > > warn unused static inline functions at all whereas Clang does if they > > are defined in source files instead of included headers although it has > > been suppressed since commit abb2ea7dfd82 ("compiler, clang: suppress > > warning for unused static inline functions"). > > > > We often miss to delete unused functions where 'static inline' is used > > in *.c files since there is no tool to detect them. Unused code remains > > until somebody notices. For example, commit 075ddd75680f ("regulator: > > core: remove unused rdev_get_supply()"). > > > > Let's remove __maybe_unused from the inline macro to allow Clang to > > start finding unused static inline functions. For now, we do this only > > for W=1 build since it is not a good idea to sprinkle warnings for the > > normal build. > > > > My initial attempt was to add -Wno-unused-function for no W=1 build > > (https://lore.kernel.org/patchwork/patch/1120594/) > > > > Nathan Chancellor pointed out that would weaken Clang's checks since > > we would no longer get -Wunused-function without W=1. It is true GCC > > would detect unused static non-inline functions, but it would weaken > > Clang as a standalone compiler at least. Got it. No problem. > > > > Here is a counter implementation. The current problem is, W=... only > > controls compiler flags, which are globally effective. There is no way > > to narrow the scope to only 'static inline' functions. > > > > This commit defines KBUILD_EXTRA_WARN[123] corresponding to W=[123]. > > When KBUILD_EXTRA_WARN1 is defined, __maybe_unused is omitted from > > the 'inline' macro. > > > > This makes the code a bit uglier, so personally I do not want to carry > > this forever. If we can manage to fix most of the warnings, we can > > drop this entirely, then enable -Wunused-function all the time. How many warnings? > > > > If you contribute to code clean-up, please run "make CC=clang W=1" > > and check -Wunused-function warnings. You will find lots of unused > > functions. > > > > Some of them are false-positives because the call-sites are disabled > > by #ifdef. I do not like to abuse the inline keyword for suppressing > > unused-function warnings because it is intended to be a hint for the > > compiler optimization. I prefer #ifdef around the definition, or > > __maybe_unused if #ifdef would make the code too ugly. > > > > Signed-off-by: Masahiro Yamada > > I can still see warnings from static unused functions and with W=1, I > see plenty more. I agree that this is uglier because of the > __inline_maybe_unused but I think this is better for regular developers. > I will try to work on these unused-function warnings! How many are we talking here? > > Reviewed-by: Nathan Chancellor > Tested-by: Nathan Chancellor This is getting kind of messy. I was more ok when the goal seemed to be simplifying the definition of `inline`, but this is worse IMO. -- Thanks, ~Nick Desaulniers