From: "Ben Elliston" <bje@au1.ibm.com>
To: gcc-patches@gcc.gnu.org
Subject: PATCH: edge_iterator reallocation safety
Date: Tue, 12 Oct 2004 07:12:00 -0000 [thread overview]
Message-ID: <87acusjwlp.fsf@au.ibm.com> (raw)
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);
}
}
}
next reply other threads:[~2004-10-12 6:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-12 7:12 Ben Elliston [this message]
2004-10-13 2:51 ` Mark Mitchell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87acusjwlp.fsf@au.ibm.com \
--to=bje@au1.ibm.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).