From: Jakub Jelinek <jakub@redhat.com>
To: Michael Karcher <kernel@mkarcher.dialup.fu-berlin.de>
Cc: Randy Dunlap <rdunlap@infradead.org>,
linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org,
Segher Boessenkool <segher@kernel.crashing.org>,
Rich Felker <dalias@libc.org>,
Yoshinori Sato <ysato@users.osdn.me>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
jakub@gcc.gnu.org
Subject: Re: [PATCH: 1/1] sh4: avoid spurious gcc warning
Date: Sun, 22 Jan 2023 13:42:44 +0100 [thread overview]
Message-ID: <Y80vRJfPJ4mIO8Cm@tucnak> (raw)
In-Reply-To: <c74cad7b-9ea3-5223-8292-3fe1172a9419@mkarcher.dialup.fu-berlin.de>
On Sun, Jan 22, 2023 at 12:33:41PM +0100, Michael Karcher wrote:
> Am 22.01.2023 um 08:00 schrieb Randy Dunlap:
> > > -#define _INTC_ARRAY(a) a, __same_type(a, NULL) ? 0 : sizeof(a)/sizeof(*a)
> > > +#define _INTC_ARRAY(a) a, sizeof(a)/(_Generic((a), typeof(NULL): 0xFFFFFFFFU, default: sizeof(*a)))
> > s/: / : / in 2 places.
> >
> > Tested-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
>
> Thanks for your confirmation! Are you sure about the space before the colon?
No, it should be without those, see various other _Generic uses in
include/linux/
All those are formatted on one line for each case, so for the above macro it
would be
#define _INTC_ARRAY(a) (a), sizeof(a)/(_Generic((a), \
typeof(NULL): -1, \
default: sizeof(*(a)))
or so.
Anyway, two comments:
1) I'd use -1 as that would be after promotion to size_t the largest size_t
unlike 0xFFFFFFFFU; of course, as for the void * case a can't be an array,
any value > sizeof(void*) will do
2) if *a and a is fine (i.e. argument of the macro has to be really simple or
wrapped in ()s, then perhaps (a) as first operand to _Generic isn't needed
either, or use (a) in the two spots (sizeof(a) is of course fine) and
*(a)
> The colon in this case terminates a case descriptor for the type-level
> switch construction using "_Generic". It says: "In case 'a' has the 'type of
> NULL', divide by 0xFFFFFFFFU, in all other cases, divide by the size of a
> single array element". It's not a colon of the ternary ?: operator, in which
> case I would agree with the space before it.
>
> If you confirm that you want a space before the colon in this case as well,
> I'm going to add it, though.
>
> > How far back in gcc versions does this work?
>
> I tested the support of _Generic on Compiler Explorer at godbolt.org. This
> construction is rejected by gcc 4.8, but accepted by gcc 4.9.
Yeah, introduced in gcc 4.9, as I think kernel minimum version is 5.1, that is fine.
And various headers already use _Generic.
Jakub
next prev parent reply other threads:[~2023-01-22 12:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-22 0:15 [PATCH: 1/1] sh4: avoid spurious gcc warning Michael.Karcher
2023-01-22 7:00 ` Randy Dunlap
2023-01-22 11:33 ` Michael Karcher
2023-01-22 12:42 ` Jakub Jelinek [this message]
2023-01-22 16:02 ` Randy Dunlap
2023-01-23 14:49 ` Geert Uytterhoeven
2023-01-22 12:35 ` John Paul Adrian Glaubitz
[not found] ` <c411961861df4ae4b011317ff2c3c7df@AcuMS.aculab.com>
2023-01-23 16:11 ` Jakub Jelinek
2023-01-23 18:00 ` Michael Karcher
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=Y80vRJfPJ4mIO8Cm@tucnak \
--to=jakub@redhat.com \
--cc=dalias@libc.org \
--cc=glaubitz@physik.fu-berlin.de \
--cc=jakub@gcc.gnu.org \
--cc=kernel@mkarcher.dialup.fu-berlin.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=rdunlap@infradead.org \
--cc=segher@kernel.crashing.org \
--cc=ysato@users.osdn.me \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.