Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] [gdb/build] Handle yyunput macro
@ 2026-11-18  9:59 Tom de Vries
  2026-11-20 10:28 ` Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2026-11-18  9:59 UTC (permalink / raw)
  To: gdb-patches

[ 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] [gdb/build] Handle yyunput macro
  2026-11-18  9:59 [PATCH] [gdb/build] Handle yyunput macro Tom de Vries
@ 2026-11-20 10:28 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2026-11-20 10:28 UTC (permalink / raw)
  To: gdb-patches

On 11/18/26 10:59 AM, Tom de Vries wrote:
> 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.
> 

Following up on a comment from Simon in the PR, I've submitted a simpler 
version ( 
https://sourceware.org/pipermail/gdb-patches/2026-November/232056.html ) 
that drops ada_flex_use and suppresses the resulting Wunused-function 
warning.

Thanks,
- Tom

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-20 10:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18  9:59 [PATCH] [gdb/build] Handle yyunput macro Tom de Vries
2026-11-20 10:28 ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox