* PATCH: edge_iterator reallocation safety
@ 2004-10-12 7:12 Ben Elliston
2004-10-13 2:51 ` Mark Mitchell
0 siblings, 1 reply; 2+ messages in thread
From: Ben Elliston @ 2004-10-12 7:12 UTC (permalink / raw)
To: gcc-patches
This patch makes edge_iterators safe against reallocation by
VEC_safe_insert() and friends. Tested with bootstrap and regression
testsuite run.
Okay for mainline?
2004-10-12 Ben Elliston <bje@au.ibm.com>
* basic-block.h (edge_iterator): Keep the address of VEC(edge) *.
(ei_container): New.
(ei_start, ei_last): New macros.
(ei_start_1, ei_last_1): New; renamed.
(ei_last_1, ei_end_p): Use ei_container() where applicable.
(ei_one_before_end_p, ei_next, ei_edge): Likewise.
* gcse.c (remove_reachable_equiv_notes): Use ei_container().
Index: basic-block.h
===================================================================
RCS file: /home/bje/gcc-cvs/gcc/gcc/basic-block.h,v
retrieving revision 1.218
diff -u -r1.218 basic-block.h
--- basic-block.h 10 Oct 2004 22:06:04 -0000 1.218
+++ basic-block.h 12 Oct 2004 06:03:25 -0000
@@ -563,12 +563,22 @@
typedef struct {
unsigned index;
- VEC(edge) *container;
+ VEC(edge) **container;
} edge_iterator;
+static inline VEC(edge) *
+ei_container (edge_iterator i)
+{
+ gcc_assert (i.container);
+ return *i.container;
+}
+
+#define ei_start(iter) ei_start_1 (&(iter))
+#define ei_last(iter) ei_last_1 (&(iter))
+
/* Return an iterator pointing to the start of an edge vector. */
static inline edge_iterator
-ei_start (VEC(edge) *ev)
+ei_start_1 (VEC(edge) **ev)
{
edge_iterator i;
@@ -581,11 +591,11 @@
/* Return an iterator pointing to the last element of an edge
vector. */
static inline edge_iterator
-ei_last (VEC(edge) *ev)
+ei_last_1 (VEC(edge) **ev)
{
edge_iterator i;
- i.index = EDGE_COUNT (ev) - 1;
+ i.index = EDGE_COUNT (*ev) - 1;
i.container = ev;
return i;
@@ -595,7 +605,7 @@
static inline bool
ei_end_p (edge_iterator i)
{
- return (i.index == EDGE_COUNT (i.container));
+ return (i.index == EDGE_COUNT (ei_container (i)));
}
/* Is the iterator `i' at one position before the end of the
@@ -603,14 +613,14 @@
static inline bool
ei_one_before_end_p (edge_iterator i)
{
- return (i.index + 1 == EDGE_COUNT (i.container));
+ return (i.index + 1 == EDGE_COUNT (ei_container (i)));
}
/* Advance the iterator to the next element. */
static inline void
ei_next (edge_iterator *i)
{
- gcc_assert (i->index < EDGE_COUNT (i->container));
+ gcc_assert (i->index < EDGE_COUNT (ei_container (*i)));
i->index++;
}
@@ -626,7 +636,7 @@
static inline edge
ei_edge (edge_iterator i)
{
- return EDGE_I (i.container, i.index);
+ return EDGE_I (ei_container (i), i.index);
}
/* Return an edge pointed to by the iterator. Do it safely so that
Index: gcse.c
===================================================================
RCS file: /home/bje/gcc-cvs/gcc/gcc/gcse.c,v
retrieving revision 1.319
diff -u -r1.319 gcse.c
--- gcse.c 30 Sep 2004 21:25:44 -0000 1.319
+++ gcse.c 12 Oct 2004 06:03:25 -0000
@@ -6293,7 +6293,7 @@
sbitmap_zero (visited);
- act = (EDGE_COUNT (ei.container) > 0 ? EDGE_I (ei.container, 0) : NULL);
+ act = (EDGE_COUNT (ei_container (ei)) > 0 ? EDGE_I (ei_container (ei), 0) : NULL);
while (1)
{
if (!act)
@@ -6351,7 +6351,7 @@
if (act)
stack[sp++] = ei;
ei = ei_start (bb->succs);
- act = (EDGE_COUNT (ei.container) > 0 ? EDGE_I (ei.container, 0) : NULL);
+ act = (EDGE_COUNT (ei_container (ei)) > 0 ? EDGE_I (ei_container (ei), 0) : NULL);
}
}
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: PATCH: edge_iterator reallocation safety
2004-10-12 7:12 PATCH: edge_iterator reallocation safety Ben Elliston
@ 2004-10-13 2:51 ` Mark Mitchell
0 siblings, 0 replies; 2+ messages in thread
From: Mark Mitchell @ 2004-10-13 2:51 UTC (permalink / raw)
To: Ben Elliston; +Cc: gcc-patches
Ben Elliston wrote:
>This patch makes edge_iterators safe against reallocation by
>VEC_safe_insert() and friends. Tested with bootstrap and regression
>testsuite run.
>
>Okay for mainline?
>
>
OK.
--
Mark Mitchell
CodeSourcery, LLC
(916) 791-8304
mark@codesourcery.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-10-13 2:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-12 7:12 PATCH: edge_iterator reallocation safety Ben Elliston
2004-10-13 2:51 ` Mark Mitchell
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).