Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp6068961ybl; Tue, 27 Aug 2019 13:59:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPQv/FBfwh87Qy0DrrhzNLtjuJaFQNgL0T1K87Xs9V95SK6j3kyJlQW0/BQ7A8ElpTY+k0 X-Received: by 2002:a17:90a:7f01:: with SMTP id k1mr691915pjl.84.1566939579396; Tue, 27 Aug 2019 13:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566939579; cv=none; d=google.com; s=arc-20160816; b=T6WPGIavdOjQLIPDbvABYWvziThf2VwPIAOwniYIMFueVS6peHdQ/4SXdX1KSblF/+ gLbQJJCT7ed0CWiRceQJQRn6L7EeJxFVroRhVFFBthaRj///Oq+4S9smgcu5+TTdEO6K +KekX8o51/1lDEX6QwV1sUlF37lwoUHtnkaEfH01EQnAnun867JKvcrAUZpPsjKXP0kF VeVJ5ZYA5OPIaX3PZvmJGH8tf41OVbN45BP62YPbJehEts5/A3PmuXvvzMKkWGetRY4M 8iwPyhXNmrExRd0lPCPla6YnDyaSvk2AzV6FIk1njAnKNjMdlzt2OEqIb3LKM3Hc6YPM IiVQ== 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=TXjsSAJv8McRWlbUcLkirZ2NM0D/RICs3+Zd+E1Xf+I=; b=Au4NSUxc6Q2jWXPx7zdtozzNml5FFefcXBxuVVDBQEkkm4+ohPHaf1Q4+JitSXaBwz yMyQkYk4inbBiZyGDKB45q+U3G2ND/phIOwH56f6NwCJgnRaQNBWjLsbUpvdYgio12y6 ZN+JemEiDf06M8nW//s4XSM2PDUMB2qQ7oUQU/enmNzEnwtfNGbk34emEcsDWjCfNepE LuhrBIyD9xBWbdsTLevsCA/kEfnWfKq4fDjChca7MlFqiiN5PcWKM/ZjC3TJMwBsWq+E 94WfKJcCQIROHGep2qf6ZXhFdpXETizYvIgrguBgFrX0yS08F5+prJnTC6fRZvk0CabN HsHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=bXg67KvM; 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 d8si137099pla.206.2019.08.27.13.59.23; Tue, 27 Aug 2019 13:59:39 -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=bXg67KvM; 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 S1730142AbfH0U6S (ORCPT + 99 others); Tue, 27 Aug 2019 16:58:18 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35424 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727887AbfH0U6S (ORCPT ); Tue, 27 Aug 2019 16:58:18 -0400 Received: by mail-pf1-f196.google.com with SMTP id d85so193334pfd.2 for ; Tue, 27 Aug 2019 13:58:17 -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=TXjsSAJv8McRWlbUcLkirZ2NM0D/RICs3+Zd+E1Xf+I=; b=bXg67KvMUzP60s0lVOxa4LPBAQxRnuEVPFTxoqhYno0kLCiiROzohMHKdhZTLYsKG7 Y1EMSRv8gJaWxAcaIVota4/JNiPku5TKZHgtQugBcVPtNLd7kuDHhQ+o1Uc/I8Q2gNY8 STBEjbGEf+otmPLiXl178YjOVzCYczBqgvy2ph9MLrwPXnDHn/o7QZ2lR9IbX2z6dN0m eae3er9tpRzQ/FBfiKfizwuhBpCE76p2uezoeMTGcSSOusd7HDOX96N1mwMwA8pdOT3y oxwMlheyCG73kV0pUtcOr5UsHVYiM+zqdqpHUyaP4/L9s0760Y8ceb2nsOiV1n6nY7qU tAgg== 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=TXjsSAJv8McRWlbUcLkirZ2NM0D/RICs3+Zd+E1Xf+I=; b=q5p8yuc4pO4bOx2UEYNANoeVeG4BSfStjDpFwpsRWsxxAoECcPCX1VEBVfUlbF2GLe hb9h//09/Zb+0Krn3VfbJpJrEL9M1PtgzZhxXLPFqzzcx2YX6ZSh6vdntoR/n/RUjadO VP68Ab4I7ppfvXQBDgxEowjBvsXHyIO0yDmJvOD7/qUqhSpauaaOHgiqJ0yMENL/hYkM Y8GAUrRvEAIwZHRglsCXdDX4cWBGOOz3DzHHir55aUygA25ktk9cumfWnSK1fohTN83h jCGgehjc9RBQsky5cWpzTVKaf1sql3ZT3anGucMbVHE6gEjAyk+Z5fzCQlPJksK1gNy8 bV7Q== X-Gm-Message-State: APjAAAXrMHDGVtaN5UCERZXM2K8Mx9akYPEOKIHdla8iP6W0bsWPdfHf M8ZiReb8I2IkL7UsJ7jpa7wXnB4WUSUWBB/vkF0wEQ== X-Received: by 2002:a63:61cd:: with SMTP id v196mr330561pgb.263.1566939496499; Tue, 27 Aug 2019 13:58:16 -0700 (PDT) MIME-Version: 1.0 References: <20190827103621.1073-1-yamada.masahiro@socionext.com> <20190827192811.GA24626@archlinux-threadripper> In-Reply-To: <20190827192811.GA24626@archlinux-threadripper> From: Nick Desaulniers Date: Tue, 27 Aug 2019 13:58:05 -0700 Message-ID: Subject: Re: [PATCH v2] kbuild: enable unused-function warnings for W= build with Clang To: Nathan Chancellor Cc: Masahiro Yamada , Linux Kbuild mailing list , Arnd Bergmann , Michal Marek , 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 Tue, Aug 27, 2019 at 12:28 PM Nathan Chancellor wrote: > > On Tue, Aug 27, 2019 at 07:36:21PM +0900, Masahiro Yamada wrote: > > GCC and Clang have different policy for -Wunused-function; GCC never > > reports unused-function warnings for 'static inline' functions whereas > > Clang reports them 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 remove 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. As always, it is not a > > good idea to sprinkle warnings for the normal build, so I added > > -Wno-unsued-function for no W= build. s/unsued/unused/ > > > > Per the documentation [1], -Wno-unused-function will also disable > > -Wunneeded-internal-declaration, which can help find bugs like > > commit 8289c4b6f2e5 ("platform/x86: mlx-platform: Properly use > > mlxplat_mlxcpld_msn201x_items"). (pointed out by Nathan Chancellor) > > I added -Wunneeded-internal-declaration to address it. > > > > 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's optimization. I prefer __maybe_unused or #ifdef around the > > definition. I'd say __maybe_unused for function parameters that are used depending of ifdefs in the body of the function, otherwise strictly ifdefs. > > > > [1]: https://clang.llvm.org/docs/DiagnosticsReference.html#wunused-function > > > > Signed-off-by: Masahiro Yamada > > Reviewed-by: Kees Cook > > I am still not a big fan of this as I think it weakens clang as a > standalone compiler but the change itself looks good so if it is going > in anyways: > > Reviewed-by: Nathan Chancellor > > I'm sure Nick would like to weigh in as well before this gets merged. So right away for an x86_64 defconfig w/ this patch, clang points out: drivers/gpu/drm/i915/i915_sw_fence.c:84:20: warning: unused function 'debug_fence_init_onstack' [-Wunused-function] static inline void debug_fence_init_onstack(struct i915_sw_fence *fence) ^ drivers/gpu/drm/i915/i915_sw_fence.c:105:20: warning: unused function 'debug_fence_free' [-Wunused-function] static inline void debug_fence_free(struct i915_sw_fence *fence) ^ The first looks fishy (grep -r debug_fence_init_onstack), the second only has a callsite ifdef CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS. drivers/gpu/drm/i915/intel_guc_submission.c:1117:20: warning: unused function 'ctx_save_restore_disabled' [-Wunused-function] static inline bool ctx_save_restore_disabled(struct intel_context *ce) ^ drivers/gpu/drm/i915/display/intel_hdmi.c:1696:26: warning: unused function 'intel_hdmi_hdcp2_protocol' [-Wunused-function] enum hdcp_wired_protocol intel_hdmi_hdcp2_protocol(void) ^ arm64 defconfig builds cleanly, same with arm. Things might get more hairy with all{yes|mod}config, but the existing things it finds don't look insurmountable to me. In fact, I'll file bugs in our issue tracker (https://github.com/ClangBuiltLinux/linux/issues) for the above. So I'm not certain this patch weakens existing checks. Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers -- Thanks, ~Nick Desaulniers