Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp612247pxb; Sat, 11 Sep 2021 15:37:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqXPd7yWmZ9Xg+wQyXFGEOYfWN4+VSa1Kdc3A+Q9RXsYAvS7dmoF2xmNVsVB5w50QNb4Et X-Received: by 2002:a17:906:8517:: with SMTP id i23mr4495505ejx.367.1631399871208; Sat, 11 Sep 2021 15:37:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631399871; cv=none; d=google.com; s=arc-20160816; b=vge+508BsK41QxztpeR9OQBgn7uNlD3A52c+Ph+sX9Zpe4e/xJMPhmFVM1goAewesy 3c2Oy8unnV7oPGn3/bSCzNua0hiXKHvVTZ+6ESWsULOG39Umy4WcF22Qzw0NeiVGfmmi nxUf1a1jGli6aBpudkDteVgvC83GocS4ZrvSoSiP+2kzrKYfnrCx5A5L1jIs18r6TQGA eOrVCrxYI72DR9fbN09eaPL1QyL+S/15qYmkaOEu60OkzJZOqWCMcUpL3G7EwWxR7IZc wlpBurabBYXCCvkVulJ7U/tTSASKrtBXmkjIiTPQg4iaQYFxLx6DohRtdLoQBCILtzVG yc/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XVZFgr0/IpI6HZ5BddTEu3Nz+x0vlNCd5Qh7W6ZME/U=; b=GsGRGjcl8If5NUX1oGcK4BhnqH97AuZWAPuKrF4S9Z6nz9A24vh6vPINoMYRQeI7FA zy0/qFUbrtVyeOWt/E+tIRFT+WmiXNqDy0iW52JA/mLcjhpcvu7SCLXZ+3HMmJARCkWF 6An8HbSs14pZwF9LRUNSAzlzKIZ8IiWi6tr+HVJLn24oVrF/BfqXeY6lWNx0sXRMDzkw hJA7d9xY8zdzVL+NAgQ8MXMszfSLrdsXAlaBO8dqCnzuoSJYLjnzCmAkkvZn9PHvgzCl bu4rndfOrnFP4zShi0PSMngmyqGHKkHXpYwsksOWCsLVadqj+wLwIvNgcBcs7lOndN9J nSLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LL22YaiU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k5si2682822edv.339.2021.09.11.15.37.25; Sat, 11 Sep 2021 15:37:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LL22YaiU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233613AbhIKWfL (ORCPT + 99 others); Sat, 11 Sep 2021 18:35:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbhIKWfK (ORCPT ); Sat, 11 Sep 2021 18:35:10 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9746FC061574; Sat, 11 Sep 2021 15:33:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=XVZFgr0/IpI6HZ5BddTEu3Nz+x0vlNCd5Qh7W6ZME/U=; b=LL22YaiURpoQEr7o3N1NVzgep/ eiWhD04rWYUoxlIQn1Z7/kmbJDJVB5Z6P2WwmEgnFFRfnLHWvIWLXH6HoWGahRo32myY8Zc3iWBpG oQJFG8hvhGCUX4HdMizpVknokkYZV41FBqsIWHpqhHragpz/2/+fcifuHK3MQGmwRiyQ9Nb+Wi4kV AsgLhjGCYnpA6x1DyG9Ow4pUrwZRha8ofuC2VZGyFYjUvBmkF0cbcLTj0sTb20LBkuse43V/QL9IA 5zGXGJs++e719NvRRIsQfo1vtMOoX6hUn8A8Xq+07lXvQaP0O/2qIkmylFsnYm0rF4R8E6JJ1qKd5 K7cVCUHg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPBYk-00CDmQ-Jd; Sat, 11 Sep 2021 22:33:26 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 70E439862C9; Sun, 12 Sep 2021 00:33:13 +0200 (CEST) Date: Sun, 12 Sep 2021 00:33:13 +0200 From: Peter Zijlstra To: Segher Boessenkool Cc: kernel test robot , Yafang Shao , kbuild-all@lists.01.org, linux-kernel@vger.kernel.org, linux-toolchains@vger.kernel.org Subject: Re: [peterz-queue:sched/core 13/19] kernel/sched/fair.c:892:34: warning: variable 'stats' set but not used Message-ID: <20210911223313.GC4323@worktop.programming.kicks-ass.net> References: <202109110214.oh62aoIq-lkp@intel.com> <20210911122049.GW4323@worktop.programming.kicks-ass.net> <20210911213041.GD1583@gate.crashing.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210911213041.GD1583@gate.crashing.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 11, 2021 at 04:30:41PM -0500, Segher Boessenkool wrote: > Hi! > > On Sat, Sep 11, 2021 at 02:20:49PM +0200, Peter Zijlstra wrote: > > On Sat, Sep 11, 2021 at 02:21:26AM +0800, kernel test robot wrote: > > > compiler: m68k-linux-gcc (GCC) 11.2.0 > > > > > kernel/sched/fair.c: In function 'update_curr': > > > kernel/sched/fair.c:860:42: warning: unused variable 'stats' [-Wunused-variable] > > > 860 | struct sched_statistics *stats = __schedstats_from_se(curr); > > > | ^~~~~ > > > > OK, compiler guys, this code reads like: > > > > #define schedstats_enabled() (0) > > #define __schedstat_set(x, y) do { } while (0) > > > > > > if (schedstats_enabled()) { > > struct sched_statistics *stats = __schedstats_from_se(curr); > > > > __schedstat_set(stats->exec_max, > > max(delta_exec, stats->exec_max)); > > } > > > > So yes, we initialize a variable that then isn't used, but the whole > > bloody thing is inside if (0) which will not ever get ran *anyway*. > > > > This is a crap warning if ever I saw one... > > Yes, we really should warn "do not use a preprocessor macro if what you > want is a function"? The variable really *is* unused, with this macro. Why would I want to write a bunch of one-off functions and preprocessor guard them? That's going to be a mess. > If we would remove dead code before warning about unused variables > there would be many *more* false positives, fwiw. Not if you also remove any variables declared in dead code and all variables only used in the dead code.