This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH][IRA] Avoid undefined behavior in ira_allocno_object_iter_cond
- From: Vladimir Makarov <vmakarov at redhat dot com>
- To: Richard Guenther <rguenther at suse dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 19 Apr 2012 13:45:20 -0400
- Subject: Re: [PATCH][IRA] Avoid undefined behavior in ira_allocno_object_iter_cond
- References: <Pine.LNX.firstname.lastname@example.org>
On 04/19/2012 08:14 AM, Richard Guenther wrote:
This gave me headaches debugging a VRP "miscompile" of ira-build.c.
Number of iteration analysis concluded that the allocno object
iterators do not iterate because it sees accesses to ->objects[n]
for a loop i = 0; i< n; ++i. This is because
ira_allocno_object_iter_cond was written in a very fancy way,
optimizing the number of source lines (appearantly).
Fixed as follows.
A bootstrap& regtest is currently running (together with the
alleged VRP modification). I will commit this if it succeeds.
2012-04-19 Richard Guenther<email@example.com>
* ira-int.h (ira_allocno_object_iter_cond): Avoid out-of-bound
--- gcc/ira-int.h (revision 186584)
+++ gcc/ira-int.h (working copy)
@@ -1138,8 +1138,13 @@ static inline bool
ira_allocno_object_iter_cond (ira_allocno_object_iterator *i, ira_allocno_t a,
- *o = ALLOCNO_OBJECT (a, i->n);
- return i->n++< ALLOCNO_NUM_OBJECTS (a);
+ int n = i->n++;
+ if (n< ALLOCNO_NUM_OBJECTS (a))
+ *o = ALLOCNO_OBJECT (a, n);
+ return true;
+ return false;
/* Loop over all objects associated with allocno A. In each