cpphash.h (POOL_ALIGN, [...]): Remove.
authorNeil Booth <neil@daikokuya.demon.co.uk>
Sun, 30 Sep 2001 10:03:11 +0000 (10:03 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Sun, 30 Sep 2001 10:03:11 +0000 (10:03 +0000)
* cpphash.h (POOL_ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE,
POOL_SIZE, POOL_ROOM, POOL_COMMIT, struct cpp_chunk,
struct cpp_pool, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve,
_cpp_pool_alloc, _cpp_next_chunk): Remove.
(_cpp_extend_buff, BUFF_ROOM): Update.
(_cpp_append_extend_buff): New.
(struct cpp_reader): Remove macro_pool, add a_buff.
* cppinit.c (cpp_create_reader): Initialize a_buff, instead of
macro_pool.
(cpp_destroy): Free a_buff instead of macro_pool.
* cpplex.c (new_chunk, chunk_suitable, _cpp_next_chunk,
new_chunk, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve,
_cpp_pool_alloc, ): Remove.
(parse_number, parse_string): Update use of _cpp_extend_buff.
(_cpp_extend_buff): Update.
(_cpp_append_extend_buff, cpp_aligned_alloc): New.
* cpplib.c (glue_header_name, parse_answer):
Update use of _cpp_extend_buff.
(cpp_register_pragma, cpp_register_pragma_space): Use
_cpp_aligned_alloc.
(do_assert, do_unassert): Check for EOL, update.
* cppmacro.c (stringify_arg, collect_args): Update to use
_cpp_extend_buff and _cpp_append_extend_buff.
(save_parameter, parse_params, alloc_expansion_token,
_cpp_create_definition): Rework memory management.

* gcc.dg/cpp/redef2.c: Add test.

From-SVN: r45899

gcc/ChangeLog
gcc/cpphash.h
gcc/cppinit.c
gcc/cpplex.c
gcc/cpplib.c
gcc/cppmacro.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/redef2.c

index c67af50..ca88ff7 100644 (file)
@@ -1,3 +1,31 @@
+2001-09-30  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * cpphash.h (POOL_ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE,
+       POOL_SIZE, POOL_ROOM, POOL_COMMIT, struct cpp_chunk,
+       struct cpp_pool, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve,
+       _cpp_pool_alloc, _cpp_next_chunk): Remove.
+       (_cpp_extend_buff, BUFF_ROOM): Update.
+       (_cpp_append_extend_buff): New.
+       (struct cpp_reader): Remove macro_pool, add a_buff.
+       * cppinit.c (cpp_create_reader): Initialize a_buff, instead of
+       macro_pool.
+       (cpp_destroy): Free a_buff instead of macro_pool.
+       * cpplex.c (new_chunk, chunk_suitable, _cpp_next_chunk,
+       new_chunk, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve,
+       _cpp_pool_alloc, ): Remove.
+       (parse_number, parse_string): Update use of _cpp_extend_buff.
+       (_cpp_extend_buff): Update.
+       (_cpp_append_extend_buff, cpp_aligned_alloc): New.
+       * cpplib.c (glue_header_name, parse_answer):
+       Update use of _cpp_extend_buff.
+       (cpp_register_pragma, cpp_register_pragma_space): Use
+       _cpp_aligned_alloc.
+       (do_assert, do_unassert): Check for EOL, update.
+       * cppmacro.c (stringify_arg, collect_args): Update to use
+       _cpp_extend_buff and _cpp_append_extend_buff.
+       (save_parameter, parse_params, alloc_expansion_token,
+       _cpp_create_definition): Rework memory management.
+
 2001-09-29  Andris Pavenis  <pavenis@lanet.lv>
 
        * config/i386/xm-djgpp.h (GCC_DRIVER_HOST_INITIALIZATION): Don't
index 874baf2..43ac833 100644 (file)
@@ -42,35 +42,6 @@ struct directive;            /* Deliberately incomplete.  */
    efficiency, and partly to limit runaway recursion.  */
 #define CPP_STACK_MAX 200
 
-/* Memory pools.  */
-#define POOL_ALIGN(size, align) (((size) + ((align) - 1)) & ~((align) - 1))
-#define POOL_FRONT(p) ((p)->cur->front)
-#define POOL_LIMIT(p) ((p)->cur->limit)
-#define POOL_BASE(p)  ((p)->cur->base)
-#define POOL_SIZE(p)  ((p)->cur->limit - (p)->cur->base)
-#define POOL_ROOM(p)  ((p)->cur->limit - (p)->cur->front)
-#define POOL_USED(p)  ((p)->cur->front - (p)->cur->base)
-#define POOL_COMMIT(p, len) do {\
-  ((p)->cur->front += POOL_ALIGN (len, (p)->align));\
-  if ((p)->cur->front > (p)->cur->limit) abort ();} while (0)
-
-typedef struct cpp_chunk cpp_chunk;
-struct cpp_chunk
-{
-  cpp_chunk *next;
-  unsigned char *front;
-  unsigned char *limit;
-  unsigned char *base;
-};
-
-typedef struct cpp_pool cpp_pool;
-struct cpp_pool
-{
-  struct cpp_chunk *cur, *first;
-  unsigned char *pos;          /* Current position.  */
-  unsigned int align;
-};
-
 /* A generic memory buffer.  */
 
 typedef struct _cpp_buff _cpp_buff;
