Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S944082AbcJSPMt (ORCPT ); Wed, 19 Oct 2016 11:12:49 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:50534 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S942558AbcJSPMr (ORCPT ); Wed, 19 Oct 2016 11:12:47 -0400 From: Arnd Bergmann To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Will Deacon , Peter Zijlstra , Stephen Boyd , "linux-kernel@vger.kernel.org" , james.greenhalgh@arm.com, Gregory CLEMENT , Linus Torvalds , Ingo Molnar Subject: Re: Build failure with v4.9-rc1 and GCC trunk -- compiler weirdness Date: Wed, 19 Oct 2016 17:11:40 +0200 Message-ID: <4333753.kxspqi1Miz@wuerfel> User-Agent: KMail/5.1.3 (Linux/4.4.0-34-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: References: <20161017183806.GG5601@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:TtROb5iEhl7vckl8QneHmSRKrtfwkUk9eTK1/bM45aTgFK2LXQ8 imtTS7Nt4obuYDdcNfkoXUVjglv7RSOcbsNsW6Os4YPZEfSk2EKs0encZUpSRETt6nMkQXF dLWHR40eWHRVOcp6jVczBE0EnGCDoAmj3ltiCkKrfI61TJDK3uJViDI2jDRN4ZwkkqLTWHb rJL/JmSv+zf5BNtFulI3w== X-UI-Out-Filterresults: notjunk:1;V01:K0:jCpJNoSRAf4=:qwYRL091g+sY5caULZDBD1 k+SPsKrm/ny5WiHxPkSm0EqIByoCCfMe6eQw9er3o30YVltrTqQxqTUTvpXyxBTRuEsZNUupG Ihvf1TDhzsIcT0EkiaOLwfrktFeEhxbD1aZz85CpUXR6ZY0znSVowir1g0V5Wdfkqxscqh+uW 6GwBD26bgLcga8rjEkQNQ8To54ukIRD8ZMCQDFBEFkFjGKr+sWkTqdL0PPFxf/AMx5LPKSfwp r7noHWjAG/zZOlLEVeaXysSpuzydivdB++ykau6mCQbiuHv8HhdfgVwjm+h7jyZenwa8sFPaT C8323vPD+Bd9Cjs2PM9/7me6a7bmSpyXQigRr5WQRlSMer2UCd//aNOGYzS/8r8OElO8wFFTa CgrZO+uLZK/NHLv8llgT8gQ9sjkAPgOqbwXYHSFa06FmVIashWqfs1OEvpwPFfXgmYH0sOMJ3 xU+Lrv+uFUbSCMZR4fwqhe5cLUmSxsJ0yZ9W1XeVQe4+xKPxaBaa9k0Pgu5XXWNwS7FkradI8 lzc5QEbVaPrugngcpp1QEpQ8q9if/6E2eCHB5aclufIXVBWNJ20IxOzzitYbXdHxasZTb1cOm MObnHe9xCTU8PeRdU5Iqf4BDZavS6zd78ddCxlXKDvrw67ZHF2UgyIfMpNvPG/9xkASx+17Lp JYrJW8axRP0+sDkPLieEnBg2r3TF2rp2IWVLK4HYbf3F8p3ueAjSNUi/8xBvp9AENkhEWkhiu 8p9PZjrJ/9+XcpyB Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2505 Lines: 58 On Wednesday, October 19, 2016 4:01:58 PM CEST Ard Biesheuvel wrote: > On 19 October 2016 at 15:59, Ard Biesheuvel wrote: > > On 19 October 2016 at 14:35, Will Deacon wrote: > >> On Mon, Oct 17, 2016 at 08:43:19PM +0100, Ard Biesheuvel wrote: > >>> On 17 October 2016 at 19:38, Will Deacon wrote: > > > > Yes, and that would be perfectly legal from a correctness point of > > view, and would likely help performance as well. By using > > __builtin_constant_p(), you are choosing to perform a build time > > evaluation of an expression that would ordinarily be evaluated only at > > runtime. This implies that you have to address undefined behavior at > > build time rather than at runtime as well. > > > >>> If order_base_2() is not defined for input 0, it should BUG() in that > >>> case, and the associated __builtin_unreachable() should prevent the > >>> special version from being emitted. If order_base_2() is defined for input > >>> 0, it should not invoke ilog2() with that argument, and the problem should > >>> go away as well. > >> > >> I don't necessarily think it should BUG() if it's not defined for input > >> 0; things like __ffs don't do that and we'd be introducing conditional > >> checks for cases that should not happen. The comment above order_base_2 > >> does suggest that ob2(0) should return 0, but it can actually end up > >> invoking ilog2(-1), which is obviously wrong. > >> > >> I could update the comment, but that doesn't fix the build issue. > >> > > > > Fixing roundup_pow_of_two() [which is arguably incorrect] > > I just spotted the comment that says it is undefined. But that means > it could legally return 1 for input 0, i suppose I think having the link error in roundup_pow_of_two() is safer than returning 1. Why not turn it into a runtime warning in this driver? diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c index cecb0fdfaef6..711d1d9842cc 100644 --- a/drivers/clk/mvebu/armada-37xx-periph.c +++ b/drivers/clk/mvebu/armada-37xx-periph.c @@ -349,8 +349,10 @@ static int armada_3700_add_composite_clk(const struct clk_periph_data *data, rate->reg = reg + (u64)rate->reg; for (clkt = rate->table; clkt->div; clkt++) table_size++; - rate->width = order_base_2(table_size); - rate->lock = lock; + if (!WARN_ON(table_size == 0)) { + rate->width = order_base_2(table_size); + rate->lock = lock; + } } } Arnd