Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH] [gdb/build] Handle yyunput macro
Date: Wed, 18 Nov 2026 10:59:31 +0100	[thread overview]
Message-ID: <20261118095931.3217165-1-tdevries@suse.de> (raw)

[ The approach taken in this patch is conservative, intended to be suitable
for backporting.  A recently submitted patch [1] proposes to remove
gdb/ada-lex.l, which also solves PR build/35015. ]

In gdb/ada-lex.l, we have the following workaround:
...
 /* Dummy definition to suppress warnings about unused static definitions. */
 typedef void (*dummy_function) ();
 dummy_function ada_flex_use[] =
 {
   (dummy_function) yyunput
 };
...

This stopped working for a range of flex versions (2.6.5 - 2.6.11) which
define yyunput as a macro:
...
 #define yyunput(c) yyunput_r(...)
...

[ Version 2.6.12 restores the previous situation using commit 160a160
("fix(skel): restore the flex 2.6.4 yyunput function"). ]

I ran into this on cygwin using 2.6.11.

We can fix this using:
...
 #ifdef yyunput
   (dummy_function) yyunput_r
 #else
   (dummy_function) yyunput
 #endif
...
but that seems fragile.

We could use "%option nounput".  It was added in 2.5.1, but with some bug that
was fixed in 2.5.2, and on current trunk, we require >= 2.5.19 due to using
--header-file.  But on release branches we require >= 2.5.1, and using
"%option nounput" would break support for 2.5.1.

Instead, use YY_NO_YYUNPUT (available starting 2.6.5) to suppress the
generation of yyunput, while falling back to ada_flex_use for < 2.6.5.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=35015

[1] https://sourceware.org/pipermail/gdb-patches/2026-November/231953.html
---
 gdb/ada-lex.l | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index 857176c4d83..2085c0b618e 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -84,6 +84,26 @@ DIAGNOSTIC_IGNORE_REGISTER
       pstate->lexptr += 1;						\
     }
 
+/* Starting v2.5.1, flex supports:
+   - YY_FLEX_MAJOR_VERSION and YY_FLEX_MINOR_VERSION
+   - YY_NO_UNPUT (though this was broken from v2.5.31 - v2.5.34)
+   Starting v2.5.22, flex supports:
+   - YY_FLEX_SUBMINOR_VERSION
+   Starting v2.6.5, flex supports:
+   - YY_NO_YYUNPUT
+
+   The ada_flex_use workaround doesn't work for v2.6.5 - v2.6.11, and we can
+   use either YY_NO_UNPUT or YY_NO_YYUNPUT to fix this.  Use YY_NO_YYUNPUT
+   because the supported check is easier.  So, check for >= v2.6.5.  */
+#if defined (YY_FLEX_MAJOR_VERSION) && defined (YY_FLEX_MINOR_VERSION)	\
+  && defined (YY_FLEX_SUBMINOR_VERSION)
+#if (YY_FLEX_MAJOR_VERSION > 2)					\
+  || (YY_FLEX_MAJOR_VERSION == 2 && YY_FLEX_MINOR_VERSION > 6)	\
+  || (YY_FLEX_MAJOR_VERSION == 2 && YY_FLEX_MINOR_VERSION == 6	\
+      && YY_FLEX_SUBMINOR_VERSION >= 5)
+#define YY_NO_YYUNPUT
+#endif
+#endif
 %}
 
 %option case-insensitive interactive nodefault noyywrap
@@ -336,11 +356,13 @@ lexer_init (FILE *inp)
 
 } /* namespace ada_exp_parser */
 
+#ifndef YY_NO_YYUNPUT
 /* Dummy definition to suppress warnings about unused static definitions. */
 typedef void (*dummy_function) ();
 dummy_function ada_flex_use[] =
 {
   (dummy_function) yyunput
 };
+#endif
 
 DIAGNOSTIC_POP

base-commit: 23953c373348a015b6243374216d460bec958672
-- 
2.51.0


             reply	other threads:[~2026-11-18 10:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  9:59 Tom de Vries [this message]
2026-11-20 10:28 ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118095931.3217165-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox