Re: [PATCH 2/15 v2] Unhardcode byte size being 8 bits.

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

 





Alexey ,

unsigned long test1(void *p)
{
        return sizeof(*p);
}
TBH, I don't think that's legal --- I know of several compilers that
will refuse to compile it, and gcc -pedantic produces a warning, which
means it probably falls into the 'undefined behaviour' bucket of the
standard. I can't find anything that specifically talks about sizeof
void, but 6.3.2.2.1 prohibits doing *anything* with the result of an
expression of type void, which sort of applies here.

Of course, I'm thinking about this from the sparse-as-a-compiler point
of view, where you're probably more interested in replicating gcc's
behaviour.

This seems to be legal, and quite popular in the Linux kernel. GNU C defines
sizeof(void) being 1.And as it has the -Wpointer-arith flag, this kind of stuff
may be caught without sparse if deemed undesirable.

It is a constraint violation.

"The sizeof operator shall not be applied to an expression that has function type or an incomplete type"

sentence 1118: c0x.coding-guidelines.com/6.5.3.4.html

void is an incomplete type that cannot be completed
sentence 524: c0x.coding-guidelines.com/6.2.5.html

In pre-C90 days, prior to the availability of void, char * was
often used in a context where void * is now used.  Treating void
as being equivalent to char in some kind of compatibility mode
makes sense.  It looks like the gcc maintainers have over stepped
the mark.

I have reported the bug in gcc.  Track Bug: 38563
at: gcc.gnu.org/bugzilla

--
Derek M. Jones                         tel: +44 (0) 1252 520 667
Knowledge Software Ltd                 mailto:derek@xxxxxxxxxxxx
Source code analysis                   http://www.knosof.co.uk
--
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