varray.h (VARRAY_POP): Add checking variant, aborts on underflow.
authorZack Weinberg <zack@gcc.gnu.org>
Tue, 13 Jan 2004 02:43:16 +0000 (02:43 +0000)
committerZack Weinberg <zack@gcc.gnu.org>
Tue, 13 Jan 2004 02:43:16 +0000 (02:43 +0000)
* 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

gcc/ChangeLog
gcc/varray.c
gcc/varray.h

index ee83e98ffe00af7ea2a045c15eb868a9621aa246..3bc907ebeaefc0548267946425b99ac82578e9b1 100644 (file)
@@ -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
        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
index aca4b6bccf4ff7796eb2bf756aae478143d35a37..b748d438e9ada4ebc2114814453fa07481c2f246 100644 (file)
@@ -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
index 7cb9ff09855c6c16a736e4f5864132789fae4b93..9cc6ea5fffe2bb974325c834412bc1595136bff9 100644 (file)
@@ -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)