bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [GNU Bison 2.3] testsuite: 103 104 failed


From: Paul Eggert
Subject: Re: [GNU Bison 2.3] testsuite: 103 104 failed
Date: Fri, 15 Sep 2006 09:41:05 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Michael Deutschmann <address@hidden> writes:

> First, there are two places in the code -- in parse_gram.y and scan-code.l
> -- where a new variable is declared in the middle of code, rather than at
> the start.  I'm using an older version of GCC (2.95.3, long story) which
> happens to object to that.
>
> After some quick line reordering to fix that, all but one test succeeded.
> The new problem is #133, which tests that a certain parser definition
> produces C code containing the line "tests = {{{{{{{{{{}}}}}}}}}};".  The
> actual output instead contains "tests = {{{{{{{{{{;};};};};};};};};};};".

Thanks for reporting these problems.  They prompted me to dust off my
old copy of GCC 2.95 (cough cough! wow! it's pretty dusty!) and I
found that there are also portability problems with its use of
<assert.h>, at least in the 2.95 shipped with Debian stable.  I
installed the following patch, which should fix the problems you
mention.

2006-09-15  Paul Eggert  <address@hidden>

        Port to GCC 2.95.  First two problems reported by Michael Deutschmann in
        <http://lists.gnu.org/archive/html/bug-bison/2006-09/msg00018.html>.

        * src/parse-gram.y (symbol_declaration): Don't put statements
        before declarations; it's not portable to C89.
        * src/scan-code.l (handle_action_at): Likewise.

        * src/scan-code.l: Always initialize braces_level; the old code
        left it uninitialized and therefore had undefined behavior.

        Don't attempt to redefine 'assert', since it runs afoul of
        systems where standard headers (mistakenly) include <assert.h>.
        Instead, define and use our own alternative, called 'aver'.
        * src/reader.c: Don't include assert.h, since we no longer
        use assert.
        * src/scan-code.l: Likewise.
        * src/system.h (assert): Remove, replacing with....
        (aver): New function, taking a bool arg.  All uses changed.
        * src/tables.c (pack_vector): Ensure that aver arg is bool,
        not merely an integer.

Index: src/LR0.c
===================================================================
RCS file: /cvsroot/bison/bison/src/LR0.c,v
retrieving revision 1.95
diff -p -u -r1.95 LR0.c
--- src/LR0.c   9 Dec 2005 23:51:25 -0000       1.95
+++ src/LR0.c   15 Sep 2006 16:26:39 -0000
@@ -1,7 +1,7 @@
 /* Generate the nondeterministic finite state machine for Bison.
 
-   Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2004, 2005 Free
-   Software Foundation, Inc.
+   Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2004, 2005, 2006
+   Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -282,7 +282,7 @@ save_reductions (state *s)
          if (r == 0)
            {
              /* This is "reduce 0", i.e., accept. */
-             assert (!final_state);
+             aver (!final_state);
              final_state = s;
            }
        }
Index: src/lalr.c
===================================================================
RCS file: /cvsroot/bison/bison/src/lalr.c,v
retrieving revision 1.109
diff -p -u -r1.109 lalr.c
--- src/lalr.c  10 Jun 2006 03:02:23 -0000      1.109
+++ src/lalr.c  15 Sep 2006 16:26:39 -0000
@@ -94,7 +94,7 @@ set_goto_map (void)
          ngotos++;
 
          /* Abort if (ngotos + 1) would overflow.  */
-         assert (ngotos != GOTO_NUMBER_MAXIMUM);
+         aver (ngotos != GOTO_NUMBER_MAXIMUM);
 
          goto_map[TRANSITION_SYMBOL (sp, i) - ntokens]++;
        }
