Commit 12a08b40 by Zack Weinberg

varray.h (VARRAY_POP): Add checking variant, aborts on underflow.

	* 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.

From-SVN: r75786
parent e79d56ea
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> 2004-01-13 Steven Bosscher <stevenb@suse.de>
PR c++/13376 PR c++/13376
...@@ -146,12 +154,12 @@ ...@@ -146,12 +154,12 @@
contraint. contraint.
(EXTRA_MEMORY_CONSTRAINT): Tell reload which constraint (EXTRA_MEMORY_CONSTRAINT): Tell reload which constraint
are memory contraints. 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. New prototype.
* gcc/config/rs6000/rs6000.md (*movdf_hardfloat64): * gcc/config/rs6000/rs6000.md (*movdf_hardfloat64):
Change 'o' to 'Y' constraint. Change 'o' to 'Y' constraint.
(*movdf_softfloat64): Ditto. (*movdf_softfloat64): Ditto.
2004-01-12 Bernardo Innocenti <bernie@develer.com> 2004-01-12 Bernardo Innocenti <bernie@develer.com>
* gcc/config/m68k/m68k.md: Switch from the "*..." syntax to the * gcc/config/m68k/m68k.md: Switch from the "*..." syntax to the
......
...@@ -118,15 +118,22 @@ varray_clear (varray_type va) ...@@ -118,15 +118,22 @@ varray_clear (varray_type va)
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007) #if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
extern void error (const char *, ...) ATTRIBUTE_PRINTF_1;
void void
varray_check_failed (varray_type va, size_t n, const char *file, int line, varray_check_failed (varray_type va, size_t n, const char *file, int line,
const char *function) 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, va->name, (unsigned long) va->num_elements, (unsigned long) n,
function, trim_filename (file), line); 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 #endif
...@@ -227,14 +227,27 @@ extern void varray_clear (varray_type); ...@@ -227,14 +227,27 @@ extern void varray_clear (varray_type);
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007) #if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
extern void varray_check_failed (varray_type, size_t, const char *, int, extern void varray_check_failed (varray_type, size_t, const char *, int,
const char *) ATTRIBUTE_NORETURN; const char *) ATTRIBUTE_NORETURN;
extern void varray_underflow (varray_type, const char *, int, const char *)
ATTRIBUTE_NORETURN;
#define VARRAY_CHECK(VA, N, T) __extension__ \ #define VARRAY_CHECK(VA, N, T) __extension__ \
(*({ varray_type const _va = (VA); \ (*({ varray_type const _va = (VA); \
const size_t _n = (N); \ const size_t _n = (N); \
if (_n >= _va->num_elements) \ if (_n >= _va->num_elements) \
varray_check_failed (_va, _n, __FILE__, __LINE__, __FUNCTION__); \ varray_check_failed (_va, _n, __FILE__, __LINE__, __FUNCTION__); \
&_va->data.T[_n]; })) &_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 #else
#define VARRAY_CHECK(VA, N, T) ((VA)->data.T[N]) #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 #endif
/* Push X onto VA. T is the name of the field in varray_data /* 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, ...@@ -248,14 +261,6 @@ extern void varray_check_failed (varray_type, size_t, const char *, int,
} \ } \
while (0) 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_CHAR(VA, N) VARRAY_CHECK (VA, N, c)
#define VARRAY_UCHAR(VA, N) VARRAY_CHECK (VA, N, uc) #define VARRAY_UCHAR(VA, N) VARRAY_CHECK (VA, N, uc)
#define VARRAY_SHORT(VA, N) VARRAY_CHECK (VA, N, s) #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, ...@@ -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) #define VARRAY_PUSH_BB(VA, X) VARRAY_PUSH (VA, bb, X)
/* Return the last element of VA. */ /* 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_CHAR(VA) VARRAY_TOP (VA, c)
#define VARRAY_TOP_UCHAR(VA) VARRAY_TOP (VA, uc) #define VARRAY_TOP_UCHAR(VA) VARRAY_TOP (VA, uc)
#define VARRAY_TOP_SHORT(VA) VARRAY_TOP (VA, s) #define VARRAY_TOP_SHORT(VA) VARRAY_TOP (VA, s)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment