bison-patches
[Top][All Lists]
Advanced

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

Re: [patch #9620] spurious compiler warning: "potential null pointer der


From: Akim Demaille
Subject: Re: [patch #9620] spurious compiler warning: "potential null pointer dereference"
Date: Sat, 12 May 2018 13:39:05 +0200

>>> Would `default: abort` suit you?
>> 
>> Mostly what bothers me is the compiler warning, so anything that
>> avoids that is basically fine with me.
> 
> I’ll try that then.

Well, that would require <stdlib.h>, which we don’t want to use.
So I used your approach as follows.  I’ll install unless someone
objects.

commit 2b5a27ba3db0f86d37eaef157cc5562082144ff3
Author: Akim Demaille <address@hidden>
Date:   Sat May 12 13:21:24 2018 +0200

    Avoid compiler warnings
    
    At least GCC 7.3, with -O1 or -O2 (but not -O0 or -O3) generates
    warnings with -Wnull-dereference when using yyformat: it fails to see
    yyformat cannot be null.
    
    Reported by Frank Heckenbach, https://savannah.gnu.org/patch/?9620.
    
    * configure.ac: Use -Wnull-dereference if supported.
    * data/glr.c, data/lalr1.cc, data/yacc.c: Define yyformat in such
    a way that GCC cannot not see that yyformat is defined.
    Using `default: abort();` also addresses the issue, but forces
    the inclusion of `stdlib.h`, which we avoid.

diff --git a/configure.ac b/configure.ac
index 5dc274fc..da94e969 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,7 +82,7 @@ AC_ARG_ENABLE([gcc-warnings],
 AM_CONDITIONAL([ENABLE_GCC_WARNINGS], [test "$enable_gcc_warnings" = yes])
 if test "$enable_gcc_warnings" = yes; then
   warn_common='-Wall -Wextra -Wno-sign-compare -Wcast-align -Wdocumentation
-    -Wformat -Wpointer-arith -Wwrite-strings'
+    -Wformat -Wnull-dereference -Wpointer-arith -Wwrite-strings'
   warn_c='-Wbad-function-cast -Wshadow -Wstrict-prototypes'
   warn_cxx='-Wnoexcept'
   # Warnings for the test suite only.
diff --git a/data/glr.c b/data/glr.c
index 4fe24913..f70069ea 100644
--- a/data/glr.c
+++ b/data/glr.c
@@ -2086,6 +2086,7 @@ yyreportSyntaxError (yyGLRStack* 
yystackp]b4_user_formals[)
       case N:                           \
         yyformat = S;                   \
       break
+    default: /* Avoid compiler warnings. */
       YYCASE_(0, YY_("syntax error"));
       YYCASE_(1, YY_("syntax error, unexpected %s"));
       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 4b071d08..3013570e 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -1077,6 +1077,7 @@ b4_error_verbose_if([state_type yystate, const 
symbol_type& yyla],
         case N:                               \
           yyformat = S;                       \
         break
+      default: // Avoid compiler warnings.
         YYCASE_ (0, YY_("syntax error"));
         YYCASE_ (1, YY_("syntax error, unexpected %s"));
         YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s"));
diff --git a/data/yacc.c b/data/yacc.c
index e974319f..8e03c32f 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -1207,6 +1207,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
       case N:                               \
         yyformat = S;                       \
       break
+    default: /* Avoid compiler warnings. */
       YYCASE_(0, YY_("syntax error"));
       YYCASE_(1, YY_("syntax error, unexpected %s"));
       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));




reply via email to

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