public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug bootstrap/30511]  New: False array bound check causes gcc failed to boostrap
@ 2007-01-19 19:13 hjl at lucon dot org
  2007-01-19 20:04 ` [Bug bootstrap/30511] " mueller at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: hjl at lucon dot org @ 2007-01-19 19:13 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1092 bytes --]

With revision 120976, I got

cc1: warnings being treated as errors
/export/gnu/src/gcc/gcc/gcc/fortran/symbol.c: In function ‘gfc_get_namespace’:
/export/gnu/src/gcc/gcc/gcc/fortran/symbol.c:1842: warning: array subscript is
above array bounds

There are

1838   /* Initialize default implicit types.  */
1839   for (i = 'a'; i <= 'z'; i++)
1840     {
1841       ns->set_flag[i - 'a'] = 0;
1842       ts = &ns->default_type[i - 'a'];
bash-3.1$ grep default_type *.h
gfortran.h:  gfc_typespec default_type[GFC_LETTERS];
...
bash-3.1$ grep GFC_LETTERS *.h
gfortran.h:#define GFC_LETTERS 26               /* Number of letters in the
alphabet.  */

I don't how array subscript can be above array bounds.


-- 
           Summary: False array bound check causes gcc failed to boostrap
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: bootstrap
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hjl at lucon dot org


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


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

* [Bug bootstrap/30511] False array bound check causes gcc failed to boostrap
  2007-01-19 19:13 [Bug bootstrap/30511] New: False array bound check causes gcc failed to boostrap hjl at lucon dot org
@ 2007-01-19 20:04 ` mueller at gcc dot gnu dot org
  2007-01-19 20:55 ` roger at eyesopen dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mueller at gcc dot gnu dot org @ 2007-01-19 20:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from mueller at gcc dot gnu dot org  2007-01-19 20:04 -------
this patch fixes / works around it. I don't like it yet, I'm trying to find a
better solution. 

--- tree-vrp.c  (revision 120953)
+++ tree-vrp.c  (working copy)
@@ -3583,6 +3583,25 @@ check_array_bounds (tree *tp, int *walk_
            *walk_subtree = FALSE;
            return NULL_TREE;
          }
+
+       /* Don't warn if the result ssa_name is used in another
+         binary expr.  */
+       if (TREE_CODE ((tree)data) == GIMPLE_MODIFY_STMT
+           && GIMPLE_STMT_OPERAND ((tree)data, 0)
+           && TREE_CODE (GIMPLE_STMT_OPERAND ((tree)data, 0)) == SSA_NAME)
+         {
+          imm_use_iterator iter;
+          tree lhs = GIMPLE_STMT_OPERAND ((tree)data, 0);
+          tree use;
+
+          FOR_EACH_IMM_USE_STMT (use, iter, lhs)
+            if (TREE_CODE (use) == GIMPLE_MODIFY_STMT
+                && BINARY_CLASS_P (GIMPLE_STMT_OPERAND (use, 1)))
+              *walk_subtree = FALSE;
+
+          if (*walk_subtree == FALSE)
+            return NULL_TREE;
+         }
        while (handled_component_p (t))
          {
            if (TREE_CODE (t) == ARRAY_REF)


-- 

mueller at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-01-19 20:04:36
               date|                            |


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


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

* [Bug bootstrap/30511] False array bound check causes gcc failed to boostrap
  2007-01-19 19:13 [Bug bootstrap/30511] New: False array bound check causes gcc failed to boostrap hjl at lucon dot org
  2007-01-19 20:04 ` [Bug bootstrap/30511] " mueller at gcc dot gnu dot org
@ 2007-01-19 20:55 ` roger at eyesopen dot com
  2007-01-19 22:02 ` mrs at apple dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: roger at eyesopen dot com @ 2007-01-19 20:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from roger at eyesopen dot com  2007-01-19 20:55 -------

