This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/36902] [4.3/4.4 Regression]: Bogus array bound warning



------- Comment #2 from hjl dot tools at gmail dot com  2008-07-22 21:13 -------
This regression is introduced by revision 120898:

http://gcc.gnu.org/ml/gcc-cvs/2007-01/msg00603.html

The simplified testcase:

---
typedef unsigned char __u8;
typedef unsigned short __u16;

static inline unsigned char *
foo(unsigned char * to, const unsigned char * from, int n)
{
    switch ( n )
    {
    case 3:
      *to = *from;
        break;
    case 5:
        to[4] = from [4];
        break;
    }
    return to;
}

struct {
    int    size_of_select;
    unsigned char pcr_select[4];
} sel;

int main(int argc, char *argv[])
{
    static unsigned char buf[64];

    sel.size_of_select = 3;
    foo(buf, sel.pcr_select, sel.size_of_select);

    return 1;
}
---

The warning is very fragile:  if the buffer in main() is not static then
there is no failure; is the size is passed as a constant there is no error.


-- 

hjl dot tools at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mueller at gcc dot gnu dot
                   |                            |org, richard dot guenther at
                   |                            |gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36902


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]