@@ -82,11 +53,13 @@ struct _cpp_buff
 
 extern _cpp_buff *_cpp_get_buff PARAMS ((cpp_reader *, size_t));
 extern void _cpp_release_buff PARAMS ((cpp_reader *, _cpp_buff *));
-extern _cpp_buff *_cpp_extend_buff PARAMS ((cpp_reader *, _cpp_buff *,
-                                           size_t));
+extern void _cpp_extend_buff PARAMS ((cpp_reader *, _cpp_buff **, size_t));
+extern _cpp_buff *_cpp_append_extend_buff PARAMS ((cpp_reader *, _cpp_buff *,
+                                                  size_t));
 extern void _cpp_free_buff PARAMS ((_cpp_buff *));
+extern unsigned char *_cpp_aligned_alloc PARAMS ((cpp_reader *, size_t));
 extern unsigned char *_cpp_unaligned_alloc PARAMS ((cpp_reader *, size_t));
-#define BUFF_ROOM(BUFF) ((BUFF)->limit - (BUFF)->cur)
+#define BUFF_ROOM(BUFF) (size_t) ((BUFF)->limit - (BUFF)->cur)
 #define BUFF_FRONT(BUFF) ((BUFF)->cur)
 #define BUFF_LIMIT(BUFF) ((BUFF)->limit)
 
@@ -270,10 +243,8 @@ struct cpp_reader
   /* The line of the '#' of the current directive.  */
   unsigned int directive_line;
 
-  /* Memory pools.  */
-  cpp_pool macro_pool;         /* For macro definitions.  Permanent.  */
-
   /* Memory buffers.  */
+  _cpp_buff *a_buff;           /* Aligned permanent storage.  */
   _cpp_buff *u_buff;           /* Unaligned permanent storage.  */
   _cpp_buff *free_buffs;       /* Free buffer chain.  */
 
@@ -434,13 +405,6 @@ extern cpp_token *_cpp_lex_direct  PARAMS ((cpp_reader *));
 extern int _cpp_equiv_tokens           PARAMS ((const cpp_token *,
                                                 const cpp_token *));
 extern void _cpp_init_tokenrun         PARAMS ((tokenrun *, unsigned int));
