Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4464635pxj; Wed, 12 May 2021 06:19:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/HY9m2KuM4A22Eqi3QV7IjVTbb38Cx/LjoGgmMF/Rd4FDpol+IfdgbWgWSZ2ylTEXAYUL X-Received: by 2002:a17:906:711a:: with SMTP id x26mr37411646ejj.125.1620825546644; Wed, 12 May 2021 06:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620825546; cv=none; d=google.com; s=arc-20160816; b=L0IXR0dBIpM/zShoVr382fwUbGqsww5UAafk41mFn4hufCf5dCz/WmyXq+t+vCaYEF TYHDeDGREUyxo01ZJk/xZHVu2013AlV7dXLbmjfDrIyq8iBLT3syi7OvO8wb/XaHdRpv eaw8XmM2pLLubXhL7E8X+HEAe2zo9VwFdcBz+PnmZLOXRKNnTjwsnMfL1+UMg3flP8eV jjFCgOepNJ1Efv/RSo4fQvtzCpR+ySBHMLwVCeJYuXnG7SuYoocXWAtlv6drfQay6HOX l17EdgSIzw8rEvH1ftOEfJEAPxnhFrwu/3MBdplMVsv9Q4STQM3y+Zh3doTyaY4JwlZz 9D6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=FO4+dB97+xluXBfg6w+S47oZbKpExaqHEOgXc4D6ICg=; b=GO12CIsS63BYanvX4QNSC6gTiGpm3Vt/IEh/7A3pq8lf/ha4iPouuiS+xBp3+zpwFw Lv75HL3wMACiFrwDdiaWTLlGxU0lymvK9xbaqGpj9ujFGLYm+D9Aomxkl8iwKCjzSV6A YcUrH7f25wOCIWheqJgrtu6mjn+5BC132vUy/WS1SzHn+RFmw5dYHB7N2VYY5yYzirdc en2KNnEm+JKqWLyUyRwehpzKBHWzjcfeUGKgVXl6bDu/rXXFomBZcDeuhIMWRAiAQQis BWp4AiJ1aTTAU9t9kO3TnCXayIPPnSFyQCKH2TGsj2pBwF6wAh+WZbecLVwq4ByyL7U6 +Izw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mBs5vpI7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hj20si3355221ejb.1.2021.05.12.06.18.42; Wed, 12 May 2021 06:19:06 -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=@kernel.org header.s=k20201202 header.b=mBs5vpI7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232925AbhELM4j (ORCPT + 99 others); Wed, 12 May 2021 08:56:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:55656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232920AbhELMys (ORCPT ); Wed, 12 May 2021 08:54:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9D06F613FB for ; Wed, 12 May 2021 12:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620824019; bh=XbmRrReojneENbPSOsU6jBGRBw9yRA5UpTwIcpDkSpc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mBs5vpI7hBKzuA1pOJxQSwbXVzF+V9ogB1ilzujPFM0oCf9q7/JCDjWMRVFNZJyl8 r06bViLCittI0TwmSi8TpCkueNZJ5cM7eu4PKjsw8vupJT3Cq05ei/aFDXeEvsHvms WrIAIRi0ZqdTNjCUHztmgTezzmHcQ5bbEIOe3gAGNqYn/aQuaBq2Erw1/qXfdJ0Hvd kfEBKC9pF3YnUc+wG1YE3ilgWv1nwyLHtoSDGccGKR2r3DBrI7rLlAHzb//SyrPbEt YcsqNsWw6ZlkmKmPobQpgFGPeQKf4HJ1MomKgMWg6wfiOuXLAXvYYHvUtTezrMUrwC spqYkPMAWV4KA== Received: by mail-ot1-f49.google.com with SMTP id r26-20020a056830121ab02902a5ff1c9b81so20435136otp.11 for ; Wed, 12 May 2021 05:53:39 -0700 (PDT) X-Gm-Message-State: AOAM530N44hWeGVKAS0a4sCOMoECv6tGuiokypEI+v9J0c9Dhl3qmLGL EbHYHAVu7TzT4alqRyyO2iFP+AzBzRMljd9pH0o= X-Received: by 2002:a05:6830:4da:: with SMTP id s26mr30389717otd.77.1620824018741; Wed, 12 May 2021 05:53:38 -0700 (PDT) MIME-Version: 1.0 References: <20210511203716.117010-1-rikard.falkeborn@gmail.com> In-Reply-To: <20210511203716.117010-1-rikard.falkeborn@gmail.com> From: Ard Biesheuvel Date: Wed, 12 May 2021 14:53:27 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] linux/bits.h: Fix compilation error with GENMASK To: Rikard Falkeborn , Arnd Bergmann Cc: Andrew Morton , Andy Shevchenko , Tetsuo Handa , Yury Norov , Linux Kernel Mailing List , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (+ Arnd) On Tue, 11 May 2021 at 22:37, Rikard Falkeborn wrote: > > GENMASK() has an input check which uses __builtin_choose_expr() to enable > a compile time sanity check of its inputs if they are known at compile > time. However, it turns out that __builtin_constant_p() does not always > return a compile time constant [0]. It was thought this problem was fixed > with gcc 4.9 [1], but apparently this is not the case [2]. > > Switch to use __is_constexpr() instead which always returns a compile > time constant, regardless of its inputs. > > [0]: https://lore.kernel.org/lkml/42b4342b-aefc-a16a-0d43-9f9c0d63ba7a@rasmusvillemoes.dk > [1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19449 > [2]: https://lore.kernel.org/lkml/1ac7bbc2-45d9-26ed-0b33-bf382b8d858b@I-love.SAKURA.ne.jp > > Reported-by: Tetsuo Handa > Signed-off-by: Rikard Falkeborn > --- > Feedback on placing __is_constexpr() in const.h is welcome, at least the > name is appropriate... > > include/linux/bits.h | 2 +- > include/linux/const.h | 8 ++++++++ > include/linux/minmax.h | 10 ++-------- > tools/include/linux/bits.h | 2 +- > tools/include/linux/const.h | 8 ++++++++ > 5 files changed, 20 insertions(+), 10 deletions(-) > > diff --git a/include/linux/bits.h b/include/linux/bits.h > index 7f475d59a097..87d112650dfb 100644 > --- a/include/linux/bits.h > +++ b/include/linux/bits.h > @@ -22,7 +22,7 @@ > #include > #define GENMASK_INPUT_CHECK(h, l) \ > (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ > - __builtin_constant_p((l) > (h)), (l) > (h), 0))) > + __is_constexpr((l) > (h)), (l) > (h), 0))) > #else > /* > * BUILD_BUG_ON_ZERO is not available in h files included from asm files, > diff --git a/include/linux/const.h b/include/linux/const.h > index 81b8aae5a855..435ddd72d2c4 100644 > --- a/include/linux/const.h > +++ b/include/linux/const.h > @@ -3,4 +3,12 @@ > > #include > > +/* > + * This returns a constant expression while determining if an argument is > + * a constant expression, most importantly without evaluating the argument. > + * Glory to Martin Uecker > + */ > +#define __is_constexpr(x) \ > + (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) > + > #endif /* _LINUX_CONST_H */ > diff --git a/include/linux/minmax.h b/include/linux/minmax.h > index c0f57b0c64d9..5433c08fcc68 100644 > --- a/include/linux/minmax.h > +++ b/include/linux/minmax.h > @@ -2,6 +2,8 @@ > #ifndef _LINUX_MINMAX_H > #define _LINUX_MINMAX_H > > +#include > + > /* > * min()/max()/clamp() macros must accomplish three things: > * > @@ -17,14 +19,6 @@ > #define __typecheck(x, y) \ > (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) > > -/* > - * This returns a constant expression while determining if an argument is > - * a constant expression, most importantly without evaluating the argument. > - * Glory to Martin Uecker > - */ > -#define __is_constexpr(x) \ > - (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) > - > #define __no_side_effects(x, y) \ > (__is_constexpr(x) && __is_constexpr(y)) > > diff --git a/tools/include/linux/bits.h b/tools/include/linux/bits.h > index 7f475d59a097..87d112650dfb 100644 > --- a/tools/include/linux/bits.h > +++ b/tools/include/linux/bits.h > @@ -22,7 +22,7 @@ > #include > #define GENMASK_INPUT_CHECK(h, l) \ > (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ > - __builtin_constant_p((l) > (h)), (l) > (h), 0))) > + __is_constexpr((l) > (h)), (l) > (h), 0))) > #else > /* > * BUILD_BUG_ON_ZERO is not available in h files included from asm files, > diff --git a/tools/include/linux/const.h b/tools/include/linux/const.h > index 81b8aae5a855..435ddd72d2c4 100644 > --- a/tools/include/linux/const.h > +++ b/tools/include/linux/const.h > @@ -3,4 +3,12 @@ > > #include > > +/* > + * This returns a constant expression while determining if an argument is > + * a constant expression, most importantly without evaluating the argument. > + * Glory to Martin Uecker > + */ > +#define __is_constexpr(x) \ > + (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) > + > #endif /* _LINUX_CONST_H */ > -- > 2.31.1 >