[tnozaki-gcc] TNF local patch for libelf - miscellaneous lint(1) warning fix for libelf_convert.m4

Issue #279 wontfix
Takehiko NOZAKI repo owner created an issue

No description provided.

Comments (3)

  1. Takehiko NOZAKI reporter
    --- src/external/bsd/libelf/dist/libelf_convert.m4:1.5  Sat Dec 19 07:33:06 2009
    +++ src/external/bsd/libelf/dist/libelf_convert.m4      Sat Dec 19 08:40:57 2009
    @@ -46,9 +46,9 @@
    
     #define        SWAP_HALF(X)    do {                                            \
                    uint16_t _x = (uint16_t) (X);                           \
    -               uint16_t _t = _x & 0xFF;                                \
    +               uint32_t _t = _x & 0xFF;                                \
                    _t <<= 8; _x >>= 8; _t |= _x & 0xFF;                    \
    -               (X) = _t;                                               \
    +               (X) = (uint16_t)(_t & 0xFFFF);                          \
            } while (/*CONSTCOND*/0)
     #define        SWAP_WORD(X)    do {                                            \
                    uint32_t _x = (uint32_t) (X);                           \
    

    this part and -Wcast-qual warning issue are fixed elftoolchain r3009 https://sourceforge.net/p/elftoolchain/code/3009/

    ticket 448 https://sourceforge.net/p/elftoolchain/tickets/448/

  2. Takehiko NOZAKI reporter

    WRITE_{HALF,WORD,WORD64} macro, uint{16,32,64}_t to byte array is rewrited as following:

     #define        WRITE_HALF(P,X) do {                                            \
    -               uint16_t _t     = (X);                                  \
    -               unsigned char *const _p = (unsigned char *) (P);        \
    -               unsigned const char *const _q = (unsigned char *) &_t;  \
    -               _p[0]           = _q[0];                                \
    -               _p[1]           = _q[1];                                \
    -               (P)             = _p + 2;                               \
    +               union {                                                 \
    +                       uint16_t val;                                   \
    +                       uint8_t bytes[2];                               \
    +               } _t;                                                   \
    +               unsigned char *const _p = (void *) (P);                 \
    +               _t.val = (X);                                           \
    +               _p[0]           = _t.bytes[0];                          \
    +               _p[1]           = _t.bytes[1];                          \
    +               (P)             = (void *)(_p + 2);                     \
            } while (/*CONSTCOND*/0)
    
     #define        WRITE_WORD(P,X) do {                                            \
    -               uint32_t _t     = (X);                                  \
    -               unsigned char *const _p = (unsigned char *) (P);        \
    -               unsigned const char *const _q = (unsigned char *) &_t;  \
    -               _p[0]           = _q[0];                                \
    -               _p[1]           = _q[1];                                \
    -               _p[2]           = _q[2];                                \
    -               _p[3]           = _q[3];                                \
    -               (P)             = _p + 4;                               \
    +               union {                                                 \
    +                       uint32_t val;                                   \
    +                       uint8_t bytes[4];                               \
    +               } _t;                                                   \
    +               unsigned char *const _p = (void *) (P);                 \
    +               _t.val = (X);                                           \
    +               _p[0]           = _t.bytes[0];                          \
    +               _p[1]           = _t.bytes[1];                          \
    +               _p[2]           = _t.bytes[2];                          \
    +               _p[3]           = _t.bytes[3];                          \
    +               (P)             = (void *)(_p + 4);                     \
            } while (/*CONSTCOND*/0)
    
     #define        WRITE_WORD64(P,X)       do {                                    \
    -               uint64_t _t     = (X);                                  \
    -               unsigned char *const _p = (unsigned char *) (P);        \
    -               unsigned const char *const _q = (unsigned char *) &_t;  \
    -               _p[0]           = _q[0];                                \
    -               _p[1]           = _q[1];                                \
    -               _p[2]           = _q[2];                                \
    -               _p[3]           = _q[3];                                \
    -               _p[4]           = _q[4];                                \
    -               _p[5]           = _q[5];                                \
    -               _p[6]           = _q[6];                                \
    -               _p[7]           = _q[7];                                \
    -               (P)             = _p + 8;                               \
    +               union {                                                 \
    +                       uint64_t val;                                   \
    +                       uint8_t bytes[8];                               \
    +               } _t;                                                   \
    +               unsigned char *const _p = (void *) (P);                 \
    +               _t.val = (X);                                           \
    +               _p[0]           = _t.bytes[0];                          \
    +               _p[1]           = _t.bytes[1];                          \
    +               _p[2]           = _t.bytes[2];                          \
    +               _p[3]           = _t.bytes[3];                          \
    +               _p[4]           = _t.bytes[4];                          \
    +               _p[5]           = _t.bytes[5];                          \
    +               _p[6]           = _t.bytes[6];                          \
    +               _p[7]           = _t.bytes[7];                          \
    +               (P)             = (void *)(_p + 8);                     \
            } while (/*CONSTCOND*/0)
    

    i think original code is ok for strict aliasing rule/type panning.

    is there any penalty of compiler optimization? or lint(1) is poor?

  3. Log in to comment