-extern void _cpp_init_pool             PARAMS ((cpp_pool *, unsigned int,
-                                                 unsigned int, unsigned int));
-extern void _cpp_free_pool             PARAMS ((cpp_pool *));
-extern unsigned char *_cpp_pool_reserve PARAMS ((cpp_pool *, unsigned int));
-extern unsigned char *_cpp_pool_alloc  PARAMS ((cpp_pool *, unsigned int));
-extern unsigned char *_cpp_next_chunk  PARAMS ((cpp_pool *, unsigned int,
-                                                unsigned char **));
 
 /* In cppinit.c.  */
 extern bool _cpp_push_next_buffer      PARAMS ((cpp_reader *));
index 5150a0e..45d9b6a 100644 (file)
@@ -527,12 +527,10 @@ cpp_create_reader (table, lang)
   pfile->base_context.macro = 0;
   pfile->base_context.prev = pfile->base_context.next = 0;
 
-  /* Unaligned storage.  */
+  /* Aligned and unaligned storage.  */
+  pfile->a_buff = _cpp_get_buff (pfile, 0);
   pfile->u_buff = _cpp_get_buff (pfile, 0);
 
-  /* Macro pool initially 8K.  Aligned, permanent pool.  */
-  _cpp_init_pool (&pfile->macro_pool, 8 * 1024, 0, 0);
-
   /* Initialise the buffer obstack.  */
   gcc_obstack_init (&pfile->buffer_ob);
 
@@ -585,7 +583,7 @@ cpp_destroy (pfile)
   _cpp_destroy_hashtable (pfile);
   _cpp_cleanup_includes (pfile);
 
-  _cpp_free_pool (&pfile->macro_pool);
+  _cpp_free_buff (pfile->a_buff);
   _cpp_free_buff (pfile->u_buff);
   _cpp_free_buff (pfile->free_buffs);
 
index 26bda36..4a6c483 100644 (file)
@@ -104,8 +104,6 @@ static int maybe_read_ucs PARAMS ((cpp_reader *, const unsigned char **,
                                   const unsigned char *, unsigned int *));
 static tokenrun *next_tokenrun PARAMS ((tokenrun *));
 
-static cpp_chunk *new_chunk PARAMS ((unsigned int));
-static int chunk_suitable PARAMS ((cpp_chunk *, unsigned int));
 static unsigned int hex_digit_value PARAMS ((unsigned int));
 static _cpp_buff *new_buff PARAMS ((size_t));
 
@@ -609,7 +607,7 @@ parse_number (pfile, number, c, leading_period)
     {
       if (dest == limit)
        {
-         pfile->u_buff = _cpp_extend_buff (pfile, pfile->u_buff, 1);
+         _cpp_extend_buff (pfile, &pfile->u_buff, 1);
          dest = BUFF_FRONT (pfile->u_buff);
          limit = BUFF_LIMIT (pfile->u_buff);
        }
@@ -624,7 +622,7 @@ parse_number (pfile, number, c, leading_period)
          if ((size_t) (limit - dest) < 2)
            {
              size_t len_so_far = dest - BUFF_FRONT (pfile->u_buff);
-             pfile->u_buff = _cpp_extend_buff (pfile, pfile->u_buff, 2);
+             _cpp_extend_buff (pfile, &pfile->u_buff, 2);
              dest = BUFF_FRONT (pfile->u_buff) + len_so_far;
              limit = BUFF_LIMIT (pfile->u_buff);
            }
@@ -726,7 +724,7 @@ parse_string (pfile, token, terminator)
       if ((size_t) (limit - dest) < 1)
        {
          size_t len_so_far = dest - BUFF_FRONT (pfile->u_buff);
-         pfile->u_buff = _cpp_extend_buff (pfile, pfile->u_buff, 2);
+         _cpp_extend_buff (pfile, &pfile->u_buff, 2);
          dest = BUFF_FRONT (pfile->u_buff) + len_so_far;
          limit = BUFF_LIMIT (pfile->u_buff);
        }
@@ -2112,20 +2110,42 @@ _cpp_get_buff (pfile, min_size)
   return result;
 }
 