@@ -153,7 +153,7 @@ map_goto (state_number s0, symbol_number
 
   for (;;)
     {
-      assert (low <= high);
+      aver (low <= high);
       middle = (low + high) / 2;
       s = from_state[middle];
       if (s == s0)
Index: src/nullable.c
===================================================================
RCS file: /cvsroot/bison/bison/src/nullable.c,v
retrieving revision 1.48
diff -p -u -r1.48 nullable.c
--- src/nullable.c      21 Jan 2006 04:35:09 -0000      1.48
+++ src/nullable.c      15 Sep 2006 16:26:39 -0000
@@ -104,8 +104,8 @@ nullable_compute (void)
        else
          {
            /* This rule has an empty RHS. */
-           assert (item_number_as_rule_number (rules_ruleno->rhs[0])
-                   == ruleno);
+           aver (item_number_as_rule_number (rules_ruleno->rhs[0])
+                 == ruleno);
            if (rules_ruleno->useful
                && ! nullable[rules_ruleno->lhs->number - ntokens])
              {
Index: src/output.c
===================================================================
RCS file: /cvsroot/bison/bison/src/output.c,v
retrieving revision 1.254
diff -p -u -r1.254 output.c
--- src/output.c        15 Sep 2006 15:56:26 -0000      1.254
+++ src/output.c        15 Sep 2006 16:26:39 -0000
@@ -235,7 +235,7 @@ prepare_rules (void)
       /* Merger-function index (GLR).  */
       merger[r] = rules[r].merger;
     }
-  assert (i == nritems);
+  aver (i == nritems);
 
   muscle_insert_item_number_table ("rhs", rhs, ritem[0], 1, nritems);
   muscle_insert_unsigned_int_table ("prhs", prhs, 0, 0, nrules);
@@ -342,7 +342,7 @@ token_definitions_output (FILE *out)
       /* At this stage, if there are literal aliases, they are part of
         SYMBOLS, so we should not find symbols which are the aliases
         here.  */
-      assert (number != USER_NUMBER_ALIAS);
+      aver (number != USER_NUMBER_ALIAS);
 
       /* Skip error token.  */
       if (sym == errtoken)
Index: src/parse-gram.y
===================================================================
RCS file: /cvsroot/bison/bison/src/parse-gram.y,v
retrieving revision 1.91
diff -p -u -r1.91 parse-gram.y
--- src/parse-gram.y    15 Sep 2006 15:56:26 -0000      1.91
+++ src/parse-gram.y    15 Sep 2006 16:26:39 -0000
@@ -345,8 +345,8 @@ symbol_declaration:
     }
 | "%type" TYPE symbols.1
     {
-      tag_seen = true;
       symbol_list *list;
+      tag_seen = true;
       for (list = $3; list; list = list->next)
        symbol_type_set (list->content.sym, $2, @2);
       symbol_list_free ($3);
Index: src/reader.c
===================================================================
RCS file: /cvsroot/bison/bison/src/reader.c,v
retrieving revision 1.271
diff -p -u -r1.271 reader.c
--- src/reader.c        4 Sep 2006 19:29:29 -0000       1.271
+++ src/reader.c        15 Sep 2006 16:26:39 -0000
@@ -22,7 +22,6 @@
 
 #include <config.h>
 #include "system.h"
-#include <assert.h>
 
 #include <quotearg.h>
 
@@ -148,7 +147,7 @@ record_merge_function_type (int merger, 
        merge_function != NULL && merger_find != merger;
        merge_function = merge_function->next)
     merger_find += 1;
-  assert (merge_function != NULL && merger_find == merger);
+  aver (merge_function != NULL && merger_find == merger);
   if (merge_function->type != NULL && !UNIQSTR_EQ (merge_function->type, type))
     {
       complain_at (declaration_loc,
@@ -515,15 +514,15 @@ packgram (void)
        }
       /* An item ends by the rule number (negated).  */
       ritem[itemno++] = rule_number_as_item_number (ruleno);
-      assert (itemno < ITEM_NUMBER_MAX);
+      aver (itemno < ITEM_NUMBER_MAX);
       ++ruleno;
-      assert (ruleno < RULE_NUMBER_MAX);
+      aver (ruleno < RULE_NUMBER_MAX);
 
       if (p)
        p = p->next;
     }
 
-  assert (itemno == nritems);
+  aver (itemno == nritems);
 
   if (trace_flag & trace_sets)
     ritem_print (stderr);
@@ -614,7 +613,7 @@ check_and_convert_grammar (void)
                node = node->next)
             ;
         }
-      assert (node != NULL);
+      aver (node != NULL);
       grammar_start_symbol_set (node->content.sym,
                                 node->content.sym->location);
     }
@@ -635,7 +634,7 @@ check_and_convert_grammar (void)
     grammar = p;
   }
 
-  assert (nsyms <= SYMBOL_NUMBER_MAXIMUM && nsyms == ntokens + nvars);
+  aver (nsyms <= SYMBOL_NUMBER_MAXIMUM && nsyms == ntokens + nvars);
 
   /* Assign the symbols their symbol numbers.  Write #defines for the
      token symbols into FDEFINES if requested.  */
