summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog14
-rw-r--r--gcc/varray.c13
-rw-r--r--gcc/varray.h23
3 files changed, 36 insertions, 14 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ee83e98ffe0..3bc907ebeae 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2004-01-12 Zack Weinberg <zack@codesourcery.com>
+
+ * varray.h (VARRAY_POP): Add checking variant, aborts on underflow.
+ (VARRAY_TOP): Use VARRAY_CHECK so the access is bounds-checked.
+ * varray.c: No need to prototype error.
+ (varray_check_failed): Wrap long string onto two lines.
+ (varray_underflow): New function.
+
2004-01-13 Steven Bosscher <stevenb@suse.de>
PR c++/13376
@@ -146,12 +154,12 @@
contraint.
(EXTRA_MEMORY_CONSTRAINT): Tell reload which constraint
are memory contraints.
- * gcc/config/rs6000/rs6000-protos.h (word_offset_memref_operand):
+ * gcc/config/rs6000/rs6000-protos.h (word_offset_memref_operand):
New prototype.
- * gcc/config/rs6000/rs6000.md (*movdf_hardfloat64):
+ * gcc/config/rs6000/rs6000.md (*movdf_hardfloat64):
Change 'o' to 'Y' constraint.
(*movdf_softfloat64): Ditto.
-
+
2004-01-12 Bernardo Innocenti <bernie@develer.com>
* gcc/config/m68k/m68k.md: Switch from the "*..." syntax to the
diff --git a/gcc/varray.c b/gcc/varray.c
index aca4b6bccf4..b748d438e9a 100644
--- a/gcc/varray.c
+++ b/gcc/varray.c
@@ -118,15 +118,22 @@ varray_clear (varray_type va)
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
-extern void error (const char *, ...) ATTRIBUTE_PRINTF_1;
-
void
varray_check_failed (varray_type va, size_t n, const char *file, int line,
const char *function)
{
- internal_error ("virtual array %s[%lu]: element %lu out of bounds in %s, at %s:%d",
+ internal_error ("virtual array %s[%lu]: element %lu out of bounds "
+ "in %s, at %s:%d",
va->name, (unsigned long) va->num_elements, (unsigned long) n,
function, trim_filename (file), line);
}
+void
+varray_underflow (varray_type va, const char *file, int line,
+ const char *function)
+{
+ internal_error ("underflowed virtual array %s in %s, at %s:%d",
+ va->name, function, trim_filename (file), line);
+}
+
#endif
diff --git a/gcc/varray.h b/gcc/varray.h
index 7cb9ff09855..9cc6ea5fffe 100644
--- a/gcc/varray.h
+++ b/gcc/varray.h
@@ -227,14 +227,27 @@ extern void varray_clear (varray_type);
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
extern void varray_check_failed (varray_type, size_t, const char *, int,
const char *) ATTRIBUTE_NORETURN;
+extern void varray_underflow (varray_type, const char *, int, const char *)
+ ATTRIBUTE_NORETURN;
#define VARRAY_CHECK(VA, N, T) __extension__ \
(*({ varray_type const _va = (VA); \
const size_t _n = (N); \
if (_n >= _va->num_elements) \
varray_check_failed (_va, _n, __FILE__, __LINE__, __FUNCTION__); \
&_va->data.T[_n]; }))
+
+#define VARRAY_POP(VA) do { \
+ varray_type const _va = (VA); \
+ if (_va->elements_used == 0) \
+ varray_underflow (_va, __FILE__, __LINE__, __FUNCTION__); \
+ else \
+ _va->elements_used--; \
+} while (0)
+
#else
#define VARRAY_CHECK(VA, N, T) ((VA)->data.T[N])
+/* Pop the top element of VA. */
+#define VARRAY_POP(VA) do { ((VA)->elements_used--); } while (0)
#endif
/* Push X onto VA. T is the name of the field in varray_data
@@ -248,14 +261,6 @@ extern void varray_check_failed (varray_type, size_t, const char *, int,
} \
while (0)
-/* Pop the top element of VA. */
-#define VARRAY_POP(VA) \
- ((VA)->elements_used--)
-
-/* Return the top element of VA. */
-#define VARRAY_TOP(VA, T) \
- ((VA)->data.T[(VA)->elements_used - 1])
-
#define VARRAY_CHAR(VA, N) VARRAY_CHECK (VA, N, c)
#define VARRAY_UCHAR(VA, N) VARRAY_CHECK (VA, N, uc)
#define VARRAY_SHORT(VA, N) VARRAY_CHECK (VA, N, s)
@@ -299,6 +304,8 @@ extern void varray_check_failed (varray_type, size_t, const char *, int,
#define VARRAY_PUSH_BB(VA, X) VARRAY_PUSH (VA, bb, X)
/* Return the last element of VA. */
+#define VARRAY_TOP(VA, T) VARRAY_CHECK(VA, (VA)->elements_used - 1, T)
+
#define VARRAY_TOP_CHAR(VA) VARRAY_TOP (VA, c)
#define VARRAY_TOP_UCHAR(VA) VARRAY_TOP (VA, uc)
#define VARRAY_TOP_SHORT(VA) VARRAY_TOP (VA, s)