-/* Return a buffer chained on the end of BUFF.  Copy to it the
-   uncommitted remaining bytes of BUFF, with at least MIN_EXTRA more
-   bytes.  */
+/* Creates a new buffer with enough space to hold the the uncommitted
+   remaining bytes of BUFF, and at least MIN_EXTRA more bytes.  Copies
+   the excess bytes to the new buffer.  Chains the new buffer after
+   BUFF, and returns the new buffer.  */
 _cpp_buff *
-_cpp_extend_buff (pfile, buff, min_extra)
+_cpp_append_extend_buff (pfile, buff, min_extra)
      cpp_reader *pfile;
      _cpp_buff *buff;
      size_t min_extra;
 {
   size_t size = EXTENDED_BUFF_SIZE (buff, min_extra);
+  _cpp_buff *new_buff = _cpp_get_buff (pfile, size);
 
-  buff->next = _cpp_get_buff (pfile, size);
-  memcpy (buff->next->base, buff->cur, buff->limit - buff->cur);
-  return buff->next;
+  buff->next = new_buff;
+  memcpy (new_buff->base, buff->cur, BUFF_ROOM (buff));
+  return new_buff;
+}
+
+/* Creates a new buffer with enough space to hold the the uncommitted
+   remaining bytes of the buffer pointed to by BUFF, and at least
+   MIN_EXTRA more bytes.  Copies the excess bytes to the new buffer.
+   Chains the new buffer before the buffer pointed to by BUFF, and
+   updates the pointer to point to the new buffer.  */
+void
+_cpp_extend_buff (pfile, pbuff, min_extra)
+     cpp_reader *pfile;
+     _cpp_buff **pbuff;
+     size_t min_extra;
+{
+  _cpp_buff *new_buff, *old_buff = *pbuff;
+  size_t size = EXTENDED_BUFF_SIZE (old_buff, min_extra);
+
+  new_buff = _cpp_get_buff (pfile, size);
+  memcpy (new_buff->base, old_buff->cur, BUFF_ROOM (old_buff));
+  new_buff->next = old_buff;
+  *pbuff = new_buff;
 }
 
 /* Free a chain of buffers starting at BUFF.  */
@@ -2163,120 +2183,23 @@ _cpp_unaligned_alloc (pfile, len)
   return result;
 }
 
-static int
-chunk_suitable (chunk, size)
-     cpp_chunk *chunk;
-     unsigned int size;
-{
-  /* Being at least twice SIZE means we can use memcpy in
-     _cpp_next_chunk rather than memmove.  Besides, it's a good idea
-     anyway.  */
-  return (chunk && (unsigned int) (chunk->limit - chunk->base) >= size * 2);
-}
-
-/* Returns the end of the new pool.  PTR points to a char in the old
-   pool, and is updated to point to the same char in the new pool.  */
+/* Allocate permanent, unaligned storage of length LEN.  */
 unsigned char *
-_cpp_next_chunk (pool, len, ptr)
-     cpp_pool *pool;
-     unsigned int len;
-     unsigned char **ptr;
-{
-  cpp_chunk *chunk = pool->cur->next;
-
-  /* LEN is the minimum size we want in the new pool.  */
-  len += POOL_ROOM (pool);
-  if (! chunk_suitable (chunk, len))
-    {
-      chunk = new_chunk (POOL_SIZE (pool) * 2 + len);
-
-      chunk->next = pool->cur->next;
-      pool->cur->next = chunk;
-    }
-
-  /* Update the pointer before changing chunk's front.  */
-  if (ptr)
-    *ptr += chunk->base - POOL_FRONT (pool);
-
-  memcpy (chunk->base, POOL_FRONT (pool), POOL_ROOM (pool));
-  chunk->front = chunk->base;
-
-  pool->cur = chunk;
-  return POOL_LIMIT (pool);
-}
-
-static cpp_chunk *
-new_chunk (size)
-     unsigned int size;
-{
-  unsigned char *base;
-  cpp_chunk *result;
-
-  size = POOL_ALIGN (size, DEFAULT_ALIGNMENT);
-  base = (unsigned char *) xmalloc (size + sizeof (cpp_chunk));
-  /* Put the chunk descriptor at the end.  Then chunk overruns will
-     cause obvious chaos.  */
-  result = (cpp_chunk *) (base + size);
-  result->base = base;
-  result->front = base;
-  result->limit = base + size;
-  result->next = 0;
-
-  return result;
-}
-
-void
-_cpp_init_pool (pool, size, align, temp)
-     cpp_pool *pool;
-     unsigned int size, align, temp;
-{
-  if (align == 0)
-    align = DEFAULT_ALIGNMENT;
-  if (align & (align - 1))
-    abort ();
-  pool->align = align;
-  pool->first = new_chunk (size);
-  pool->cur = pool->first;
-  if (temp)
-    pool->cur->next = pool->cur;
-}
-
-void
-_cpp_free_pool (pool)
-     cpp_pool *pool;
+_cpp_aligned_alloc (pfile, len)
+     cpp_reader *pfile;
+     size_t len;
 {
-  cpp_chunk *chunk = pool->first, *next;
+  _cpp_buff *buff = pfile->a_buff;
+  unsigned char *result = buff->cur;
 
-  do
+  if (len > (size_t) (buff->limit - result))
     {
-      next = chunk->next;
-      free (chunk->base);
-      chunk = next;
+      buff = _cpp_get_buff (pfile, len);
+      buff->next = pfile->a_buff;
+      pfile->a_buff = buff;
+      result = buff->cur;
     }
-  while (chunk && chunk != pool->first);
-}
-
-/* Reserve LEN bytes from a memory pool.  */
-unsigned char *
-_cpp_pool_reserve (pool, len)
-     cpp_pool *pool;
-     unsigned int len;
-{
-  len = POOL_ALIGN (len, pool->align);
-  if (len > (unsigned int) POOL_ROOM (pool))
-    _cpp_next_chunk (pool, len, 0);
 
-  return POOL_FRONT (pool);
-}
-
-/* Allocate LEN bytes from a memory pool.  */
-unsigned char *
-_cpp_pool_alloc (pool, len)
-     cpp_pool *pool;
-     unsigned int len;
-{
-  unsigned char *result = _cpp_pool_reserve (pool, len);
-
-  POOL_COMMIT (pool, len);
+  buff->cur = result + len;
   return result;
 }
index 2d5968a..f5d10e0 100644 (file)
@@ -512,7 +512,7 @@ glue_header_name (pfile)
       if ((size_t) (BUFF_LIMIT (pfile->u_buff) - dest) < len)
        {
          size_t len_so_far = dest - BUFF_FRONT (pfile->u_buff);
-         pfile->u_buff = _cpp_extend_buff (pfile, pfile->u_buff, len);
+         _cpp_extend_buff (pfile, &pfile->u_buff, len);
          dest = BUFF_FRONT (pfile->u_buff) + len_so_far;
        }
 
@@ -893,7 +893,7 @@ cpp_register_pragma (pfile, space, name, handler)
 
  found:
   new = (struct pragma_entry *)
-    _cpp_pool_alloc (&pfile->macro_pool, sizeof (struct pragma_entry));
+    _cpp_aligned_alloc (pfile, sizeof (struct pragma_entry));
   new->name = name;
   new->len = strlen (name);
   new->isnspace = 0;
@@ -922,7 +922,7 @@ cpp_register_pragma_space (pfile, space)
     }
 
   new = (struct pragma_entry *)
-    _cpp_pool_alloc (&pfile->macro_pool, sizeof (struct pragma_entry));
+    _cpp_aligned_alloc (pfile, sizeof (struct pragma_entry));
   new->name = space;
   new->len = len;
   new->isnspace = 1;
