public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35593]  New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2
@ 2008-03-14 20:11 niemayer at isg dot de
  2008-03-14 22:45 ` [Bug middle-end/35593] [4.3 Regression] " rguenth at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: niemayer at isg dot de @ 2008-03-14 20:11 UTC (permalink / raw)
  To: gcc-bugs

When compiling the following tiny example .cxx source with "-Wall -O2", I get
spurious warnings:

------------- cut example test.cxx here --------------
extern void function(void * x);

struct A {
        long x;
        char d[0];
};


void test(A * a) {
        function((char *)a - 4); // gcc emits warning, here - why?
}

// ------------

struct B {
        char d[0];
};

void test(B * b) {
        char * c = (char *)b;
        void * v = c-1;
        function(v);  // gcc emits warning, here - why?
}
------------- cut here --------------

The output of
> gcc -Wall -c test.cxx -O2
is:
/tmp/test.cxx: In function ‘void test(B*)’:
/tmp/test.cxx:22: warning: array subscript is below array bounds
/tmp/test.cxx: In function ‘void test(A*)’:
/tmp/test.cxx:10: warning: array subscript is below array bounds

I have not found a sane way in my non-example, real-world code to avoid those
warnings.


-- 
           Summary: spurious warning "array subscript is below array bounds"
                    with void* function argument plus -O2
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: niemayer at isg dot de
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/35593] [4.3 Regression] spurious warning "array subscript is below array bounds" with void* function argument plus -O2
  2008-03-14 20:11 [Bug c++/35593] New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2 niemayer at isg dot de
@ 2008-03-14 22:45 ` rguenth at gcc dot gnu dot org
  2008-03-14 22:45 ` rguenth at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-14 22:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2008-03-14 22:44 -------
I'll have a look.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2008-03-14 22:44:35         |2008-03-14 22:44:50
               date|                            |


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/35593] [4.3 Regression] spurious warning "array subscript is below array bounds" with void* function argument plus -O2
  2008-03-14 20:11 [Bug c++/35593] New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2 niemayer at isg dot de
  2008-03-14 22:45 ` [Bug middle-end/35593] [4.3 Regression] " rguenth at gcc dot gnu dot org
@ 2008-03-14 22:45 ` rguenth at gcc dot gnu dot org
  2008-03-15 14:29 ` rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-14 22:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2008-03-14 22:44 -------
Because we fold the pointer addition to &a->d[-8] ;)


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|c++                         |middle-end
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2008-03-14 22:44:35
               date|                            |
            Summary|spurious warning "array     |[4.3 Regression] spurious
                   |subscript is below array    |warning "array subscript is
                   |bounds" with void* function |below array bounds" with
                   |argument plus -O2           |void* function argument plus
                   |                            |-O2
   Target Milestone|---                         |4.3.1


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/35593] [4.3 Regression] spurious warning "array subscript is below array bounds" with void* function argument plus -O2
  2008-03-14 20:11 [Bug c++/35593] New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2 niemayer at isg dot de
  2008-03-14 22:45 ` [Bug middle-end/35593] [4.3 Regression] " rguenth at gcc dot gnu dot org
  2008-03-14 22:45 ` rguenth at gcc dot gnu dot org
@ 2008-03-15 14:29 ` rguenth at gcc dot gnu dot org
  2008-03-15 16:10 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-15 14:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2008-03-15 14:28 -------
Subject: Bug 35593

Author: rguenth
Date: Sat Mar 15 14:27:55 2008
New Revision: 133249

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133249
Log:
2008-03-15  Richard Guenther  <rguenther@suse.de>

        PR middle-end/35593
        * tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Make sure
        to not produce negative array indices if not allowed.  Add
        parameter to indicate that.
        (maybe_fold_offset_to_component_ref): Allow negative array
        indices only for the first member of a structure.
        (maybe_fold_offset_to_reference): Allow negative array indices.
        (maybe_fold_stmt_addition): Likewise.

        * g++.dg/warn/Warray-bounds-3.C: New testcase.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Warray-bounds-3.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-ccp.c


-- 


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/35593] [4.3 Regression] spurious warning "array subscript is below array bounds" with void* function argument plus -O2
  2008-03-14 20:11 [Bug c++/35593] New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2 niemayer at isg dot de
                   ` (2 preceding siblings ...)
  2008-03-15 14:29 ` rguenth at gcc dot gnu dot org
@ 2008-03-15 16:10 ` rguenth at gcc dot gnu dot org
  2008-03-15 19:15 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-15 16:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2008-03-15 16:09 -------
