Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1222707ybl; Wed, 28 Aug 2019 11:23:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIvffkDbR9O4mhIMKpmtBDtHCfm0KGlPj7MLvz0O8qXT+r9IJa08YJAZZpIVVku2ysgxAM X-Received: by 2002:a63:481c:: with SMTP id v28mr4629163pga.50.1567016579993; Wed, 28 Aug 2019 11:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567016579; cv=none; d=google.com; s=arc-20160816; b=0KZv9t6x5wBrh7XM0anPhRXILJMtOSnOHfUIro5kbbvsDIC5f3LUbpm6AY93tkiV+S K65z2s2CniAxHPDjGw5y8QeuHxrzSBoH4IXF2YOIV/d91NR65czcXHvNKOgBZwjX/wCz F0dxVJZpRtJcGOKKjsYMPZK+LoPfeWCEVhfa3nxL86qOpAQIYMy556BSibO2vaVmNHZC GgHeduFSBpaL84Xp8Tfnv5OaTayKA6H2PM8YNqJKKpGh24wdm1pfSxzXZg9tLnzAPykK q3b+QEBx+tLNt7oNvW9eGv28Wt2wDc6Nx9vfu9/tbgZPMD0lSd+G2pLCa9JLb5PRp0jc 5i6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FmZWuyzXgdUwXVfXnARqmGSbKSR4TizqVD3AQkgzi7A=; b=nEc/v7QFpKC+iPZNdTYh7vnvRr6APSWYJwdJpLa8J+RxoeF8ID5a9AM0foe3mqYxyv jN8hgJ8GAALdfrpRw597d443K8PpnpR8bGp1oz96Er28ijhwLB1/0wNKj0BVeoleXO80 1LUGojk6/S/Gwj0dPemwEud1LaWUplVyQOqXuN7s6GFHDs+UCHZ2LczFf/kMZWCboSVa 1q4+AgsWzUXccZICeiE/yPijIt5sOvM77Vme8Ta20OlRNIAotGGFbqnTjyuMQ+/TGX9D PhrWqskEv/Aoe+2OsmH5okt8jAxP3uCwuAZW+PkAJsqGGPeJ4rn1KnKi8FZKZU/w6MBg CT4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cjH5XczQ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si2554pjo.48.2019.08.28.11.22.43; Wed, 28 Aug 2019 11:22:59 -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=@gmail.com header.s=20161025 header.b=cjH5XczQ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726749AbfH1SUW (ORCPT + 99 others); Wed, 28 Aug 2019 14:20:22 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34526 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726315AbfH1SUW (ORCPT ); Wed, 28 Aug 2019 14:20:22 -0400 Received: by mail-wr1-f65.google.com with SMTP id s18so800301wrn.1; Wed, 28 Aug 2019 11:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=FmZWuyzXgdUwXVfXnARqmGSbKSR4TizqVD3AQkgzi7A=; b=cjH5XczQkjoLXAo9dkBLhKq20RtyY9fv4ghF7e1qpWBvIxybqCfhA3qCAMgUQ8Rzkn pj7rROP+H8jD6TarciOB4LYpgmkEzXuUHzYkXX/FBKSkQLUpDwvLuaEwYWFHNWIPENLi lMySAoseWH5KlSvhgzeK+H7mwd0wRm8trpKfCft25wz8Lc3AWAAJR8YSoup0hJzj8P3d uFM434Z3y9YdIy8LSeKV7dgtGAM7Dkr7xaixS2/Lstv6kHusOCLDM1a41mX+rTQYEz1t GHVPbubqLxnLNltylFQ0ZaKbwS+WJhaWN46v4YL1fOBiKRBnlOfNM69poca9rpSyMUfI qUhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=FmZWuyzXgdUwXVfXnARqmGSbKSR4TizqVD3AQkgzi7A=; b=snbQoSkZzK8C73sMt3xjpfJ9eMBK+udYtfnVe6gYIxIkjuNUINw++gmNGhG/smp+/F nnabEDa5ysdi6fcGCTuIRUDYziRP1X0+LMvklKx+Af05JcrYp1A05DxeJS2ZavdekyRD H+zQTA2HCYkS9xzQd0rrh7j+tt06w16v2AOnHKVm1P6ZmjX9gKAWfpawH/1Sb8G6BZPj c+hWiq2Y5QUh6gFRbLAid0fa5190x561t/4NMofOZWSdEV2JNYB17XaOdFFB4gKp1Adx 6q+gj9E8ofEdcvqVd7BAYV0CTDofehjFx+sczg2hUuAlp0JnbFJsPUS7OsTagW/4L9hH 5u+A== X-Gm-Message-State: APjAAAU8m/SyT6AM8SYx81iYteOgdiH/XHZF7cIsYGwocYtWT7KzFWOI 81Si+iLp98dVRnrNb9awVvSG1GkR02iWSw== X-Received: by 2002:adf:8541:: with SMTP id 59mr6357653wrh.298.1567016419538; Wed, 28 Aug 2019 11:20:19 -0700 (PDT) Received: from archlinux-threadripper ([2a01:4f8:222:2f1b::2]) by smtp.gmail.com with ESMTPSA id o3sm2017589wrv.90.2019.08.28.11.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2019 11:20:18 -0700 (PDT) Date: Wed, 28 Aug 2019 11:20:17 -0700 From: Nathan Chancellor To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, Nick Desaulniers , Miguel Ojeda , Arnd Bergmann , Kees Cook , Luc Van Oostenryck , Michal Marek , Sven Schnelle , Xiaozhou Liu , clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] kbuild: allow Clang to find unused static inline functions for W=1 build Message-ID: <20190828182017.GB127646@archlinux-threadripper> References: <20190828055425.24765-1-yamada.masahiro@socionext.com> <20190828055425.24765-2-yamada.masahiro@socionext.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190828055425.24765-2-yamada.masahiro@socionext.com> User-Agent: Mutt/1.12.1 (2019-06-15) 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 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. > > 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. > > 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! Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor