bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH 5/5] bison: pacify Sun C 5.12


From: Akim Demaille
Subject: Re: [PATCH 5/5] bison: pacify Sun C 5.12
Date: Wed, 23 Oct 2013 11:08:08 +0200

Le 23 oct. 2013 à 03:35, Paul Eggert <address@hidden> a écrit :

> Akim Demaille wrote:
>> Bison is already generating code to define __attribute__.
>> That's the code that was in glr.c, and which is now used
>> in yacc.c and lalr1.cc too:
>> 
>> # b4_attribute_define
>> # -------------------
>> # Provide portability for __attribute__.
>> m4_define([b4_attribute_define],
>> [#ifndef __attribute__
>> /* This feature is available in gcc versions 2.5 and later.  */
>> # if (! defined __GNUC__ || __GNUC__ < 2 \
>>      || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
>> #  define __attribute__(Spec) /* empty */
>> # endif
>> #endif
> 
> Ah, that probably should be updated to match what's in
> gnulib/lib/stdio.in.h.  The "5" is a bit tricky
> (not that anybody uses compilers that old any more)
> and the gnulib version knows about __gnu_printf__
> versus __printf__.

Actually in the generated code we don't need format checking,
just __pure__, __noreturn__, and __unused__.

> 
>> I expect that you would recommend that we define YY_ATTRIBUTE,
>> YY_ATTRIBUTE_UNUSED and so forth instead?
> 
> That's for the generated code, as opposed to uniqstr.h
> which is for Bison itself, right?  Yes, I suppose Bison's
> YY* macros should track the latest and greatest from Gnulib.
> Perhaps that tracking could be automated?

Sounds tricky.  A preliminary step which would look useful
anyway would be to introduce an attribute module in gnulib
that would factor all the scattered definitions.

What do you think about these two patches?

commit dd5790cbef5d77daf0e41464a7704671f404e54a
Author: Akim Demaille <address@hidden>
Date:   Wed Oct 23 10:57:09 2013 +0200

    data: update the handling of compiler attributes
    
    * data/c.m4 (b4_attribute_define): Instead of defining __attribute__,
    define YY_ATTRIBUTE conditionally.
    (YY_ATTRIBUTE_PURE, YY_ATTRIBUTE_UNUSED, _Noreturn): New.
    Use them.
    * data/glr.c: Use them.

diff --git a/data/c.m4 b/data/c.m4
index b1b4394..6ec5842 100644
--- a/data/c.m4
+++ b/data/c.m4
@@ -205,13 +205,27 @@ m4_define([b4_table_value_equals],
 
 # b4_attribute_define
 # -------------------
-# Provide portability for __attribute__.
+# Provide portable compiler "attributes".
 m4_define([b4_attribute_define],
-[#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later.  */
-# if (! defined __GNUC__ || __GNUC__ < 2 \
-      || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
-#  define __attribute__(Spec) /* empty */
+[#ifndef YY_ATTRIBUTE
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+#  define YY_ATTRIBUTE(Spec) __attribute__((Spec))
+# else
+#  define YY_ATTRIBUTE(Spec) /* empty */
+# endif
+#endif
+
+#define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
+#define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
+
+#if !defined _Noreturn && __STDC_VERSION__ < 201112
+# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
+      || 0x5110 <= __SUNPRO_C)
+#  define _Noreturn YY_ATTRIBUTE ((__noreturn__))
+# elif 1200 <= _MSC_VER
+#  define _Noreturn __declspec (noreturn)
+# else
+#  define _Noreturn
 # endif
 #endif
 
@@ -783,7 +797,7 @@ m4_define([b4_yy_location_print_define],
 
 /* Print *YYLOCP on YYO.  Private, do not rely on its existence. */
 
-__attribute__((__unused__))
+YY_ATTRIBUTE_UNUSED
 ]b4_function_define([yy_location_print_],
     [static unsigned],
                [[FILE *yyo],                    [yyo]],
diff --git a/data/glr.c b/data/glr.c
index 8ef3553..25dda38 100644
--- a/data/glr.c
+++ b/data/glr.c
@@ -445,9 +445,9 @@ int yydebug;
 
 struct yyGLRStack;
 static void yypstack (struct yyGLRStack* yystackp, size_t yyk)
-  __attribute__ ((__unused__));
+  YY_ATTRIBUTE_UNUSED;
 static void yypdumpstack (struct yyGLRStack* yystackp)
-  __attribute__ ((__unused__));
+  YY_ATTRIBUTE_UNUSED;
 
 #else /* !]b4_api_PREFIX[DEBUG */
 
@@ -670,7 +670,7 @@ static void yyexpandGLRStack (yyGLRStack* yystackp);
 #endif
 
 static void yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
-  __attribute__ ((__noreturn__));
+  _Noreturn;
 static void
 yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
 {
@@ -679,8 +679,7 @@ yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* 
yymsg)
   YYLONGJMP (yystackp->yyexception_buffer, 1);
 }
 
-static void yyMemoryExhausted (yyGLRStack* yystackp)
-  __attribute__ ((__noreturn__));
+static void yyMemoryExhausted (yyGLRStack* yystackp) _Noreturn;
 static void
 yyMemoryExhausted (yyGLRStack* yystackp)
 {
@@ -702,7 +701,7 @@ yytokenName (yySymbol yytoken)
 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
  *  at YYVSP[YYLOW0].yystate.yypred.  Leaves YYVSP[YYLOW1].yystate.yypred
  *  containing the pointer to the next state in the chain.  */
-static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
+static void yyfillin (yyGLRStackItem *, int, int) YY_ATTRIBUTE_UNUSED;
 static void
 yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
 {
@@ -729,7 +728,7 @@ yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
  * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
  * For convenience, always return YYLOW1.  */
 static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
-     __attribute__ ((__unused__));
+     YY_ATTRIBUTE_UNUSED;
 static inline int
 yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
 {
@@ -751,8 +750,7 @@ yyuserAction (yyRuleNum yyn, size_t yyrhslen, 
yyGLRStackItem* yyvsp,
               yyGLRStack* yystackp,
               YYSTYPE* yyvalp]b4_locuser_formals[)
 {
-  yybool yynormal __attribute__ ((__unused__)) =
-    (yystackp->yysplitPoint == YY_NULL);
+  yybool yynormal YY_ATTRIBUTE_UNUSED = (yystackp->yysplitPoint == YY_NULL);
   int yylow;
 ]b4_parse_param_use([yyvalp], [yylocp])dnl
 [  YYUSE (yyrhslen);

commit 91d0daf6dffceaa8fd58ffdb0fff16bbfa471729
Author: Akim Demaille <address@hidden>
Date:   Wed Oct 23 10:57:51 2013 +0200

    c++: use __attribute__((__pure__)) to avoid warnings
    
    Building C++ parsers with -Wsuggest-attribute=const and
    -Wsuggest-attribute=noreturn triggers warning in generated code.
    
    * data/lalr1.cc: Call b4_attribute_define.
    (debug_stream, debug_level): Flag as pure.

diff --git a/data/lalr1.cc b/data/lalr1.cc
index a378463..5752008 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -183,14 +183,14 @@ b4_location_define])])[
 
 #if ]b4_api_PREFIX[DEBUG
     /// The current debugging stream.
-    std::ostream& debug_stream () const;
+    std::ostream& debug_stream () const YY_ATTRIBUTE_PURE;
     /// Set the current debugging stream.
     void set_debug_stream (std::ostream &);
 
     /// Type for debugging levels.
     typedef int debug_level_type;
     /// The current debugging level.
-    debug_level_type debug_level () const;
+    debug_level_type debug_level () const YY_ATTRIBUTE_PURE;
     /// Set the current debugging level.
     void set_debug_level (debug_level_type l);
 #endif
@@ -418,6 +418,8 @@ m4_if(b4_prefix, [yy], [],
 # endif
 #endif
 
+]b4_attribute_define[
+
 ]b4_locations_if([dnl
 [#define YYRHSLOC(Rhs, K) ((Rhs)[K].location)
 ]b4_yylloc_default_define])[




reply via email to

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