It looks like the ivopts pass is creating dubious? array references.
The symbol.c.053t.vrp1

  D.12252_12 = (long unsigned int) i_2;
  D.12255_15 = &ns_4->default_type[D.12252_12];
  ts_16 = D.12255_15 + -2328B;

i.e. we now have "&ns->default_type[i] - &ns->default_type['a']".
I wouldn't like to offer an opinion on whether this IV is valid in the
middle-end.  The transformation is certainly unsafe in C, where a pointer
arithmetic is not guaranteed to be valid outside of the declared object.

I think the appropriate fix is that if ivopts is going to create these
suspicious array refs, it should appropriately set TREE_NO_WARNING, which
will then cause the reference to be ignored by the bounds checking in VRP.

Alternatively, we need more context in array bounds checking such that
&x['a'] is not a problem, but x['a'] on it's own is diagnosed.  i.e. we
could perhaps keep an in_indirect_ref_p flag during the tree walking.

I hope this helps.


-- 


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


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

* [Bug bootstrap/30511] False array bound check causes gcc failed to boostrap
  2007-01-19 19:13 [Bug bootstrap/30511] New: False array bound check causes gcc failed to boostrap hjl at lucon dot org
  2007-01-19 20:04 ` [Bug bootstrap/30511] " mueller at gcc dot gnu dot org
  2007-01-19 20:55 ` roger at eyesopen dot com
@ 2007-01-19 22:02 ` mrs at apple dot com
  2007-01-19 22:05 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mrs at apple dot com @ 2007-01-19 22:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from mrs at apple dot com  2007-01-19 22:02 -------
Testcase from delta, compile with:

$ ./xgcc -B./  t.c -O2 -S -Wall
t.c: In function 'gfc_get_namespace':
t.c:10: warning: array subscript is above array bounds


typedef struct { int kind; } gfc_typespec;
typedef struct gfc_namespace { gfc_typespec default_type[26]; } gfc_namespace;
void gfc_get_namespace ()
{
  gfc_namespace *ns=0;
  gfc_typespec *ts =0;
  int i;
  for (i = 'a'; i <= 'z'; i++)
    {
      ts = &ns->default_type[i - 'a'];
      ts->kind = 0;
    }
}


-- 


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


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

* [Bug bootstrap/30511] False array bound check causes gcc failed to boostrap
  2007-01-19 19:13 [Bug bootstrap/30511] New: False array bound check causes gcc failed to boostrap hjl at lucon dot org
                   ` (2 preceding siblings ...)
  2007-01-19 22:02 ` mrs at apple dot com
@ 2007-01-19 22:05 ` pinskia at gcc dot gnu dot org
  2007-01-19 22:15 ` mueller at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-19 22:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2007-01-19 22:05 -------
(In reply to comment #3)
> Testcase from delta, compile with:
Hmm, in the non reduced testcase, is default_type last?  Since in the reduced
testcase, default_type is last, it seems like we should not warn about that
case even if the bounds does go over anyways.


-- 


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


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

* [Bug bootstrap/30511] False array bound check causes gcc failed to boostrap
  2007-01-19 19:13 [Bug bootstrap/30511] New: False array bound check causes gcc failed to boostrap hjl at lucon dot org
                   ` (3 preceding siblings ...)
  2007-01-19 22:05 ` pinskia at gcc dot gnu dot org
@ 2007-01-19 22:15 ` mueller at gcc dot gnu dot org
  2007-01-20 13:28 ` dominiq at lps dot ens dot fr
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mueller at gcc dot gnu dot org @ 2007-01-19 22:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from mueller at gcc dot gnu dot org  2007-01-19 22:15 -------
the ivopts problem is a duplicate of bug 26726.


-- 


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


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

* [Bug bootstrap/30511] False array bound check causes gcc failed to boostrap
  2007-01-19 19:13 [Bug bootstrap/30511] New: False array bound check causes gcc failed to boostrap hjl at lucon dot org
                   ` (4 preceding siblings ...)
  2007-01-19 22:15 ` mueller at gcc dot gnu dot org
@ 2007-01-20 13:28 ` dominiq at lps dot ens dot fr
  2007-01-21 16:12 ` mueller at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dominiq at lps dot ens dot fr @ 2007-01-20 13:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from dominiq at lps dot ens dot fr  2007-01-20 13:27 -------
On Mac OSX 10.3.9, after the same failure I have applied the patch of comment
#1. Now the build fails
with:

/sw/src/fink.build/gcc4-4.3.0-20070120/darwin_objdir/./gcc/xgcc
-B/sw/src/fink.build/gcc4-4.3.0-20070120/darwin_objdir/./gcc/
-B/sw/lib/gcc4/powerpc-apple-darwin7/bin/
-B/sw/lib/gcc4/powerpc-apple-darwin7/lib/ -isystem
/sw/lib/gcc4/powerpc-apple-darwin7/include -isystem
/sw/lib/gcc4/powerpc-apple-darwin7/sys-include -DHAVE_CONFIG_H -I.
-I../../../gcc-4.3-20070120/libgfortran -I.
-iquote../../../gcc-4.3-20070120/libgfortran/io
-I../../../gcc-4.3-20070120/libgfortran/../gcc
-I../../../gcc-4.3-20070120/libgfortran/../gcc/config -I../.././gcc
-D_GNU_SOURCE -std=gnu99 -Wall -Wstrict-prototypes -Wmissing-prototypes
-Wold-style-definition -Wextra -Wwrite-strings -O2 -g -O2 -MT error.lo -MD -MP
-MF .deps/error.Tpo -c ../../../gcc-4.3-20070120/libgfortran/runtime/error.c 
-fno-common -DPIC -o .libs/error.o
In file included from ../../../gcc-4.3-20070120/libgfortran/runtime/error.c:52:
/usr/include/sys/resource.h:81: error: field 'ru_utime' has incomplete type
/usr/include/sys/resource.h:82: error: field 'ru_stime' has incomplete type

Any idea?


-- 


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


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

* [Bug bootstrap/30511] False array bound check causes gcc failed to boostrap
  2007-01-19 19:13 [Bug bootstrap/30511] New: False array bound check causes gcc failed to boostrap hjl at lucon dot org
                   ` (5 preceding siblings ...)
  2007-01-20 13:28 ` dominiq at lps dot ens dot fr
@ 2007-01-21 16:12 ` mueller at gcc dot gnu dot org
  2007-01-21 16:53 ` mueller at gcc dot gnu dot org
  2007-01-30 17:18 ` mueller at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: mueller at gcc dot gnu dot org @ 2007-01-21 16:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from mueller at gcc dot gnu dot org  2007-01-21 16:12 -------
