]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gengtype: Include system.h earlier in gengtype-lex.cc [PR121386]
authorJakub Jelinek <jakub@redhat.com>
Wed, 6 Aug 2025 09:27:00 +0000 (11:27 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 6 Aug 2025 09:27:00 +0000 (11:27 +0200)
OpenBSD headers apparently instead of just
 #define SIZE_MAX something
do
 #ifndef SIZE_MAX
 #define SIZE_MAX something
 #endif
This causes problem with gengtype-lex.cc, where the flex generated
code has
 #ifndef SIZE_MAX
 #define SIZE_MAX (~(size_t)0)
 #endif
and system.h is included only after that and since my changes for
host size_t *printf printing SIZE_MAX is used in preprocessor
expressions,
 #if SIZE_MAX <= UINT_MAX
etc.
In the preprocessor, identifiers are replaced with 0 and so
it is (~(0)0) <= 0xffffffffU
or so and thus invalid.

Now, normally we want to include system.h early, ideally immediately
after config.h or bconfig.h, but in gengtype-lex.cc case we have
 #ifdef HOST_GENERATOR_FILE
 #include "config.h"
 #define GENERATOR_FILE 1
 #else
 #include "bconfig.h"
 #endif

 // flex generated start of file, including
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <inttypes.h>
 #ifndef SIZE_MAX
 #define SIZE_MAX (~(size_t)0)
 #endif

 // start of gengtype-lex.l %{} section
 #ifdef HOST_GENERATOR_FILE
 #include "config.h"
 #define GENERATOR_FILE 1
 #else
 #include "bconfig.h"
 #endif
 #include "system.h"

 #define malloc xmalloc
 #define realloc xrealloc

 #include "gengtype.h"

As I'm not sure what flex we require for building gcc (%top{} which COBOL FE
*.l uses is only in flex from 2003-04-01), the patch keeps using the %top{}
done by hand in Makefile.in, but includes system.h in the top part, with
FLEX_SCANNER temporarily defined (I'm undefining it afterwards because
flex generated code defines it again and I don't want to guarantee it is
defined to the same value) so that malloc/realloc poisoning doesn't happen
and #define malloc xmalloc and realloc xrealloc are done in system.h.
Note, system.h already includes all the 5 headers flex generated code
includes.

2025-08-06  Jakub Jelinek  <jakub@redhat.com>

PR bootstrap/121386
* Makefile.in (gengtype-lex.cc): Append #define FLEX_SCANNER,
#include "system.h" and #undef FLEX_SCANNER to the prepended lines.
* gengtype-lex.l: Remove inclusion of config.h or bconfig.h, system.h
and definition of malloc/realloc from %{} section.

gcc/Makefile.in
gcc/gengtype-lex.l

index d7d5cbe7277039435ca8d33574f58c3c407df25e..3406517934739af6786151e6632b7c55a555735f 100644 (file)
@@ -3402,6 +3402,9 @@ gengtype-lex.cc : gengtype-lex.l
          echo '#else'                     >> $@.tmp; \
          echo '#include "bconfig.h"'      >> $@.tmp; \
          echo '#endif'                    >> $@.tmp; \
+         echo '#define FLEX_SCANNER'      >> $@.tmp; \
+         echo '#include "system.h"'       >> $@.tmp; \
+         echo '#undef FLEX_SCANNER'       >> $@.tmp; \
          cat $@ >> $@.tmp; \
          mv $@.tmp $@; \
        }
index e36ca5b4e9d32e0c9ef9e8868528f2cb95acec49..37e4eb0f6571bb5c097c9764225a698ddaf46aae 100644 (file)
@@ -21,17 +21,6 @@ along with GCC; see the file COPYING3.  If not see
 %option noinput
 
 %{
-#ifdef HOST_GENERATOR_FILE
-#include "config.h"
-#define GENERATOR_FILE 1
-#else
-#include "bconfig.h"
-#endif
-#include "system.h"
-
-#define malloc xmalloc
-#define realloc xrealloc
-
 #include "gengtype.h"
 
 #define YY_DECL int yylex (const char **yylval)