From: Qian Cai <cai@lca.pw>
To: David Howells <dhowells@redhat.com>
Cc: akpm@linux-foundation.org, davem@davemloft.net, arnd@arndb.de,
jakub@redhat.com, ndesaulniers@google.com, morbo@google.com,
jyknight@google.com, natechancellor@gmail.com,
linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] asm-generic: fix -Wtype-limits compiler warnings
Date: Wed, 24 Jul 2019 14:45:52 -0400 [thread overview]
Message-ID: <1563993952.11067.15.camel@lca.pw> (raw)
In-Reply-To: <31573.1563954571@warthog.procyon.org.uk>
On Wed, 2019-07-24 at 08:49 +0100, David Howells wrote:
> Qian Cai <cai@lca.pw> wrote:
>
> > Fix it by moving almost all of this multi-line macro into a proper
> > function __get_order(), and leave get_order() as a single-line macro in
> > order to avoid compilation errors.
>
> The idea was that you could compile-time initialise a global variable with
> get_order():
>
> int a = get_order(SOME_MACRO);
>
> This is the same reason that ilog2() is a macro:
>
> int a = ilog2(SOME_MACRO);
>
> See the banner comment on get_order():
>
> * This function may be used to initialise variables with compile time
> * evaluations of constants.
>
> If you're moving the constant branch into __get_order(), an inline function,
> then we'll no longer be able to do this and you need to modify the comment
> too. In fact, would there still be a point in having the get_order() macro?
>
> Also, IIRC, older versions of gcc see __builtin_constant_p(n) == 0 inside an
> function, inline or otherwise, even if the passed-in argument *is* constant.
I have GCC 8.2.1 which works fine.
# cat const.c
#include <stdio.h>
static int i = 0;
static inline void check()
{
if (__builtin_constant_p(i))
printf("i is a const.\n");
}
void main()
{
check();
}
# gcc -O2 const.c -o const
# ./const
i is a const.
next prev parent reply other threads:[~2019-07-24 18:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-23 20:49 [PATCH] asm-generic: fix -Wtype-limits compiler warnings Qian Cai
2019-07-23 21:27 ` Andrew Morton
2019-07-24 2:29 ` Nathan Chancellor
2019-07-24 7:49 ` David Howells
2019-07-24 18:45 ` Qian Cai [this message]
2019-07-24 21:49 ` David Howells
2019-07-25 3:22 ` Qian Cai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1563993952.11067.15.camel@lca.pw \
--to=cai@lca.pw \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=jakub@redhat.com \
--cc=jyknight@google.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=morbo@google.com \
--cc=natechancellor@gmail.com \
--cc=ndesaulniers@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox