This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix off-by-one error in pretty-printed array bounds
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 7 Dec 2004 18:11:06 -0800
- Subject: fix off-by-one error in pretty-printed array bounds
I spent a depressingly long time trying to figure out why a
compiler-generated array temporary, "tmp.60[4]" was sized for
only four elements, when it should have matched up to a user
array that had five elements. And given that I was looking
for a runtime memory corruption bug in the first place, it
seemed all too plausible.
Guh.
I also switch the display of non-standard array bounds from
"min .. max" to the Fortran style "min:max", because I think
it looks better when one of the bounds is omitted.
r~
* tree-pretty-print.c (dump_array_domain): Split out from
dump_generic_node; fix off-by-one error on zero-based array bounds.
(dump_generic_node): Use it.
(print_declaration): Likewise.
Index: tree-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-pretty-print.c,v
retrieving revision 2.50
diff -c -p -d -r2.50 tree-pretty-print.c
*** tree-pretty-print.c 7 Dec 2004 21:23:04 -0000 2.50
--- tree-pretty-print.c 8 Dec 2004 02:02:54 -0000
*************** dump_function_declaration (pretty_printe
*** 217,222 ****
--- 217,251 ----
pp_character (buffer, ')');
}
+ /* Dump the domain associated with an array. */
+
+ static void
+ dump_array_domain (pretty_printer *buffer, tree domain, int spc, int flags)
+ {
+ pp_character (buffer, '[');
+ if (domain)
+ {
+ tree min = TYPE_MIN_VALUE (domain);
+ tree max = TYPE_MAX_VALUE (domain);
+
+ if (min && max
+ && integer_zerop (min)
+ && host_integerp (max, 0))
+ pp_wide_integer (buffer, TREE_INT_CST_LOW (max) + 1);
+ else
+ {
+ if (min)
+ dump_generic_node (buffer, min, spc, flags, false);
+ pp_character (buffer, ':');
+ if (max)
+ dump_generic_node (buffer, max, spc, flags, false);
+ }
+ }
+ else
+ pp_string (buffer, "<unknown>");
+ pp_character (buffer, ']');
+ }
+
/* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
IS_STMT is true, the object printed is considered to be a statement
*************** dump_generic_node (pretty_printer *buffe
*** 427,457 ****
dump_generic_node (buffer, tmp, spc, flags, false);
/* Print the dimensions. */
! for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE;
! tmp = TREE_TYPE (tmp))
! {
! tree domain = TYPE_DOMAIN (tmp);
!
! pp_character (buffer, '[');
! if (domain)
! {
! if (TYPE_MIN_VALUE (domain)
! && !integer_zerop (TYPE_MIN_VALUE (domain)))
! {
! dump_generic_node (buffer, TYPE_MIN_VALUE (domain),
! spc, flags, false);
! pp_string (buffer, " .. ");
! }
!
! if (TYPE_MAX_VALUE (domain))
! dump_generic_node (buffer, TYPE_MAX_VALUE (domain),
! spc, flags, false);
! }
! else
! pp_string (buffer, "<unknown>");
!
! pp_character (buffer, ']');
! }
break;
}
--- 456,463 ----
dump_generic_node (buffer, tmp, spc, flags, false);
/* Print the dimensions. */
! for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE; tmp = TREE_TYPE (tmp))
! dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
break;
}
*************** print_declaration (pretty_printer *buffe
*** 1515,1537 ****
tmp = TREE_TYPE (t);
while (TREE_CODE (tmp) == ARRAY_TYPE)
{
! pp_character (buffer, '[');
! if (TYPE_DOMAIN (tmp))
! {
! if (TYPE_MIN_VALUE (TYPE_DOMAIN (tmp))
! && !integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tmp))))
! {
! dump_generic_node (buffer,
! TYPE_MIN_VALUE (TYPE_DOMAIN (tmp)),
! spc, flags, false);
! pp_string (buffer, " .. ");
! }
!
! if (TYPE_MAX_VALUE (TYPE_DOMAIN (tmp)))
! dump_generic_node (buffer, TYPE_MAX_VALUE (TYPE_DOMAIN (tmp)),
! spc, flags, false);
! }
! pp_character (buffer, ']');
tmp = TREE_TYPE (tmp);
}
}
--- 1521,1527 ----
tmp = TREE_TYPE (t);
while (TREE_CODE (tmp) == ARRAY_TYPE)
{
! dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
tmp = TREE_TYPE (tmp);
}
}