Fixed on the trunk.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|minor                       |normal
           Keywords|                            |diagnostic
      Known to fail|                            |4.3.0
      Known to work|                            |4.4.0


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/35593] [4.3 Regression] spurious warning "array subscript is below array bounds" with void* function argument plus -O2
  2008-03-14 20:11 [Bug c++/35593] New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2 niemayer at isg dot de
                   ` (3 preceding siblings ...)
  2008-03-15 16:10 ` rguenth at gcc dot gnu dot org
@ 2008-03-15 19:15 ` rguenth at gcc dot gnu dot org
  2008-03-18 17:25 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-15 19:15 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/35593] [4.3 Regression] spurious warning "array subscript is below array bounds" with void* function argument plus -O2
  2008-03-14 20:11 [Bug c++/35593] New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2 niemayer at isg dot de
                   ` (4 preceding siblings ...)
  2008-03-15 19:15 ` rguenth at gcc dot gnu dot org
@ 2008-03-18 17:25 ` rguenth at gcc dot gnu dot org
  2008-03-18 17:28 ` rguenth at gcc dot gnu dot org
  2009-06-03  5:07 ` at dot wufei at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-18 17:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2008-03-18 17:24 -------
Subject: Bug 35593

Author: rguenth
Date: Tue Mar 18 17:23:35 2008
New Revision: 133318

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133318
Log:
2008-03-18  Richard Guenther  <rguenther@suse.de>

        Backport from mainline:
        2008-03-15  Richard Guenther  <rguenther@suse.de>

        PR middle-end/35593
        * tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Make sure
        to not produce negative array indices if not allowed.  Add
        parameter to indicate that.
        (maybe_fold_offset_to_component_ref): Allow negative array
        indices only for the first member of a structure.
        (maybe_fold_offset_to_reference): Allow negative array indices.
        (maybe_fold_stmt_addition): Likewise.

        * g++.dg/warn/Warray-bounds-3.C: New testcase.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/warn/Warray-bounds-3.C
      - copied unchanged from r133249,
trunk/gcc/testsuite/g++.dg/warn/Warray-bounds-3.C
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_3-branch/gcc/tree-ssa-ccp.c


-- 


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/35593] [4.3 Regression] spurious warning "array subscript is below array bounds" with void* function argument plus -O2
  2008-03-14 20:11 [Bug c++/35593] New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2 niemayer at isg dot de
                   ` (5 preceding siblings ...)
  2008-03-18 17:25 ` rguenth at gcc dot gnu dot org
@ 2008-03-18 17:28 ` rguenth at gcc dot gnu dot org
  2009-06-03  5:07 ` at dot wufei at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-18 17:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2008-03-18 17:28 -------
And the branch.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/35593] [4.3 Regression] spurious warning "array subscript is below array bounds" with void* function argument plus -O2
  2008-03-14 20:11 [Bug c++/35593] New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2 niemayer at isg dot de
                   ` (6 preceding siblings ...)
  2008-03-18 17:28 ` rguenth at gcc dot gnu dot org
@ 2009-06-03  5:07 ` at dot wufei at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: at dot wufei at gmail dot com @ 2009-06-03  5:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from at dot wufei at gmail dot com  2009-06-03 05:07 -------
Did the patch fixes the second case (struct B)? It still warns on 4.3 branch,
but no problem on 4.4.


-- 


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-06-03  5:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-14 20:11 [Bug c++/35593] New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2 niemayer at isg dot de
2008-03-14 22:45 ` [Bug middle-end/35593] [4.3 Regression] " rguenth at gcc dot gnu dot org
2008-03-14 22:45 ` rguenth at gcc dot gnu dot org
2008-03-15 14:29 ` rguenth at gcc dot gnu dot org
2008-03-15 16:10 ` rguenth at gcc dot gnu dot org
2008-03-15 19:15 ` rguenth at gcc dot gnu dot org
2008-03-18 17:25 ` rguenth at gcc dot gnu dot org
2008-03-18 17:28 ` rguenth at gcc dot gnu dot org
2009-06-03  5:07 ` at dot wufei at gmail dot com

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 read-only IMAP folder(s) and NNTP newsgroup(s).