lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 22 Jan 2023 13:42:44 +0100
From:   Jakub Jelinek <jakub@...hat.com>
To:     Michael Karcher <kernel@...rcher.dialup.fu-berlin.de>
Cc:     Randy Dunlap <rdunlap@...radead.org>, linux-kernel@...r.kernel.org,
        linux-sh@...r.kernel.org,
        Segher Boessenkool <segher@...nel.crashing.org>,
        Rich Felker <dalias@...c.org>,
        Yoshinori Sato <ysato@...rs.osdn.me>,
        John Paul Adrian Glaubitz <glaubitz@...sik.fu-berlin.de>,
        jakub@....gnu.org
Subject: Re: [PATCH: 1/1] sh4: avoid spurious gcc warning

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@...radead.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