@@ -1406,12 +1406,7 @@ parse_answer (pfile, answerp, type)
 {
   const cpp_token *paren;
   struct answer *answer;
-
-  if (POOL_FRONT (&pfile->macro_pool) + sizeof (struct answer) >
-      POOL_LIMIT (&pfile->macro_pool))
-    _cpp_next_chunk (&pfile->macro_pool, sizeof (struct answer), 0);
-  answer = (struct answer *) POOL_FRONT (&pfile->macro_pool);
-  answer->count = 0;
+  unsigned int acount;
 
   /* In a conditional, it is legal to not have an open paren.  We
      should save the following token in this case.  */
@@ -1436,18 +1431,12 @@ parse_answer (pfile, answerp, type)
       return 1;
     }
 
-  for (;;)
+  for (acount = 0;; acount++)
     {
-      cpp_token *token = &answer->first[answer->count];
-      /* Check we have room for the token.  */
-      if ((unsigned char *) (token + 1) >= POOL_LIMIT (&pfile->macro_pool))
-       {
-         _cpp_next_chunk (&pfile->macro_pool, sizeof (cpp_token),
-                          (unsigned char **) &answer);
-         token = &answer->first[answer->count];
-       }
+      size_t room_needed;
+      const cpp_token *token = cpp_get_token (pfile);
+      cpp_token *dest;
 
-      *token = *cpp_get_token (pfile);
       if (token->type == CPP_CLOSE_PAREN)
        break;
 
@@ -1456,21 +1445,32 @@ parse_answer (pfile, answerp, type)
          cpp_error (pfile, "missing ')' to complete answer");
          return 1;
        }
-      answer->count++;
+
+      /* struct answer includes the space for one token.  */
+      room_needed = (sizeof (struct answer) + acount * sizeof (cpp_token));
+
+      if (BUFF_ROOM (pfile->a_buff) < room_needed)
+       _cpp_extend_buff (pfile, &pfile->a_buff, sizeof (struct answer));
+
+      dest = &((struct answer *) BUFF_FRONT (pfile->a_buff))->first[acount];
+      *dest = *token;
+
+      /* Drop whitespace at start, for answer equivalence purposes.  */
+      if (acount == 0)
+       dest->flags &= ~PREV_WHITE;
     }
 
-  if (answer->count == 0)
+  if (acount == 0)
     {
       cpp_error (pfile, "predicate's answer is empty");
       return 1;
     }
 
-  /* Drop whitespace at start.  */
-  answer->first->flags &= ~PREV_WHITE;
+  answer = (struct answer *) BUFF_FRONT (pfile->a_buff);
+  answer->count = acount;
+  answer->next = NULL;
   *answerp = answer;
 
-  if (type == T_ASSERT || type == T_UNASSERT)
-    check_eol (pfile);
   return 0;
 }
 
@@ -1580,11 +1580,13 @@ do_assert (pfile)
            }
          new_answer->next = node->value.answers;
        }
+
       node->type = NT_ASSERTION;
       node->value.answers = new_answer;
-      POOL_COMMIT (&pfile->macro_pool, (sizeof (struct answer)
-                                       + (new_answer->count - 1)
-                                       * sizeof (cpp_token)));
+      BUFF_FRONT (pfile->a_buff) += (sizeof (struct answer)
+                                    + (new_answer->count - 1)
+                                    * sizeof (cpp_token));
+      check_eol (pfile);
     }
 }
 
@@ -1611,6 +1613,8 @@ do_unassert (pfile)
          /* Did we free the last answer?  */
          if (node->value.answers == 0)
            node->type = NT_VOID;
+
+         check_eol (pfile);
        }
       else
        _cpp_free_definition (node);
index 7886bdf..845d90b 100644 (file)
@@ -285,7 +285,7 @@ stringify_arg (pfile, arg)
       if ((size_t) (BUFF_LIMIT (pfile->u_buff) - dest) < len)
        {
          size_t len_so_far = dest - BUFF_FRONT (pfile->u_buff);
-         pfile->u_buff = _cpp_extend_buff (pfile, pfile->u_buff, len);
+         _cpp_extend_buff (pfile, &pfile->u_buff, len);
          dest = BUFF_FRONT (pfile->u_buff) + len_so_far;
        }
 
