public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Geoff Levand <geoffrey.levand@am•sony.com>
To: Linus Torvalds <torvalds@osdl•org>
Cc: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom•com>,
	Linux/PPC Development <linuxppc-dev@ozlabs•org>,
	linux-sparse@vger•kernel.org,
	Andrew Pinski <Andrew_Pinski@PlayStation•Sony.Com>
Subject: Re: cast truncates bits from constant value (8000000000000000 becomes 0)
Date: Fri, 01 Dec 2006 08:51:05 -0800	[thread overview]
Message-ID: <45705D79.6000107@am.sony.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0612010723190.3695@woody.osdl.org>

Linus Torvalds wrote:
> 
> On Fri, 1 Dec 2006, Geert Uytterhoeven wrote:
>>
>> On Tue, 21 Nov 2006, Geoff Levand wrote:
>> > +enum ps3_vendor_id {
>> > +	PS3_VENDOR_ID_NONE = 0,
>> > +	PS3_VENDOR_ID_SONY = 0x8000000000000000UL,
>> > +};
>> 
>> I've just ran `make C=1' (PPC in 64-bit mode, and sparse is called with -m64),
>> and noticed that sparse (cloned from
>> git://git.kernel.org/pub/scm/devel/sparse/sparse.git a few minutes ago)
>> complains about the second value with:
>> 
>> | warning: cast truncates bits from constant value (8000000000000000 becomes 0)
>> 
>> Section 6.7.2.2.4 of C99 says:
>> 
>> | Each enumerated type shall be compatible with char, a signed integer type, or
>> | an unsigned integer type. The choice of type is implementation-defined, but
>> | shall be capable of representing the values of all the members of the
>> | enumeration.
>> 
>> The code snippet
>> 
>> | u64 x = PS3_VENDOR_ID_SONY;
>> | printk("PS3_VENDOR_ID_SONY = %lu\n", x);
>> 
>> does print the expected (i.e. non-zero) result.
>> 
>> Hence this looks like a bug in sparse.
> 
> It's really a bug in gcc, but it's documented, so it's a "feature".
> 
> Gcc allows large enums, but does so in such a strange manner that it's 
> totally hopeless to catch problems. Also, putting a value that is larger 
> than "unsigned int" into an enum is really setting yourself up for bugs 
> and not even guaranteed to work for standard C, so sparse takes a dim view 
> of it and just says that enums are limited in size to "int" or "unsigned 
> int".
> 
> You can either ignore that warning or just use a #define. 

One of the gcc maintainers (Andrew Pinski) told me to set it up that
way, so I figured it was safe.

-Geoff

  reply	other threads:[~2006-12-01 16:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-22  4:20 [PATCH 8/14] powerpc: add ps3 platform repository support Geoff Levand
2006-12-01 14:25 ` cast truncates bits from constant value (8000000000000000 becomes 0) Geert Uytterhoeven
2006-12-01 14:39   ` Al Viro
2006-12-01 14:55     ` Geert Uytterhoeven
2006-12-02  7:50       ` Michael Ellerman
2006-12-01 15:30   ` Linus Torvalds
2006-12-01 16:51     ` Geoff Levand [this message]
2006-12-01 20:20       ` Linus Torvalds
2006-12-01 20:49         ` Derek M Jones
2006-12-01 21:00           ` Al Viro
2006-12-01 21:19             ` Linus Torvalds
2006-12-01 20:50         ` Linus Torvalds
2006-12-01 21:17           ` Geoff Levand

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=45705D79.6000107@am.sony.com \
    --to=geoffrey.levand@am$(echo .)sony.com \
    --cc=Andrew_Pinski@PlayStation$(echo .)Sony.Com \
    --cc=Geert.Uytterhoeven@sonycom$(echo .)com \
    --cc=linux-sparse@vger$(echo .)kernel.org \
    --cc=linuxppc-dev@ozlabs$(echo .)org \
    --cc=torvalds@osdl$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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