Subject: Bug 30511

Author: mueller
Date: Sun Jan 21 16:12:10 2007
New Revision: 121032

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121032
Log:
2007-01-21  Dirk Mueller  <dmueller@suse.de>

        PR bootstrap/30511
        * tree-vrp.c (check_array_bounds): do not warn
        about ADDR_EXPR's of ARRAY_REF's which are immediately
        used in binary expressions.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-vrp.c


-- 


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


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

* [Bug bootstrap/30511] False array bound check causes gcc failed to boostrap
  2007-01-19 19:13 [Bug bootstrap/30511] New: False array bound check causes gcc failed to boostrap hjl at lucon dot org
                   ` (6 preceding siblings ...)
  2007-01-21 16:12 ` mueller at gcc dot gnu dot org
@ 2007-01-21 16:53 ` mueller at gcc dot gnu dot org
  2007-01-30 17:18 ` mueller at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: mueller at gcc dot gnu dot org @ 2007-01-21 16:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from mueller at gcc dot gnu dot org  2007-01-21 16:52 -------
Fixed for 4.3. 


-- 

mueller at gcc dot gnu dot org changed:

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


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


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

* [Bug bootstrap/30511] False array bound check causes gcc failed to boostrap
  2007-01-19 19:13 [Bug bootstrap/30511] New: False array bound check causes gcc failed to boostrap hjl at lucon dot org
                   ` (7 preceding siblings ...)
  2007-01-21 16:53 ` mueller at gcc dot gnu dot org
