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 fortran/26801] -fbounds-check generates segfault



------- Comment #4 from fxcoudert at gcc dot gnu dot org  2006-06-07 10:55 -------
The extra variable is generated from the call to gfc_evaluate_now around line
1970 of trans-array.c (the call is "indexse.expr = gfc_evaluate_now
(indexse.expr, &se->pre)").

I'm not sure yet if it's the right solution (maybe Andrew, you'd have an idea
on that) but evaluating the index to a different tree than the one used later
on fixes the segfault.

Index: trans-array.c
===================================================================
--- trans-array.c       (revision 114461)
+++ trans-array.c       (working copy)
@@ -1967,14 +1967,13 @@
          (ar->as->type != AS_ASSUMED_SIZE  || n < ar->dimen - 1))
        {
          /* Check array bounds.  */
-         tree cond;
+         tree cond, i;
          char *msg;

-         indexse.expr = gfc_evaluate_now (indexse.expr, &se->pre);
+         i = gfc_evaluate_now (indexse.expr, &se->pre);

          tmp = gfc_conv_array_lbound (se->expr, n);
-         cond = fold_build2 (LT_EXPR, boolean_type_node, 
-                             indexse.expr, tmp);
+         cond = fold_build2 (LT_EXPR, boolean_type_node, i, tmp);
          asprintf (&msg, "%s for array '%s', "
                    "lower bound of dimension %d exceeded", gfc_msg_fault,
                    sym->name, n+1);
@@ -1982,8 +1981,7 @@
          gfc_free (msg);

          tmp = gfc_conv_array_ubound (se->expr, n);
-         cond = fold_build2 (GT_EXPR, boolean_type_node, 
-                             indexse.expr, tmp);
+         cond = fold_build2 (GT_EXPR, boolean_type_node, i, tmp);
          asprintf (&msg, "%s for array '%s', "
                    "upper bound of dimension %d exceeded", gfc_msg_fault,
                    sym->name, n+1);



I worked with the following reduced testcase:

  integer :: i = 1
  logical :: l
  type dt
    integer, pointer :: a
  end type dt
  type(dt) :: obj(1)

  l = associated(obj(i)%a)
  print *, l
end


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2006-05-28 13:23:39         |2006-06-07 10:55:24
               date|                            |


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


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