@@ -465,8 +465,8 @@ collect_args (pfile, node)
          /* Require space for 2 new tokens (including a CPP_EOF).  */
          if ((unsigned char *) &arg->first[ntokens + 2] > buff->limit)
            {
-             buff = _cpp_extend_buff (pfile, buff,
-                                      1000 * sizeof (cpp_token *));
+             buff = _cpp_append_extend_buff (pfile, buff,
+                                             1000 * sizeof (cpp_token *));
              arg->first = (const cpp_token **) buff->cur;
            }
 
@@ -1129,8 +1129,6 @@ save_parameter (pfile, macro, node)
      cpp_macro *macro;
      cpp_hashnode *node;
 {
-  cpp_hashnode **dest;
-
   /* Constraint 6.10.3.6 - duplicate parameter names.  */
   if (node->arg_index)
     {
@@ -1138,22 +1136,16 @@ save_parameter (pfile, macro, node)
       return 1;
     }
 
-  dest = &macro->params[macro->paramc];
-
-  /* Check we have room for the parameters.  */
-  if ((unsigned char *) (dest + 1) >= POOL_LIMIT (&pfile->macro_pool))
-    {
-      _cpp_next_chunk (&pfile->macro_pool, sizeof (cpp_hashnode *),
-                      (unsigned char **) &macro->params);
-      dest = &macro->params[macro->paramc];
-    }
+  if (BUFF_ROOM (pfile->a_buff)
+      < (macro->paramc + 1) * sizeof (cpp_hashnode *))
+    _cpp_extend_buff (pfile, &pfile->a_buff, sizeof (cpp_hashnode *));
 
-  *dest = node;
-  node->arg_index = ++macro->paramc;
+  ((cpp_hashnode **) BUFF_FRONT (pfile->a_buff))[macro->paramc++] = node;
+  node->arg_index = macro->paramc;
   return 0;
 }
 
-/* Check the syntax of the paramters in a MACRO definition.  */
+/* Check the syntax of the parameters in a MACRO definition.  */
 static int
 parse_params (pfile, macro)
      cpp_reader *pfile;
@@ -1161,7 +1153,6 @@ parse_params (pfile, macro)
 {
   unsigned int prev_ident = 0;
 
-  macro->params = (cpp_hashnode **) POOL_FRONT (&pfile->macro_pool);
   for (;;)
     {
       const cpp_token *token = _cpp_lex_token (pfile);
@@ -1187,7 +1178,7 @@ parse_params (pfile, macro)
 
        case CPP_CLOSE_PAREN:
          if (prev_ident || macro->paramc == 0)
-           break;
+           return 1;
 
          /* Fall through to pick up the error.  */
        case CPP_COMMA:
@@ -1215,18 +1206,13 @@ parse_params (pfile, macro)
          /* We're at the end, and just expect a closing parenthesis.  */
          token = _cpp_lex_token (pfile);
          if (token->type == CPP_CLOSE_PAREN)
-           break;
+           return 1;
          /* Fall through.  */
 
        case CPP_EOF:
          cpp_error (pfile, "missing ')' in macro parameter list");
          return 0;
        }
-
-      /* Success.  Commit the parameter array.  */
-      POOL_COMMIT (&pfile->macro_pool,
-                  macro->paramc * sizeof (cpp_hashnode *));
-      return 1;
     }
 }
 
@@ -1236,18 +1222,10 @@ alloc_expansion_token (pfile, macro)
      cpp_reader *pfile;
      cpp_macro *macro;
 {
-  cpp_token *token = &macro->expansion[macro->count];
-
-  /* Check we have room for the token.  */
-  if ((unsigned char *) (token + 1) >= POOL_LIMIT (&pfile->macro_pool))
-    {
-      _cpp_next_chunk (&pfile->macro_pool, sizeof (cpp_token),
-                      (unsigned char **) &macro->expansion);
-      token = &macro->expansion[macro->count];
-    }
+  if (BUFF_ROOM (pfile->a_buff) < (macro->count + 1) * sizeof (cpp_token))
+    _cpp_extend_buff (pfile, &pfile->a_buff, sizeof (cpp_token));
 
-  macro->count++;
-  return token;
+  return &((cpp_token *) BUFF_FRONT (pfile->a_buff))[macro->count++];
 }
 
 static cpp_token *
