Re: bitwise enums

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 20, 2018 at 09:20:45AM -0800, Linus Torvalds wrote:
> On Tue, Feb 20, 2018 at 9:02 AM, Luc Van Oostenryck
> <luc.vanoostenryck@xxxxxxxxx> wrote:
> > On Tue, Feb 20, 2018 at 08:09:39AM -0800, Matthew Wilcox wrote:
> >>
> >> I have a feature request relating to bitwise and enums.  The following
> >> does not work the way I would like it to:
> >>
> >> typedef __attribute__((bitwise)) enum {
> >>       FOO,
> >>       BAR,
> >> } my_t;
> >>

> >> I think it would be appropriate for the __attribute__((bitwise)) to
> >> apply not just to 'my_t' but also to 'FOO' and 'BAR'.
> 
> Definitely.

One detail about the syntax: my understanding of the attribute
syntax is that in:
	typedef __bitwise enum foobar { FOO, BAR, } my_t;
which is essentially the same as:
	enum foobar { FOO, BAR, };
	typedef __bitwise enum foobar my_t;
the attribute relate to the typedef/my_t and not to the enum type.

It doesn't matter much later, when my_t is used, but it matters
for the initializers, for example in:
> >> typedef __attribute__((bitwise)) enum {
> >>       FOO = 1,
> >>       BAR = 2,
> >>       BAZ = 4,
> >>       QUUX = 8,
> >>       WIBBLE = 0x10,

So, I propose that what we should aim for is to support:
	enum __bitwise foobar { FOO, BAR, };
and, maybe:
	enum foobar { FOO, BAR, } __bitwise;
Both are equivalent following GGC's attribute's syntax but in
this case, I think the first is far better (and is easier).

> > Yes, it's reasonable and intuitive.
> > It would be nice to have Al Viro's option on this, though.
> 
> I'm pretty sure Al will agree, and it's just a matter of "it's a
> bug/not implemented".

I think, it's both. It's certainly not implemented but also there
is a least one bug (but I think several ones) related to attributes
and types. For example in type declaration like:
	struct s {
		int	a;
		int	b;
	} __aligned(8);

The __aligned() (or any other attribute) is simply ignored.
It's easy to fix but it then triggers another problem regarding
out-of-range access of bitfields in a struct with an __packed.
This late one need more work to fix (or we can simply silence
the corresponding warning for packed structs).

-- Luc
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux