bison-patches
[Top][All Lists]
Advanced

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

FYI: fixed yycheck signed/unsigned comparison warnings


From: Joel E. Denny
Subject: FYI: fixed yycheck signed/unsigned comparison warnings
Date: Wed, 9 Aug 2006 21:18:44 -0400 (EDT)

I configure bison with --enable-gcc-warnings.  I tried adding a new token 
to parse-gram.y today, but it failed to compile as gcc complained of 
comparisons between signed and unsigned for yycheck.  The following patch, 
which I've committed, isn't perfect (what if yycheck[i] is an unsigned 
int?), but it works for me for now.

Joel

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1542
diff -p -u -r1.1542 ChangeLog
--- ChangeLog   9 Aug 2006 17:13:46 -0000       1.1542
+++ ChangeLog   10 Aug 2006 01:01:31 -0000
@@ -1,3 +1,13 @@
+2006-08-09  Joel E. Denny  <address@hidden>
+
+       Suppress signed/unsigned comparison warnings for yycheck.
+       * data/c.m4 (b4_safest_int_type): New macro.
+       * data/glr.c, data/lalr1.cc: Wherever you compare yycheck[i] against
+       a signed int type, cast it to b4_safest_int_type first.
+       * data/yacc.c: Likewise.
+       (b4_safest_int_type): Overwrite the one from c.m4 since b4_int_type is
+       also overwritten.
+
 2006-08-09  Ralf Wildenhues <address@hidden>  (tiny change)
 
        * doc/bison.texinfo: Fix some typos.
Index: data/c.m4
===================================================================
RCS file: /sources/bison/bison/data/c.m4,v
retrieving revision 1.62
diff -p -u -r1.62 c.m4
--- data/c.m4   12 Jul 2006 13:48:41 -0000      1.62
+++ data/c.m4   10 Aug 2006 01:01:31 -0000
@@ -164,6 +164,11 @@ m4_define([b4_int_type],
 
                                               [int])])
 
+# b4_safest_int_type
+# ------------------
+# The safest int type to cast to when it's necessary to compare a signed int
+# type against an int type set by b4_int_type.
+m4_define([b4_safest_int_type],[int])
 
 # b4_int_type_for(NAME)
 # ---------------------
Index: data/glr.c
===================================================================
RCS file: /sources/bison/bison/data/glr.c,v
retrieving revision 1.186
diff -p -u -r1.186 glr.c
--- data/glr.c  29 Jul 2006 04:11:32 -0000      1.186
+++ data/glr.c  10 Aug 2006 01:01:32 -0000
@@ -1048,7 +1048,8 @@ yygetLRActions (yyStateNum yystate, int 
                int* yyaction, const short int** yyconflicts)
 {
   int yyindex = yypact[yystate] + yytoken;
-  if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
+  if (yyindex < 0 || YYLAST < yyindex
+      || (]b4_safest_int_type[)yycheck[yyindex] != yytoken)
     {
       *yyaction = -yydefact[yystate];
       *yyconflicts = yyconfl;
@@ -1070,7 +1071,8 @@ yyLRgotoState (yyStateNum yystate, yySym
 {
   int yyr;
   yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
-  if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
+  if (0 <= yyr && yyr <= YYLAST
+      && (]b4_safest_int_type[)yycheck[yyr] == yystate)
     return yytable[yyr];
   else
     return yydefgoto[yylhs - YYNTOKENS];
@@ -2120,7 +2122,8 @@ yyreportSyntaxError (yyGLRStack* yystack
          yyfmt = yystpcpy (yyformat, yyunexpected);
 
          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
-           if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+           if ((]b4_safest_int_type[)yycheck[yyx + yyn] == yyx
+                && yyx != YYTERROR)
              {
                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
                  {
@@ -2216,7 +2219,8 @@ yyrecoverSyntaxError (yyGLRStack* yystac
        if (yyis_pact_ninf (yyj))
          return;
        yyj += yytoken;
-       if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken)
+       if (yyj < 0 || YYLAST < yyj
+            || (]b4_safest_int_type[)yycheck[yyj] != yytoken)
          {
            if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0)
              return;
Index: data/lalr1.cc
===================================================================
RCS file: /sources/bison/bison/data/lalr1.cc,v
retrieving revision 1.139
diff -p -u -r1.139 lalr1.cc
--- data/lalr1.cc       29 Jul 2006 04:11:33 -0000      1.139
+++ data/lalr1.cc       10 Aug 2006 01:01:32 -0000
@@ -608,7 +608,8 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_para
     /* If the proper action on seeing token YYTOKEN is to reduce or to
        detect an error, take that action.  */
     yyn += yytoken;
-    if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
+    if (yyn < 0 || yylast_ < yyn
+        || (]b4_safest_int_type[)yycheck_[yyn] != yytoken)
       goto yydefault;
 
     /* Reduce or error.  */
@@ -686,7 +687,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_para
     yyn = yyr1_[yyn];
     yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
     if (0 <= yystate && yystate <= yylast_
-       && yycheck_[yystate] == yystate_stack_[0])
+       && (]b4_safest_int_type[)yycheck_[yystate] == yystate_stack_[0])
       yystate = yytable_[yystate];
     else
       yystate = yydefgoto_[yyn - yyntokens_];
@@ -759,7 +760,8 @@ b4_error_verbose_if([, yytoken])[));
        if (yyn != yypact_ninf_)
        {
          yyn += yyterror_;
-         if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
+         if (0 <= yyn && yyn <= yylast_
+              && (]b4_safest_int_type[)yycheck_[yyn] == yyterror_)
            {
              yyn = yytable_[yyn];
              if (0 < yyn)
@@ -843,7 +845,7 @@ b4_error_verbose_if([, int tok])[)
        int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
        int count = 0;
        for (int x = yyxbegin; x < yyxend; ++x)
-         if (yycheck_[x + yyn] == x && x != yyterror_)
+         if ((]b4_safest_int_type[)yycheck_[x + yyn] == x && x != yyterror_)
            ++count;
 
        // FIXME: This method of building the message is not compatible
@@ -860,7 +862,8 @@ b4_error_verbose_if([, int tok])[)
          {
            count = 0;
            for (int x = yyxbegin; x < yyxend; ++x)
-             if (yycheck_[x + yyn] == x && x != yyterror_)
+             if ((]b4_safest_int_type[)yycheck_[x + yyn] == x
+                  && x != yyterror_)
                {
                  res += (!count++) ? ", expecting " : " or ";
                  res += yytnamerr_ (yytname_[x]);
Index: data/yacc.c
===================================================================
RCS file: /sources/bison/bison/data/yacc.c,v
retrieving revision 1.151
diff -p -u -r1.151 yacc.c
--- data/yacc.c 29 Jul 2006 04:11:33 -0000      1.151
+++ data/yacc.c 10 Aug 2006 01:01:32 -0000
@@ -86,6 +86,15 @@ m4_define([b4_int_type],
                                               [int])])
 
 
+# b4_safest_int_type
+# ------------------
+# The safest int type to cast to when it's necessary to compare a signed int
+# type against an int type set by b4_int_type.  Overwrite the version from
+# c.m4 as a reminder to keep it consistent with the overwritten b4_int_type.
+m4_define([b4_safest_int_type],[int])
+
+
+
 ## ----------------- ##
 ## Semantic Values.  ##
 ## ----------------- ##
@@ -900,7 +909,7 @@ yysyntax_error (char *yyresult, int yyst
       yyfmt = yystpcpy (yyformat, yyunexpected);
 
       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
-       if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+       if ((]b4_safest_int_type[)yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
          {
            if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
              {
@@ -1205,7 +1214,7 @@ yybackup:
   /* If the proper action on seeing token YYTOKEN is to reduce or to
      detect an error, take that action.  */
   yyn += yytoken;
-  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+  if (yyn < 0 || YYLAST < yyn || (]b4_safest_int_type[)yycheck[yyn] != yytoken)
     goto yydefault;
   yyn = yytable[yyn];
   if (yyn <= 0)
@@ -1285,7 +1294,8 @@ yyreduce:
   yyn = yyr1[yyn];
 
   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
-  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+  if (0 <= yystate && yystate <= YYLAST
+      && (]b4_safest_int_type[)yycheck[yystate] == *yyssp)
     yystate = yytable[yystate];
   else
     yystate = yydefgoto[yyn - YYNTOKENS];




reply via email to

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