Index: src/scan-code.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-code.l,v
retrieving revision 1.12
diff -p -u -r1.12 scan-code.l
--- src/scan-code.l     4 Sep 2006 19:29:29 -0000       1.12
+++ src/scan-code.l     15 Sep 2006 16:26:39 -0000
@@ -35,7 +35,6 @@
 #include "complain.h"
 #include "reader.h"
 #include "getargs.h"
-#include <assert.h>
 #include <get-errno.h>
 #include <quote.h>
 
@@ -79,14 +78,14 @@ splice       (\\[ \f\t\v]*\n)*
 
 %{
   /* Nesting level of the current code in braces.  */
-  int braces_level IF_LINT (= 0);
+  int braces_level = 0;
 
   /* This scanner is special: it is invoked only once, henceforth
      is expected to return only once.  This initialization is
      therefore done once per action to translate. */
-  assert (sc_context == SC_SYMBOL_ACTION
-         || sc_context == SC_RULE_ACTION
-         || sc_context == INITIAL);
+  aver (sc_context == SC_SYMBOL_ACTION
+       || sc_context == SC_RULE_ACTION
+       || sc_context == INITIAL);
   BEGIN sc_context;
 %}
 
@@ -339,13 +338,12 @@ static void
 handle_action_at (symbol_list *rule, char *text, location at_loc)
 {
   char *cp = text + 1;
-  locations_flag = true;
-  int effective_rule_length;
+  int effective_rule_length =
+    (rule->midrule_parent_rule
+     ? rule->midrule_parent_rhs_index - 1
+     : symbol_list_length (rule->next));
 
-  if (rule->midrule_parent_rule)
-    effective_rule_length = rule->midrule_parent_rhs_index - 1;
-  else
-    effective_rule_length = symbol_list_length (rule->next);
+  locations_flag = true;
 
   if (*cp == '$')
     obstack_sgrow (&obstack_for_string, "]b4_lhs_location[");
Index: src/state.c
===================================================================
RCS file: /cvsroot/bison/bison/src/state.c,v
retrieving revision 1.41
diff -p -u -r1.41 state.c
--- src/state.c 10 Jun 2006 03:02:23 -0000      1.41
+++ src/state.c 15 Sep 2006 16:26:39 -0000
@@ -61,7 +61,7 @@ transitions_to (transitions *shifts, sym
   int j;
   for (j = 0; ; j++)
     {
-      assert (j < shifts->num);
+      aver (j < shifts->num);
       if (TRANSITION_SYMBOL (shifts, j) == sym)
        return shifts->states[j];
     }
@@ -135,7 +135,7 @@ state_new (symbol_number accessing_symbo
   state *res;
   size_t items_size = nitems * sizeof *core;
 
-  assert (nstates < STATE_NUMBER_MAXIMUM);
+  aver (nstates < STATE_NUMBER_MAXIMUM);
 
   res = xmalloc (offsetof (state, items) + items_size);
   res->number = nstates++;
@@ -176,7 +176,7 @@ state_free (state *s)
 void
 state_transitions_set (state *s, int num, state **trans)
 {
-  assert (!s->transitions);
+  aver (!s->transitions);
   s->transitions = transitions_new (num, trans);
 }
 
@@ -188,7 +188,7 @@ state_transitions_set (state *s, int num
 void
 state_reductions_set (state *s, int num, rule **reds)
 {
-  assert (!s->reductions);
+  aver (!s->reductions);
   s->reductions = reductions_new (num, reds);
 }
 
@@ -212,7 +212,7 @@ state_reduction_find (state *s, rule *r)
 void
 state_errs_set (state *s, int num, symbol **tokens)
 {
-  assert (!s->errs);
+  aver (!s->errs);
   s->errs = errs_new (num, tokens);
 }
 
Index: src/symlist.c
===================================================================
RCS file: /cvsroot/bison/bison/src/symlist.c,v
retrieving revision 1.21
diff -p -u -r1.21 symlist.c
--- src/symlist.c       4 Sep 2006 22:20:52 -0000       1.21
+++ src/symlist.c       15 Sep 2006 16:26:39 -0000
@@ -185,7 +185,7 @@ symbol_list_n_type_name_get (symbol_list
       complain_at (loc, _("invalid $ value: $%d"), n);
       return NULL;
     }
-  assert (l->content_type == SYMLIST_SYMBOL);
+  aver (l->content_type == SYMLIST_SYMBOL);
   return l->content.sym->type_name;
 }
 
Index: src/symtab.c
===================================================================
RCS file: /cvsroot/bison/bison/src/symtab.c,v
retrieving revision 1.81
diff -p -u -r1.81 symtab.c
--- src/symtab.c        4 Sep 2006 22:20:52 -0000       1.81
+++ src/symtab.c        15 Sep 2006 16:26:39 -0000
@@ -383,7 +383,7 @@ symbol_user_token_number_set (symbol *sy
 {
   int *user_token_numberp;
 
-  assert (sym->class == token_sym);
+  aver (sym->class == token_sym);
 
   if (sym->user_token_number != USER_NUMBER_ALIAS)
     user_token_numberp = &sym->user_token_number;
@@ -546,7 +546,7 @@ symbol_pack (symbol *this)
            this->number = this->alias->number = 0;
          else
            {
-             assert (this->alias->number != NUMBER_UNDEFINED);
+             aver (this->alias->number != NUMBER_UNDEFINED);
              this->number = this->alias->number;
            }
        }
@@ -555,7 +555,7 @@ symbol_pack (symbol *this)
        return true;
     }
   else /* this->class == token_sym */
-    assert (this->number != NUMBER_UNDEFINED);
+    aver (this->number != NUMBER_UNDEFINED);
 
   symbols[this->number] = this;
   return true;
Index: src/system.h
===================================================================
RCS file: /cvsroot/bison/bison/src/system.h,v
retrieving revision 1.78
diff -p -u -r1.78 system.h
--- src/system.h        9 Jul 2006 03:44:51 -0000       1.78
+++ src/system.h        15 Sep 2006 16:26:39 -0000
@@ -136,6 +136,21 @@ typedef size_t uintptr_t;
 #include <stdbool.h>
 
 
+
+/*-------------.
+| Assertions.  |
+`-------------*/
+
+/* <assert.h>'s assertions are too heavyweight, and can be disabled
+   too easily, so use aver rather than assert.  */
+static inline void
+aver (bool assertion)
+{
+  if (! assertion)
+    abort ();
+}
+
+
 /*-----------.
 | Obstacks.  |
 `-----------*/
@@ -210,11 +225,6 @@ do {                                               \
 } while (0)
 
 
-/* Assertions.  <assert.h>'s assertions are too heavyweight, and can
-   be disabled too easily, so implement it separately here.  */
-#define assert(x) ((void) ((x) || (abort (), 0)))
-
-
 /*---------------------------------------------.
 | Debugging memory allocation (must be last).  |
 `---------------------------------------------*/
Index: src/tables.c
===================================================================
RCS file: /cvsroot/bison/bison/src/tables.c,v
retrieving revision 1.32
diff -p -u -r1.32 tables.c
--- src/tables.c        10 Jun 2006 03:02:23 -0000      1.32
+++ src/tables.c        15 Sep 2006 16:26:39 -0000
@@ -1,7 +1,7 @@
 /* Output the generated parsing program for Bison.
 
    Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003, 2004,
-   2005 Free Software Foundation, Inc.
+   2005, 2006 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -202,14 +202,14 @@ conflict_row (state *s)
              && (actrow[j]
                  != rule_number_as_item_number (reds->rules[i]->number)))
            {
-             assert (0 < conflict_list_free);
+             aver (0 < conflict_list_free);
              conflict_list[conflict_list_cnt] = reds->rules[i]->number + 1;
              conflict_list_cnt += 1;
              conflict_list_free -= 1;
            }
 
        /* Leave a 0 at the end.  */
-       assert (0 < conflict_list_free);
+       aver (0 < conflict_list_free);
        conflict_list[conflict_list_cnt] = 0;
        conflict_list_cnt += 1;
        conflict_list_free -= 1;
@@ -673,14 +673,14 @@ pack_vector (vector_number vector)
   base_number *to = tos[i];
   unsigned int *conflict_to = conflict_tos[i];
 
-  assert (t);
+  aver (t != 0);
 
   for (j = lowzero - from[0]; ; j++)
     {
       int k;
       bool ok = true;
 
-      assert (j < table_size);
+      aver (j < table_size);
 
       for (k = 0; ok && k < t; k++)
        {
@@ -713,7 +713,7 @@ pack_vector (vector_number vector)
          if (loc > high)
            high = loc;
 
-         assert (BASE_MINIMUM <= j && j <= BASE_MAXIMUM);
+         aver (BASE_MINIMUM <= j && j <= BASE_MAXIMUM);
          return j;
        }
     }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]