linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Samuel Bronson <naesten@gmail.com>
To: Christopher Li <sparse@chrisli.org>
Cc: linux-sparse@vger.kernel.org
Subject: Re: [PATCH-v2 2/4] Replace SYM_ and MOD_ #defines with enums in symbol.h.
Date: Tue, 2 Jun 2009 23:43:05 -0400	[thread overview]
Message-ID: <db65a1cd0906022043l6a9f175asd79c85e82287e15@mail.gmail.com> (raw)
In-Reply-To: <70318cbf0906021344w2adcf585g7d7adcd320d66fa9@mail.gmail.com>

On Tue, Jun 2, 2009 at 4:44 PM, Christopher Li <sparse@chrisli.org> wrote:
> On Mon, Jun 1, 2009 at 11:37 AM, Samuel Bronson <naesten@gmail.com> wrote:
>> Adjust the associated fields to match. While we're here, change
>> some nearby bitfields from "char" to "int" so GDB doesn't bother
>> showing character literals for them.
>
>> +enum modifier {
>> +       MOD_AUTO        = 1 << 0,
>
> The patch does not apply to my tree. The modifier is definitely not
> an enum because we apply bit operation to it.

Hmm, which tree is yours? I pulled from
git://git.kernel.org/pub/scm/devel/sparse/sparse.git

As for the bit operations, those are perfectly legal for enum values,
and there are two similar enum types defined in this very header:

enum namespace {
        NS_NONE         = 0,
        NS_MACRO        = 1,
        NS_TYPEDEF      = 2,
        NS_STRUCT       = 4,  // Also used for unions and enums.
        NS_LABEL        = 8,
        NS_SYMBOL       = 16,
        NS_ITERATOR     = 32,
        NS_PREPROCESSOR = 64,
        NS_UNDEF        = 128,
        NS_KEYWORD      = 256,
};

enum keyword {
        KW_SPECIFIER    = 1 << 0,
        KW_MODIFIER     = 1 << 1,
        KW_QUALIFIER    = 1 << 2,
        KW_ATTRIBUTE    = 1 << 3,
        KW_TYPEOF       = 1 << 4,
        KW_STATEMENT    = 1 << 5,
        KW_ASM          = 1 << 6,
        KW_MODE         = 1 << 7,
};

> Changing bitfield from "char" to "int" has risk of making the symbol
> struct bigger. We don't want that because symbol is a very common
> structure for sparse.

When could this actually happen? Here (on i386), pahole says this:

struct symbol {
        enum type                  type:8;               /*     0:24  4 */
        enum namespace             namespace:9;          /*     0:15  4 */
        unsigned int               used:1;               /*     0:14  4 */
        enum sym_attr              attr:2;               /*     0:12  4 */
        unsigned int               enum_member:1;        /*     0:11  4 */
        unsigned int               bound:1;              /*     0:10  4 */

        /* XXX 10 bits hole, try to pack */

        struct position            pos;                  /*     4     8 */

[...]

        union {
                struct basic_block * bb_target;          /*           4 */
                void *             aux;                  /*           4 */
                struct {
                        char       kind;                 /*   116     1 */

                        /* Bitfield combined with previous fields */

                        unsigned int visited:1;          /*   116:23  4 */
                };                                       /*           4 */
        };                                               /*   116     4 */

If you run c2xml on the pahole output, you'll get:

  <symbol type="struct" id="_9" ident="position" file="-"
start-line="10" start-col="8" end-line="21" end-col="2" bit-si
ze="64" alignment="4" offset="0">

in the output, indicating that the 10-bit hole near the beginning is
not due to the use of "unsigned int" instead of "unsigned char" for
the bitfields before the hole, but due to the alignment required for
the "struct position" following the hole.

The "visited" bitfield doesn't cause a problem either, because it is
packed into the same word as the "kind" field, and the other members
of that union both take a word anyway.

Looking it up in K&R 2nd edition, I see that the treatment of
bitfields is almost entirely implementation-defined, so I
unfortunately can't really make any general statements about this --
does anyone (perhaps someone on another architecture) have something
to add?
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

      reply	other threads:[~2009-06-03  3:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1243881445-30069-1-git-send-email-naesten@gmail.com>
2009-06-01 18:37 ` [PATCH-v2 2/4] Replace SYM_ and MOD_ #defines with enums in symbol.h Samuel Bronson
     [not found]   ` <1243881445-30069-3-git-send-email-naesten@gmail.com>
2009-06-01 18:37     ` [PATCH 4/4] Have Makefile import config.mak if it exists Samuel Bronson
2009-06-02 20:30       ` Christopher Li
2009-06-03  0:37         ` Samuel Bronson
2009-06-02 20:44   ` [PATCH-v2 2/4] Replace SYM_ and MOD_ #defines with enums in symbol.h Christopher Li
2009-06-03  3:43     ` Samuel Bronson [this message]

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=db65a1cd0906022043l6a9f175asd79c85e82287e15@mail.gmail.com \
    --to=naesten@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).