From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753607AbdCMStP (ORCPT ); Mon, 13 Mar 2017 14:49:15 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:33818 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751012AbdCMStF (ORCPT ); Mon, 13 Mar 2017 14:49:05 -0400 Date: Mon, 13 Mar 2017 11:49:01 -0700 From: Matthias Kaehlcke To: Heiko Stuebner Cc: Elaine Zhang , Caesar Wang , Shawn Lin , Douglas Anderson , Grant Grundler , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1] soc: rockchip: power-domain: Fix clang warning about negative shift count Message-ID: <20170313184901.GB50582@google.com> References: <20170311022153.139362-1-mka@chromium.org> <1715023.AuHs9buZxh@phil> <20170313172222.GA50582@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20170313172222.GA50582@google.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org El Mon, Mar 13, 2017 at 10:22:22AM -0700 Matthias Kaehlcke ha dit: > El Sat, Mar 11, 2017 at 01:03:48PM +0100 Heiko Stuebner ha dit: > > > Hi Matthias, > > > > Am Freitag, 10. März 2017, 18:21:53 CET schrieb Matthias Kaehlcke: > > > The following warning is generated when building with clang: > > > > > > drivers/soc/rockchip/pm_domains.c:726:22: error: shift count is negative > > > [-Werror,-Wshift-count-negative] [RK3399_PD_TCPD0] = DOMAIN_RK3399(8, > > > 8, -1, false), > > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > drivers/soc/rockchip/pm_domains.c:101:2: note: expanded from macro > > > 'DOMAIN_RK3399' DOMAIN(pwr, status, req, req, req, wakeup) > > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > drivers/soc/rockchip/pm_domains.c:88:27: note: expanded from macro 'DOMAIN' > > > .req_mask = (req >= 0) ? BIT(req) : 0, \ > > > ^~~~~~~~ > > > include/linux/bitops.h:6:24: note: expanded from macro 'BIT' > > > > > > The BIT macro is evaluated with the negative value -1, even though the > > > resulting value would not be assigned. To fix this we only pass values > > > between 0 and 63 to BIT(). Unfortunately this means that we lose the > > > benefit of the compiler checking for out of bounds errors. > > > > I tend to disagree here. This looks more like a case of "fix your compiler". > > > > That conditional seems perfectly valid as the BIT(req) will never be reached > > if req < 0 - your clang simply doesn't recognize the pattern somehow, while > > for example gcc does. > > My interpretation is that with clang the '(req >= 0) ?' condition is > not evaluated by the preprocessor, but only by the compiler. This seems to > be different with gcc. > > > Catering to specific whims of specific compilers feels somehow wrong, as what > > will happen if some imaginary third compiler requires another different hack > > to be satisfied? > > I'll check with the clang developers if clang can be changed to behave > like gcc in this aspect. FYI: "We currently don't construct control-flow graphs (CFGs) when processing initializer expressions in a global context. CFGs have been used for doing a variety of flow-based warnings in functions, but at this point they haven't been used for global initializer expressions." https://bugs.llvm.org//show_bug.cgi?id=10030 m.