@ 2007-01-30 17:18 ` mueller at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: mueller at gcc dot gnu dot org @ 2007-01-30 17:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from mueller at gcc dot gnu dot org  2007-01-30 17:18 -------
Subject: Bug 30511

Author: mueller
Date: Tue Jan 30 17:17:39 2007
New Revision: 121346

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121346
Log:
backport from mainline:

  2007-01-21  Dirk Mueller  <dmueller@suse.de>

        PR bootstrap/30511
        * tree-vrp.c (check_array_bounds): do not warn
        about ADDR_EXPR's of ARRAY_REF's which are immediately
        used in binary expressions.

  2007-01-19  Dirk Mueller  <dmueller@suse.de>

        * config/i386.h (CONDITIONAL_REGISTER_USAGE): Store
        result of PIC_OFFSET_TABLE_REGNUM in temporary variable to avoid
        duplicate evaluation.

  2007-01-18  Dirk Mueller  <dmueller@suse.de>
            Richard Guenther <rguenther@suse.de>

        PR diagnostic/8268
        * doc/invoke.texi (Warray-bounds): Document -Warray-bounds.
        * common.opt (Warray-bounds): Add new warning option.
        * c-opts.c (c_common_handle_option): Define -Warray-bounds
        if -Wall is given.
        * Makefile.in: make tree-vrp.o depend on toplev.h
        * tree-vrp.c (vrp_finalize): Call check_array_refs if
        * -Warray-bounds
        is enabled.
        (check_array_refs, check_array_bounds, check_array_ref): New.


Added:
    branches/suse/gcc-4_2-branch/gcc/testsuite/g++.dg/warn/Warray-bounds-2.C
      - copied unchanged from r120898,
trunk/gcc/testsuite/g++.dg/warn/Warray-bounds-2.C
    branches/suse/gcc-4_2-branch/gcc/testsuite/g++.dg/warn/Warray-bounds.C
      - copied unchanged from r120898,
trunk/gcc/testsuite/g++.dg/warn/Warray-bounds.C
    branches/suse/gcc-4_2-branch/gcc/testsuite/gcc.dg/Warray-bounds-2.c
      - copied unchanged from r120898,
trunk/gcc/testsuite/gcc.dg/Warray-bounds-2.c
    branches/suse/gcc-4_2-branch/gcc/testsuite/gcc.dg/Warray-bounds.c
      - copied unchanged from r120898,
trunk/gcc/testsuite/gcc.dg/Warray-bounds.c
Modified:
    branches/suse/gcc-4_2-branch/gcc/Makefile.in
    branches/suse/gcc-4_2-branch/gcc/c-opts.c
    branches/suse/gcc-4_2-branch/gcc/common.opt
    branches/suse/gcc-4_2-branch/gcc/config/i386/i386.h
    branches/suse/gcc-4_2-branch/gcc/doc/invoke.texi
    branches/suse/gcc-4_2-branch/gcc/tree-vrp.c


-- 


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


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

end of thread, other threads:[~2007-01-30 17:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-19 19:13 [Bug bootstrap/30511] New: False array bound check causes gcc failed to boostrap hjl at lucon dot org
2007-01-19 20:04 ` [Bug bootstrap/30511] " mueller at gcc dot gnu dot org
2007-01-19 20:55 ` roger at eyesopen dot com
2007-01-19 22:02 ` mrs at apple dot com
2007-01-19 22:05 ` pinskia at gcc dot gnu dot org
2007-01-19 22:15 ` mueller at gcc dot gnu dot org
2007-01-20 13:28 ` dominiq at lps dot ens dot fr
2007-01-21 16:12 ` mueller at gcc dot gnu dot org
2007-01-21 16:53 ` mueller at gcc dot gnu dot org
2007-01-30 17:18 ` mueller at gcc dot gnu dot org

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).