@@ -1284,8 +1262,7 @@ _cpp_create_definition (pfile, node)
   const cpp_token *ctoken;
   unsigned int i, ok = 1;
 
-  macro = (cpp_macro *) _cpp_pool_alloc (&pfile->macro_pool,
-                                        sizeof (cpp_macro));
+  macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
   macro->line = pfile->directive_line;
   macro->params = 0;
   macro->paramc = 0;
@@ -1299,8 +1276,13 @@ _cpp_create_definition (pfile, node)
 
   if (ctoken->type == CPP_OPEN_PAREN && !(ctoken->flags & PREV_WHITE))
     {
-      if (!(ok = parse_params (pfile, macro)))
+      ok = parse_params (pfile, macro);
+      macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff);
+      if (!ok)
        goto cleanup2;
+
+      /* Success.  Commit the parameter array.  */
+      BUFF_FRONT (pfile->a_buff) = (U_CHAR *) &macro->params[macro->paramc];
       macro->fun_like = 1;
     }
   else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE))
@@ -1308,7 +1290,6 @@ _cpp_create_definition (pfile, node)
 
   pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
   saved_cur_token = pfile->cur_token;
-  macro->expansion = (cpp_token *) POOL_FRONT (&pfile->macro_pool);
 
   if (macro->fun_like)
     token = lex_expansion_token (pfile, macro);
@@ -1366,9 +1347,18 @@ _cpp_create_definition (pfile, node)
       token = lex_expansion_token (pfile, macro);
     }
 
+  macro->expansion = (cpp_token *) BUFF_FRONT (pfile->a_buff);
+
   /* Don't count the CPP_EOF.  */
   macro->count--;
 
+  /* Clear whitespace on first token for macro equivalence purposes.  */
+  if (macro->count)
+    macro->expansion[0].flags &= ~PREV_WHITE;
+
+  /* Commit the memory.  */
+  BUFF_FRONT (pfile->a_buff) = (U_CHAR *) &macro->expansion[macro->count];
+
   /* Implement the macro-defined-to-itself optimisation.  */
   macro->disabled = (macro->count == 1 && !macro->fun_like
                     && macro->expansion[0].type == CPP_NAME
@@ -1377,9 +1367,6 @@ _cpp_create_definition (pfile, node)
   /* To suppress some diagnostics.  */
   macro->syshdr = pfile->map->sysp != 0;
 
-  /* Commit the memory.  */
-  POOL_COMMIT (&pfile->macro_pool, macro->count * sizeof (cpp_token));
-
   if (node->type != NT_VOID)
     {
       if (warn_of_redefinition (pfile, node, macro))
index 86807a2..0e8f92e 100644 (file)
@@ -1,3 +1,7 @@
+2001-09-30  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * gcc.dg/cpp/redef2.c: Add test.
+
 2001-09-27  Geoffrey Keating  <geoffk@redhat.com>
 
        * gcc.c-torture/execute/loop-2e.x: This is a manifestation of a
index 1656ab8..7001d67 100644 (file)
@@ -14,6 +14,9 @@
 #define va(a...) a
 #define va(...) __VA_ARGS__
 
+#define foo(x) x
+#define foo(x)x                /* { dg-bogus "redefined" "redefined foo" } */
+
 /* { dg-warning "redefined" "redef mac"     { target *-*-* } 7  }
    { dg-warning "redefined" "redef mac"     { target *-*-* } 8  }
    { dg-warning "redefined" "redef mac"     { target *-*-* } 9  }