From cc10f9ab24312ac78313d2cf249c691c9995c948 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 9 Jun 2019 08:43:43 +0200 Subject: [PATCH 01/24] CI: factor * .travis.yml (Clang 7 libc++ and ASAN part 2): Reuse bits from "Clang 7 libc++ and ASAN part 1". --- .travis.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 16a69c60..f4c4d773 100644 --- a/.travis.yml +++ b/.travis.yml @@ -88,7 +88,7 @@ jobs: stage: test os: linux dist: xenial - addons: + addons: &clang7 apt: sources: - llvm-toolchain-xenial-7 @@ -105,15 +105,7 @@ jobs: stage: test os: linux dist: xenial - addons: - apt: - sources: - - llvm-toolchain-xenial-7 - - ubuntu-toolchain-r-test - packages: - - clang-7 - - libc++-7-dev - - libc++abi-7-dev + addons: *clang7 env: # Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379 - MATRIX_EVAL="PART=2 CC='clang-7 -fsanitize=address' CXX='clang++-7 -fsanitize=address -stdlib=libc++'" From feeacc2d57de3b2efd0ef69dd1af947600c53504 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 14 Jun 2019 18:30:25 +0200 Subject: [PATCH 02/24] CI: avoid useless git costs Travis answered favorably to my suggestion to provide a means to disable git clone on some jobs (issue 7542). See https://docs.travis-ci.com/user/customizing-the-build/#disabling-git-clone. * .travis.yml: Disable git globally, enable it for i. the compile job, and ii. the test job on ICC which needs the install-icc.sh script. --- .travis.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index f4c4d773..a51d2143 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,20 +20,18 @@ stages: - compile - test +# The 'test' jobs do not need the repo at all, only the 'compile' +# does. Let's save time, bandwith, energy, and polar bears. git: - # Manually handle submodules so that we don't have to uselessly waste 150s - # to download gnulib in the 'test' jobs. - submodules: false - - # For the same reasons, we would like to not clone the repo either, but it - # does not seem to be possible. - depth: 1 + clone: false # matrix.include and jobs.include are aliases # (https://docs.travis-ci.com/user/conditional-builds-stages-jobs/). jobs: include: - stage: "compile" + git: + clone: true dist: xenial script: - sudo apt-get install -qq autoconf automake autopoint flex gettext graphviz help2man m4 texinfo @@ -112,6 +110,11 @@ jobs: - name: "ICC" stage: test + # We need the build-aux/install-icc.sh script. + git: + clone: true + submodules: false + depth: 1 os: linux dist: xenial env: From de7c66ab41ec24a318c1ae46c3fa1cb05b4c78e0 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 22 Jun 2019 08:28:29 +0200 Subject: [PATCH 03/24] CI: propagate sftp failures * .travis.yml (stage: "compile"): here. --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a51d2143..923598de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,7 +58,9 @@ jobs: # conflicts). Besides, one day we would like not to depend on the repository at all in the # 'test' jobs. So also expose this tarball on a name that only depends on the Travis build # number. - - sftp bison@sftp.lrde.epita.fr <<< "put $dist"$'\n'"ln -s $dist bison-$TRAVIS_BUILD_NUMBER.tar.xz" + # + # Without -b -, exit status is always 0. + - sftp -b - bison@sftp.lrde.epita.fr <<< "put $dist"$'\n'"ln -s $dist bison-$TRAVIS_BUILD_NUMBER.tar.xz" ## ------- ## ## First. ## From 2663035ea54d2ed540ed7c2b3728d9e73abe4dc7 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 2 Sep 2019 23:22:01 +0200 Subject: [PATCH 04/24] CI: fail fast --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 923598de..2ee30dc4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -410,6 +410,9 @@ script: # with `Picked up _JAVA_OPTIONS: -Xmx2048m -Xms512m`, which makes # the test suite fail. - unset _JAVA_OPTIONS + + # Fail fast from now on. + - set -e - sftp bison@sftp.lrde.epita.fr:bison-$TRAVIS_BUILD_NUMBER.tar.xz - tar xf bison-$TRAVIS_BUILD_NUMBER.tar.xz - dir=$(tar tf bison-$TRAVIS_BUILD_NUMBER.tar.xz | sed 1q) @@ -423,4 +426,4 @@ script: - if test ${PART-2} = 2; then make maintainer-check-g++ VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }; fi after_script: - - if [[ $CC == "icc" ]]; then uninstall_intel_software; fi + - if [[ $CC == "icc" ]]; then uninstall_intel_software || true; fi From 12c412f6bbd091f71fb0a925d8c265e6ee3aa283 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 2 Sep 2019 19:09:58 +0200 Subject: [PATCH 05/24] CI: more compilers * .travis.yml: Bionic is now available, with GCC8. GCC7 sanitizers work, but they are too longer: cover only part 1. Redefine part 1 and part 2 so that part 1 is really the core of the tests: not playing with POSIX and C++ compiler for C code. --- .travis.yml | 91 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2ee30dc4..7d22533e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,46 +69,44 @@ jobs: # Start with three completely different environments, to get # errors asap. - - name: "GCC 7 -O3" + - name: "GCC 8 -O3" stage: test os: linux - dist: xenial + dist: bionic addons: apt: - sources: - - ubuntu-toolchain-r-test packages: - - g++-7 + - g++-8 env: - - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'" + - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8 && CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'" # ASAN is time consuming, and we timeout the 50min granted by # Travis if we run all the tests in one go. Run in two parts. - - name: "Clang 7 libc++ and ASAN part 1" + - name: "Clang 8 libc++ and ASAN part 1" stage: test os: linux - dist: xenial - addons: &clang7 + dist: bionic + addons: &clang8 apt: sources: - - llvm-toolchain-xenial-7 + - llvm-toolchain-bionic-8 - ubuntu-toolchain-r-test packages: - - clang-7 - - libc++-7-dev - - libc++abi-7-dev + - clang-8 + - libc++-8-dev + - libc++abi-8-dev env: # Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379 - - MATRIX_EVAL="PART=1 CC='clang-7 -fsanitize=address' CXX='clang++-7 -fsanitize=address -stdlib=libc++'" + - MATRIX_EVAL="PART=1 CC='clang-8 -fsanitize=address' CXX='clang++-8 -fsanitize=address -stdlib=libc++'" - - name: "Clang 7 libc++ and ASAN part 2" + - name: "Clang 8 libc++ and ASAN part 2" stage: test os: linux - dist: xenial - addons: *clang7 + dist: bionic + addons: *clang8 env: # Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379 - - MATRIX_EVAL="PART=2 CC='clang-7 -fsanitize=address' CXX='clang++-7 -fsanitize=address -stdlib=libc++'" + - MATRIX_EVAL="PART=2 CC='clang-8 -fsanitize=address' CXX='clang++-8 -fsanitize=address -stdlib=libc++'" - name: "ICC" stage: test @@ -131,23 +129,27 @@ jobs: ## GCC. ## ## ----- ## - #- name: "GCC 8 with sanitizers" - # os: linux - # dist: xenial - # addons: - # apt: - # sources: - # - ubuntu-toolchain-r-test - # packages: - # - g++-8 - # env: - # # Can't use UBSAN: I get: - # # configure:4951: gcc-8 -fsanitize=undefined,address -fno-omit-frame-pointer conftest.c - # # /usr/bin/ld: unrecognized option '--push-state' (on trusty) - # # /usr/bin/ld: unrecognized option '--push-state--no-as-needed' (on xenial) - # # - # # https://stackoverflow.com/questions/50024731/ suggests using the gold linker. - # - MATRIX_EVAL="CC='gcc-8 -fsanitize=undefined,address -fno-omit-frame-pointer' CXX='g++-8 -fsanitize=undefined,address -fno-omit-frame-pointer'" + - name: "GCC 7 with sanitizers" + os: linux + dist: bionic + addons: + apt: + packages: + - g++-7 + env: + - MATRIX_EVAL="CC='gcc-7 -fsanitize=undefined,address -fno-omit-frame-pointer' CXX='g++-7 -fsanitize=undefined,address -fno-omit-frame-pointer'" + - PART=1 + + - name: "GCC 7" + stage: test + os: linux + dist: bionic + addons: + apt: + packages: + - g++-7 + env: + - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" - name: "GCC 6" stage: test @@ -231,6 +233,23 @@ jobs: ## Clang. ## ## ------- ## + - name: "Clang 7 -O3 and libc++" + stage: test + os: linux + dist: bionic + addons: + apt: + sources: + - llvm-toolchain-bionic-7 + - ubuntu-toolchain-r-test + packages: + - clang-7 + - libc++-7-dev + - libc++abi-7-dev + env: + - MATRIX_EVAL="CC=clang-7 && CXX='clang++-7 -stdlib=libc++'" + - CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3' + - name: "Clang 6 -O3 and libc++" stage: test os: linux @@ -422,7 +441,7 @@ script: - ../configure --enable-gcc-warnings CC="$CC" CXX="$CXX" $CONFIGUREFLAGS || { cat config.log && false; } - make -j2 $MAKE_ARGS - if test ${PART-1} = 1; then make check VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat test-suite.log && cat tests/testsuite.log && false; }; fi - - if test ${PART-1} = 1; then make maintainer-check-posix VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }; fi + - if test ${PART-2} = 2; then make maintainer-check-posix VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }; fi - if test ${PART-2} = 2; then make maintainer-check-g++ VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }; fi after_script: From ed796869bb0f2d0531e0de367737e18ccaf43016 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 1 Sep 2019 17:56:38 +0200 Subject: [PATCH 06/24] gnulib: update This update brings file from Gettext 0.20, which is not available on the CI yet. .travis.yml: Adjust. Use Bionic now that it's available. --- .travis.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7d22533e..0e843e85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ jobs: - stage: "compile" git: clone: true - dist: xenial + dist: bionic script: - sudo apt-get install -qq autoconf automake autopoint flex gettext graphviz help2man m4 texinfo - autoconf --version @@ -49,15 +49,20 @@ jobs: - git submodule update --init --recursive - ./bootstrap - - ./configure --enable-gcc-warnings CC="$CC" CXX="$CXX" $CONFIGUREFLAGS || { cat config.log && false; } + # gnulib-po/Makefile.in.in is about Gettext 0.20, which is not available in bionic. So it will break here. Override it. Don't use autopoint, which sends some other files in the past. + - cp po/Makefile.in.in gnulib-po + + - ./configure --enable-gcc-warnings || { cat config.log && false; } - make -j2 - make -j2 dist - dist=$(echo bison*.xz) + # Unfortunately we cannot deterministically know the name of the tarball without the full # git history (because git describe --abbrev=4 may use more than 4 characters if there are - # conflicts). Besides, one day we would like not to depend on the repository at all in the - # 'test' jobs. So also expose this tarball on a name that only depends on the Travis build - # number. + # conflicts). + # + # So for the sake of the 'test' jobs (that don't even have the repo at all), also expose this + # tarball on a name that only depends on the Travis build number. # # Without -b -, exit status is always 0. - sftp -b - bison@sftp.lrde.epita.fr <<< "put $dist"$'\n'"ln -s $dist bison-$TRAVIS_BUILD_NUMBER.tar.xz" From 1e452b1553d888ee42643ac591b2627d8de6649f Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 30 Jun 2019 19:19:43 +0200 Subject: [PATCH 07/24] c++: avoid duplicate definition of YYUSE Reported by Frank Heckenbach. https://lists.gnu.org/archive/html/bug-bison/2019-06/msg00009.html * data/skeletons/lalr1.cc (b4_shared_declarations): Remove the duplicate definition of YYUSE, the other one coming from b4_attribute_define. --- data/skeletons/lalr1.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc index ef5d76f5..d1c30403 100644 --- a/data/skeletons/lalr1.cc +++ b/data/skeletons/lalr1.cc @@ -459,9 +459,6 @@ m4_if(b4_prefix, [yy], [], [#define YYRHSLOC(Rhs, K) ((Rhs)[K].location) ]b4_yylloc_default_define])[ -// Suppress unused-variable warnings by "using" E. -#define YYUSE(E) ((void) (E)) - // Enable debugging if requested. #if ]b4_api_PREFIX[DEBUG From 47262c36bb13a2d0d21a3a78ce83c8f34deea008 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 9 Aug 2019 04:36:55 -0500 Subject: [PATCH 08/24] git: ignore files generated in gnulib-po Because of them, the CI generates "-dirty" tarballs. --- gnulib-po/.gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gnulib-po/.gitignore b/gnulib-po/.gitignore index 3cbbc011..f2acc705 100644 --- a/gnulib-po/.gitignore +++ b/gnulib-po/.gitignore @@ -1,9 +1,12 @@ /*.gmo /*.po /LINGUAS +/Makefile +/Makefile.in /Makefile.in.in /Makevars /Makevars.template +/POTFILES /POTFILES.in /Rules-quot /bison-gnulib.pot From e63811dd86c340cd1758509b422e9c4978129804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20V=C3=A1rady?= Date: Fri, 9 Aug 2019 14:24:14 +0200 Subject: [PATCH 09/24] diagnostics: fix invalid error message indentation https://lists.gnu.org/archive/html/bison-patches/2019-08/msg00007.html When Bison is started with a flag that suppresses warning messages, the error_message() function can produce a few gigabytes of indentation because of a dangling pointer. * src/complain.c (error_message): Don't reset indent_ptr here, but... (complain_indent): here. * tests/diagnostics.at (Indentation with message suppression): Check this case. --- NEWS | 4 ++++ THANKS | 1 + src/complain.c | 2 +- tests/diagnostics.at | 30 ++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index a7a37f1c..52c85980 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ GNU Bison NEWS * Noteworthy changes in release ?.? (????-??-??) [?] +** Bug fixes + + In some cases, when warnings are disabled, bison could emit tons of white + spaces as diagnostics. * Noteworthy changes in release 3.4.1 (2019-05-22) [stable] diff --git a/THANKS b/THANKS index 14a26d76..e40fc001 100644 --- a/THANKS +++ b/THANKS @@ -95,6 +95,7 @@ Keith Browne kbrowne@legato.com Ken Moffat zarniwhoop@ntlworld.com Kiyoshi Kanazawa yoi_no_myoujou@yahoo.co.jp Laurent Mascherpa laurent.mascherpa@epita.fr +László Várady laszlo.varady93@gmail.com Lie Yan lie.yan@kaust.edu.sa Magnus Fromreide magfr@lysator.liu.se Marc Autret autret_m@epita.fr diff --git a/src/complain.c b/src/complain.c index 19c03cc3..3cec0ca0 100644 --- a/src/complain.c +++ b/src/complain.c @@ -416,7 +416,6 @@ error_message (const location *loc, warnings flags, severity sever, *indent_ptr = pos; else if (*indent_ptr > pos) fprintf (stderr, "%*s", *indent_ptr - pos, ""); - indent_ptr = NULL; } const char* style = severity_style (sever); @@ -487,6 +486,7 @@ complain_indent (location const *loc, warnings flags, unsigned *indent, va_start (args, message); complains (loc, flags, message, args); va_end (args); + indent_ptr = NULL; } void diff --git a/tests/diagnostics.at b/tests/diagnostics.at index fb24fbcf..3f9e19fa 100644 --- a/tests/diagnostics.at +++ b/tests/diagnostics.at @@ -242,3 +242,33 @@ input.y: warning: fix-its can be applied. Rerun with option m4_popdef([AT_TEST]) + + + + +## -------------------------------------- ## +## Indentation with message suppression. ## +## -------------------------------------- ## + +AT_SETUP([[Indentation with message suppression]]) + +# https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00002.html + +AT_DATA([[input.y]], +[[%define api.pure +%pure-parser +%error-verbose +%% +exp : '0' +]]) + +AT_BISON_CHECK([[-fcaret -Wno-other input.y]], [0], [], +[[input.y:2.1-12: warning: deprecated directive, use '%define api.pure' [-Wdeprecated] + 2 | %pure-parser + | ^~~~~~~~~~~~ +input.y:3.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated] + 3 | %error-verbose + | ^~~~~~~~~~~~~~ +]]) + +AT_CLEANUP From 53526f31dfe04ad8b74af2c9dc0941e1dc88e966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20V=C3=A1rady?= Date: Fri, 9 Aug 2019 14:24:15 +0200 Subject: [PATCH 10/24] diagnostics: avoid global variables * src/complain.c (indent_ptr): Remove. (error_message, complains): Take indent as an argument. Adjust callers. --- src/complain.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/complain.c b/src/complain.c index 3cec0ca0..8044064e 100644 --- a/src/complain.c +++ b/src/complain.c @@ -63,8 +63,6 @@ typedef enum /** For each warning type, its severity. */ static severity warnings_flag[warnings_size]; -static unsigned *indent_ptr = NULL; - styled_ostream_t errstream = NULL; void @@ -386,6 +384,7 @@ warnings_print_categories (warnings warn_flags, FILE *out) * * \param loc the location, defaulting to the current file, * or the program name. + * \param indent optional indentation for the error message. * \param flags the category for this message. * \param sever to decide the prefix to put before the message * (e.g., "warning"). @@ -397,8 +396,8 @@ warnings_print_categories (warnings warn_flags, FILE *out) */ static void -error_message (const location *loc, warnings flags, severity sever, - const char *message, va_list args) +error_message (const location *loc, unsigned *indent, warnings flags, + severity sever, const char *message, va_list args) { unsigned pos = 0; @@ -408,14 +407,14 @@ error_message (const location *loc, warnings flags, severity sever, pos += fprintf (stderr, "%s", current_file ? current_file : program_name); pos += fprintf (stderr, ": "); - if (indent_ptr) + if (indent) { - if (*indent_ptr) + if (*indent) sever = severity_disabled; - if (!*indent_ptr) - *indent_ptr = pos; - else if (*indent_ptr > pos) - fprintf (stderr, "%*s", *indent_ptr - pos, ""); + if (!*indent) + *indent = pos; + else if (*indent > pos) + fprintf (stderr, "%*s", *indent - pos, ""); } const char* style = severity_style (sever); @@ -450,8 +449,8 @@ error_message (const location *loc, warnings flags, severity sever, /** Raise a complaint (fatal error, error or just warning). */ static void -complains (const location *loc, warnings flags, const char *message, - va_list args) +complains (const location *loc, unsigned *indent, warnings flags, + const char *message, va_list args) { severity s = warning_severity (flags); if ((flags & complaint) && complaint_status < status_complaint) @@ -461,7 +460,7 @@ complains (const location *loc, warnings flags, const char *message, { if (severity_error <= s && ! complaint_status) complaint_status = status_warning_as_error; - error_message (loc, flags, s, message, args); + error_message (loc, indent, flags, s, message, args); } if (flags & fatal) @@ -473,7 +472,7 @@ complain (location const *loc, warnings flags, const char *message, ...) { va_list args; va_start (args, message); - complains (loc, flags, message, args); + complains (loc, NULL, flags, message, args); va_end (args); } @@ -482,11 +481,9 @@ complain_indent (location const *loc, warnings flags, unsigned *indent, const char *message, ...) { va_list args; - indent_ptr = indent; va_start (args, message); - complains (loc, flags, message, args); + complains (loc, indent, flags, message, args); va_end (args); - indent_ptr = NULL; } void From f788ba2ab6ce627a9e4d7ca66a00a97a61de5469 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 31 Aug 2019 18:07:26 -0500 Subject: [PATCH 11/24] check for memory exhaustion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hash_initialize returns NULL when out of memory. Check for it, and die cleanly instead of crashing. Reported by 江 祖铭 (Zu-Ming Jiang). https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00015.html * src/muscle-tab.c, src/state.c, src/symtab.c, src/uniqstr.c: Check the value returned by hash_initialize. --- THANKS | 1 + src/muscle-tab.c | 2 ++ src/state.c | 2 ++ src/symtab.c | 4 ++++ src/uniqstr.c | 2 ++ 5 files changed, 11 insertions(+) diff --git a/THANKS b/THANKS index e40fc001..a0e3af66 100644 --- a/THANKS +++ b/THANKS @@ -199,6 +199,7 @@ Wwp subscript@free.fr xolodho xolodho@gmail.com Zack Weinberg zack@codesourcery.com 長田偉伸 cbh34680@iret.co.jp +江 祖铭 jjzuming@outlook.com Many people are not named here because we lost track of them. We thank them! Please, help us keeping this list up to date. diff --git a/src/muscle-tab.c b/src/muscle-tab.c index fbb80fc2..d3e358e6 100644 --- a/src/muscle-tab.c +++ b/src/muscle-tab.c @@ -128,6 +128,8 @@ muscle_init (void) muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle, hash_compare_muscles, muscle_entry_free); + if (!muscle_table) + xalloc_die (); /* Version and input file. */ MUSCLE_INSERT_STRING ("version", VERSION); diff --git a/src/state.c b/src/state.c index 87fbb1c6..64bb256c 100644 --- a/src/state.c +++ b/src/state.c @@ -364,6 +364,8 @@ state_hash_new (void) state_hasher, state_comparator, NULL); + if (!state_table) + xalloc_die (); } diff --git a/src/symtab.c b/src/symtab.c index 83e8256b..60733e72 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -778,11 +778,15 @@ symbols_new (void) hash_symbol_hasher, hash_symbol_comparator, symbol_free); + if (!symbol_table) + xalloc_die (); semantic_type_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_semantic_type_hasher, hash_semantic_type_comparator, free); + if (!semantic_type_table) + xalloc_die (); } diff --git a/src/uniqstr.c b/src/uniqstr.c index f654d55e..d5c66846 100644 --- a/src/uniqstr.c +++ b/src/uniqstr.c @@ -162,6 +162,8 @@ uniqstrs_new (void) hash_uniqstr, hash_compare_uniqstr, free); + if (!uniqstrs_table) + xalloc_die (); } From 628012d830db1e4a1c68ea6ea1e45af489260728 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 5 Sep 2019 11:38:02 +0200 Subject: [PATCH 12/24] gnulib: update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contains a fix for https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00016.html. See https://lists.gnu.org/archive/html/bug-gnulib/2019-09/msg00005.html. Reported by 江 祖铭 (Zu-Ming Jiang). --- gnulib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnulib b/gnulib index 9bfa2644..03add7eb 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit 9bfa2644feac79b87cc0d78b11ec9c210b78bba5 +Subproject commit 03add7eb9d06ab509034ba01c904a4cb36f5706b From 29c75ef27f5c06508d518ec3376f58aef6c65072 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 6 Sep 2019 07:37:26 +0200 Subject: [PATCH 13/24] glr.c: initialize vector of bools The CI, with CC='gcc-7 -fsanitize=undefined,address -fno-omit-frame-pointer', reports: calc.cc:1652:50: runtime error: load of value 190, which is not a valid value for type 'bool' ../../tests/calc.at:867: cat stderr --- expout 2019-09-05 20:30:37.887257545 +0000 +++ /home/travis/build/bison-3.4.1.72-79a1-dirty/_build/tests/testsuite.dir/at-groups/438/stdout 2019-09-05 20:30:37.887257545 +0000 @@ -1 +1,2 @@ syntax error +calc.cc:1652:50: runtime error: load of value 190, which is not a valid value for type 'bool' 438. calc.at:867: 438. Calculator glr.cc (calc.at:867): FAILED (calc.at:867) The problem is that yylookaheadNeeds is not initialized in yyinitStateSet, and when it is copied, the value is not 0 or 1. * data/skeletons/glr.c (yylookaheadNeeds): Initialize yylookaheadNeeds. --- data/skeletons/glr.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c index 5d4121b8..c9c6ce7d 100644 --- a/data/skeletons/glr.c +++ b/data/skeletons/glr.c @@ -1094,17 +1094,20 @@ yyinitStateSet (yyGLRStateSet* yyset) { yyset->yysize = 1; yyset->yycapacity = 16; - yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]); + yyset->yystates + = (yyGLRState**) YYMALLOC (yyset->yycapacity * sizeof yyset->yystates[0]); if (! yyset->yystates) return yyfalse; yyset->yystates[0] = YY_NULLPTR; - yyset->yylookaheadNeeds = - (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]); + yyset->yylookaheadNeeds + = (yybool*) YYMALLOC (yyset->yycapacity * sizeof yyset->yylookaheadNeeds[0]); if (! yyset->yylookaheadNeeds) { YYFREE (yyset->yystates); return yyfalse; } + memset (yyset->yylookaheadNeeds, + 0, yyset->yycapacity * sizeof yyset->yylookaheadNeeds[0]); return yytrue; } From d3a86f7b20bd3a6756f2382fad12beafba0443e7 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 6 Sep 2019 07:21:59 +0200 Subject: [PATCH 14/24] yacc.c: beware of GCC's -Wmaybe-uninitialized Test 400 (calc.at:773: testing Calculator api.push-pull=both api.pure=full parse.error=verbose %debug %locations %defines api.prefix={calc} %verbose %yacc) fails on the CI with GCC 8 on Bionic: 400. calc.at:773: testing Calculator api.push-pull=both api.pure=full parse.error=verbose %debug %locations %defines api.prefix={calc} %verbose %yacc ... ../../tests/calc.at:773: bison --color=no -fno-caret -Wno-deprecated -o calc.c calc.y ../../tests/calc.at:773: $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c calc-lex.c calc-main.c $LIBS stderr: calc.y: In function 'int calcpush_parse(calcpstate*, int, const CALCSTYPE*, CALCLTYPE*)': calc.y:26:20: error: 'yylval.CALCSTYPE::ival' may be used uninitialized in this function [-Werror=maybe-uninitialized] %printer { fprintf (yyo, "%d", $$); } ; ^ calc.c:1272:9: note: 'yylval.CALCSTYPE::ival' was declared here YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); ^~~~~~ cc1plus: all warnings being treated as errors stdout: ../../tests/calc.at:773: exit code was 1, expected 0 400. calc.at:773: 400. Calculator api.push-pull=both api.pure=full parse.error=verbose %debug %locations %defines api.prefix={calc} %verbose %yacc (calc.at:773): FAILED (calc.at:773) * data/skeletons/c.m4 (yy_symbol_value_print): Disable the warning locally. --- data/skeletons/c.m4 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4 index fcf58a84..27aa2939 100644 --- a/data/skeletons/c.m4 +++ b/data/skeletons/c.m4 @@ -545,7 +545,9 @@ m4_if(b4_skeleton, ["yacc.c"], # endif ]])dnl b4_percent_code_get([[pre-printer]])dnl + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN b4_symbol_actions([printer]) + YY_IGNORE_MAYBE_UNINITIALIZED_END b4_percent_code_get([[post-printer]])dnl [} From 375eb714892c573e72d760d528c3e66a35689b46 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 6 Sep 2019 17:47:16 +0200 Subject: [PATCH 15/24] tests: check token redeclaration * src/symtab.c (symbol_class_set): Report previous definitions when redeclared. * tests/input.at (Symbol redeclared): New. --- src/symtab.c | 8 +++++++- tests/diagnostics.at | 15 +++++++++++++++ tests/input.at | 32 ++++++++++++++++++++++++++++++++ tests/regression.at | 9 ++++----- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/symtab.c b/src/symtab.c index 60733e72..684fdf3d 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -462,7 +462,13 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring) if (declaring) { if (s->status == declared) - complain (&loc, Wother, _("symbol %s redeclared"), sym->tag); + { + unsigned i = 0; + complain (&loc, Wother, _("symbol %s redeclared"), sym->tag); + i += SUB_INDENT; + complain_indent (&sym->location, Wother, &i, + _("previous declaration")); + } else s->status = declared; } diff --git a/tests/diagnostics.at b/tests/diagnostics.at index 3f9e19fa..15815db3 100644 --- a/tests/diagnostics.at +++ b/tests/diagnostics.at @@ -67,18 +67,33 @@ exp: %empty; [[input.y:9.12-14: warning: symbol FOO redeclared [-Wother] 9 | %token FOO FOO FOO | ^~~ +input.y:9.8-10: previous declaration + 9 | %token FOO FOO FOO + | ^~~ input.y:9.16-18: warning: symbol FOO redeclared [-Wother] 9 | %token FOO FOO FOO | ^~~ +input.y:9.8-10: previous declaration + 9 | %token FOO FOO FOO + | ^~~ input.y:10.8-10: warning: symbol FOO redeclared [-Wother] 10 | %token FOO FOO FOO | ^~~ +input.y:9.8-10: previous declaration + 9 | %token FOO FOO FOO + | ^~~ input.y:10.13-15: warning: symbol FOO redeclared [-Wother] 10 | %token FOO FOO FOO | ^~~ +input.y:9.8-10: previous declaration + 9 | %token FOO FOO FOO + | ^~~ input.y:10.18-20: warning: symbol FOO redeclared [-Wother] 10 | %token FOO FOO FOO | ^~~ +input.y:9.8-10: previous declaration + 9 | %token FOO FOO FOO + | ^~~ ]]) diff --git a/tests/input.at b/tests/input.at index cc5e41fb..16f5aca6 100644 --- a/tests/input.at +++ b/tests/input.at @@ -615,6 +615,38 @@ AT_CHECK_UNUSED_VALUES([1], [1]) AT_CLEANUP +## ------------------- ## +## Symbol redeclared. ## +## ------------------- ## + +AT_SETUP([Symbol redeclared]) + +AT_DATA([[input.y]], +[[%token FOO FOO +%token BAR 12 BAR 12 + +%% +exp: FOO BAR +]]) + +AT_BISON_CHECK([-fcaret input.y], [0], [], +[[input.y:1.12-14: warning: symbol FOO redeclared [-Wother] + 1 | %token FOO FOO + | ^~~ +input.y:1.8-10: previous declaration + 1 | %token FOO FOO + | ^~~ +input.y:2.15-17: warning: symbol BAR redeclared [-Wother] + 2 | %token BAR 12 BAR 12 + | ^~~ +input.y:2.8-10: previous declaration + 2 | %token BAR 12 BAR 12 + | ^~~ +]]) + +AT_CLEANUP + + ## --------------------------- ## ## Symbol class redefinition. ## ## --------------------------- ## diff --git a/tests/regression.at b/tests/regression.at index bf0b4754..0e403cbd 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -397,19 +397,18 @@ AT_BISON_OPTION_POPDEFS # unnecessarily escaped here even though it would need to be if encoded in a # C-string literal. Also notice that unnecessary escaping, such as "\?", from # the user specification is eliminated. -AT_BISON_CHECK([-o input.c input.y], [[0]], [[]], -[[input.y:22.8-14: warning: symbol SPECIAL redeclared [-Wother] -input.y:22.16-63: warning: symbol "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" used more than once as a literal string [-Wother] -]]) - AT_BISON_CHECK([-fcaret -o input.c input.y], [[0]], [[]], [[input.y:22.8-14: warning: symbol SPECIAL redeclared [-Wother] 22 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!" | ^~~~~~~ +input.y:21.8-14: previous declaration + 21 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!" + | ^~~~~~~ input.y:22.16-63: warning: symbol "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" used more than once as a literal string [-Wother] 22 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]]) + AT_COMPILE([input]) # Checking the error message here guarantees that yytname, which does contain From f8db8fe4d7cb9db4cfbc414fca6f6ff9d74f0db6 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 7 Sep 2019 16:32:20 +0200 Subject: [PATCH 16/24] fix: don't die when EOF token is defined twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With %token EOF 0 EOF 0 we get input.y:3.14-16: warning: symbol EOF redeclared [-Wother] 3 | %token EOF 0 EOF 0 | ^~~ input.y:3.8-10: previous declaration 3 | %token EOF 0 EOF 0 | ^~~ Assertion failed: (nsyms == ntokens + nvars), function check_and_convert_grammar, file /Users/akim/src/gnu/bison/src/reader.c, line 839. Reported by Marc Schönefeld. * src/symtab.c (symbol_user_token_number_set): Register only the first definition of the end of input token. * tests/input.at (Symbol redeclared): Check that case. --- THANKS | 1 + src/symtab.c | 2 +- tests/input.at | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/THANKS b/THANKS index a0e3af66..2df6763c 100644 --- a/THANKS +++ b/THANKS @@ -100,6 +100,7 @@ Lie Yan lie.yan@kaust.edu.sa Magnus Fromreide magfr@lysator.liu.se Marc Autret autret_m@epita.fr Marc Mendiola mmendiol@usc.edu +Marc Schönefeld marc.schoenefeld@gmx.org Mark Boyall wolfeinstein@gmail.com Martin Jacobs martin.jacobs@arcor.de Martin Mokrejs mmokrejs@natur.cuni.cz diff --git a/src/symtab.c b/src/symtab.c index 684fdf3d..7b0439ad 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -495,7 +495,7 @@ symbol_user_token_number_set (symbol *sym, int user_token_number, location loc) { *user_token_numberp = user_token_number; /* User defined $end token? */ - if (user_token_number == 0) + if (user_token_number == 0 && !endtoken) { endtoken = sym->content->symbol; /* It is always mapped to 0, so it was already counted in diff --git a/tests/input.at b/tests/input.at index 16f5aca6..df0f6939 100644 --- a/tests/input.at +++ b/tests/input.at @@ -624,7 +624,7 @@ AT_SETUP([Symbol redeclared]) AT_DATA([[input.y]], [[%token FOO FOO %token BAR 12 BAR 12 - +%token EOF 0 EOF 0 %% exp: FOO BAR ]]) @@ -642,6 +642,12 @@ input.y:2.15-17: warning: symbol BAR redeclared [-Wother] input.y:2.8-10: previous declaration 2 | %token BAR 12 BAR 12 | ^~~ +input.y:3.14-16: warning: symbol EOF redeclared [-Wother] + 3 | %token EOF 0 EOF 0 + | ^~~ +input.y:3.8-10: previous declaration + 3 | %token EOF 0 EOF 0 + | ^~~ ]]) AT_CLEANUP From 77dbdd0d594fb9cc5c45d43ed82560748eb71183 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 8 Sep 2019 09:17:48 +0200 Subject: [PATCH 17/24] news: update --- NEWS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS b/NEWS index 52c85980..5d67f0ba 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,13 @@ GNU Bison NEWS In some cases, when warnings are disabled, bison could emit tons of white spaces as diagnostics. + When running out of memory, bison could crash (found by fuzzing). + + When defining twice the EOF token, bison would crash. + + New warnings from recent compilers have been addressed in the generated + parsers (yacc.c, glr.c, glr.cc). + * Noteworthy changes in release 3.4.1 (2019-05-22) [stable] ** Bug fixes From 0b417c3479ca63a55cff5305a35e6eea3e7bc7a4 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 8 Sep 2019 12:02:30 +0200 Subject: [PATCH 18/24] tests: add noexcept to please GCC 9 bison/tests/c++.at:552: bison --color=no -fno-caret -o list.cc list.y bison/tests/c++.at:552: $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o list list.cc $LIBS stderr: gcc9/c++/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = string; _Args = {string}; _Tp = string]': gcc9/c++/bits/alloc_traits.h:482:2: required from 'static void std::allocator_traits >::construct(std::allocator_traits >::allocator_type&, _Up*, _Args&& ...) [with _Up = string; _Args = {string}; _Tp = string; std::allocator_traits >::allocator_type = std::allocator]' gcc9/c++/bits/stl_uninitialized.h:888:67: required from 'void std::__relocate_object_a(_Tp*, _Up*, _Allocator&) [with _Tp = string; _Up = string; _Allocator = std::allocator]' gcc9/c++/bits/stl_uninitialized.h:920:47: required from '_ForwardIterator std::__relocate_a_1(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = string*; _ForwardIterator = string*; _Allocator = std::allocator]' gcc9/c++/bits/stl_uninitialized.h:942:37: required from '_ForwardIterator std::__relocate_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = string*; _ForwardIterator = string*; _Allocator = std::allocator]' gcc9/c++/bits/stl_vector.h:430:35: required from 'static constexpr bool std::vector<_Tp, _Alloc>::_S_nothrow_relocate(std::true_type) [with _Tp = string; _Alloc = std::allocator; std::true_type = std::integral_constant]' gcc9/c++/bits/stl_vector.h:446:28: required from 'void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {const string&}; _Tp = string; _Alloc = std::allocator; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator >; typename std::_Vector_base<_Tp, _Alloc>::pointer = string*]' gcc9/c++/bits/stl_vector.h:1195:4: required from 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = string; _Alloc = std::allocator; std::vector<_Tp, _Alloc>::value_type = string]' list.y:126:110: required from here gcc9/c++/bits/vector.tcc:459:44: in 'constexpr' expansion of 'std::vector::_S_use_relocate()' list.y:41:7: error: but 'string::string(string&&)' does not throw; perhaps it should be declared 'noexcept' [-Werror=noexcept] 41 | string (string&& s) | ^~~~~~ * tests/c++.at (Variants): Add noexcept where appropriate. --- tests/c++.at | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/c++.at b/tests/c++.at index e2e73fc2..13902138 100644 --- a/tests/c++.at +++ b/tests/c++.at @@ -313,7 +313,7 @@ AT_DATA_GRAMMAR([list.y], } #if defined __cplusplus && 201103L <= __cplusplus - string (string&& s) + string (string&& s) noexcept : val_(std::move(s.val_)) { s.val_.clear(); From d80815ac23192b0b3a2ebc82e6a7e512968bacb1 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 8 Sep 2019 18:48:49 +0200 Subject: [PATCH 19/24] build: fix distcheck * configure.ac (gl_LIBOBJS): Adjust so that the generated files are indeed the expected ones. --- configure.ac | 11 +++++++++++ src/parse-gram.c | 6 ++++-- src/parse-gram.h | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 83e2c972..6f323691 100644 --- a/configure.ac +++ b/configure.ac @@ -297,4 +297,15 @@ AC_SUBST([GCC]) AC_CONFIG_FILES([Makefile po/Makefile.in doc/yacc.1]) + +# Fix LIBOBJS to give the Makefile the right file names. Otherwise +# compilation works, but with unexpected file names, so clean rules don't +# remove the actual files and distcheck fails. +AC_CONFIG_COMMANDS_PRE([ + case $am__api_version in + 1.14*|1.15*) gl_LIBOBJS=`echo "$gl_LIBOBJS" | sed -e 's, lib/, lib/lib_libbison_a-,g'`;; + *) gl_LIBOBJS=`echo "$gl_LIBOBJS" | sed -e 's, lib/, lib/libbison_a-,g'`;; + esac +]) + AC_OUTPUT diff --git a/src/parse-gram.c b/src/parse-gram.c index fd1dec3c..2d0be44d 100644 --- a/src/parse-gram.c +++ b/src/parse-gram.c @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 3.4. */ +/* A Bison parser, made by GNU Bison 3.4.1.26-d17af. */ /* Bison implementation for Yacc-like parsers in C @@ -48,7 +48,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "3.4" +#define YYBISON_VERSION "3.4.1.26-d17af" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -886,6 +886,7 @@ yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YY /* "%code pre-printer" blocks. */ tron (yyo); + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN switch (yytype) { case 3: /* "string" */ @@ -1069,6 +1070,7 @@ tron (yyo); default: break; } + YY_IGNORE_MAYBE_UNINITIALIZED_END /* "%code post-printer" blocks. */ troff (yyo); diff --git a/src/parse-gram.h b/src/parse-gram.h index 1009592f..68d2b693 100644 --- a/src/parse-gram.h +++ b/src/parse-gram.h @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 3.4. */ +/* A Bison parser, made by GNU Bison 3.4.1.26-d17af. */ /* Bison interface for Yacc-like parsers in C From 741a58a504d8ace397272365df5342ddf574757a Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 9 Sep 2019 19:40:31 +0200 Subject: [PATCH 20/24] gnulib: update Contains the creation of the xhash module. https://lists.gnu.org/archive/html/bug-gnulib/2019-09/msg00046.html * src/muscle-tab.c, src/state.c, src/symtab.c, src/uniqstr.c: Use hash_xinitialize. --- bootstrap.conf | 3 ++- gnulib | 2 +- lib/.gitignore | 1 + src/muscle-tab.c | 6 ++---- src/state.c | 12 +++++------- src/symtab.c | 24 ++++++++++-------------- src/uniqstr.c | 12 +++++------- 7 files changed, 26 insertions(+), 34 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 0d379797..44469581 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -25,7 +25,7 @@ gnulib_modules=' error extensions fdl fopen-safer getopt-gnu gettext-h git-version-gen gitlog-to-changelog - gpl-3.0 hash inttypes isnan javacomp-script + gpl-3.0 inttypes isnan javacomp-script javaexec-script ldexpl libtextstyle-optional @@ -48,6 +48,7 @@ gnulib_modules=' xalloc xalloc-die xconcat-filename + xhash xlist xmemdup0 xstrndup diff --git a/gnulib b/gnulib index 03add7eb..672663ac 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit 03add7eb9d06ab509034ba01c904a4cb36f5706b +Subproject commit 672663aca33a8fac097f114693f69f09896ea62d diff --git a/lib/.gitignore b/lib/.gitignore index 344caefd..39a21e68 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -321,3 +321,4 @@ /assure.h /fsync.c /textstyle.in.h +/xhash.c diff --git a/src/muscle-tab.c b/src/muscle-tab.c index d3e358e6..91a45737 100644 --- a/src/muscle-tab.c +++ b/src/muscle-tab.c @@ -126,10 +126,8 @@ muscle_init (void) /* Initialize the muscle obstack. */ obstack_init (&muscle_obstack); - muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle, - hash_compare_muscles, muscle_entry_free); - if (!muscle_table) - xalloc_die (); + muscle_table = hash_xinitialize (HT_INITIAL_CAPACITY, NULL, hash_muscle, + hash_compare_muscles, muscle_entry_free); /* Version and input file. */ MUSCLE_INSERT_STRING ("version", VERSION); diff --git a/src/state.c b/src/state.c index 64bb256c..418f3fab 100644 --- a/src/state.c +++ b/src/state.c @@ -359,13 +359,11 @@ state_hasher (void const *s, size_t tablesize) void state_hash_new (void) { - state_table = hash_initialize (HT_INITIAL_CAPACITY, - NULL, - state_hasher, - state_comparator, - NULL); - if (!state_table) - xalloc_die (); + state_table = hash_xinitialize (HT_INITIAL_CAPACITY, + NULL, + state_hasher, + state_comparator, + NULL); } diff --git a/src/symtab.c b/src/symtab.c index 7b0439ad..417b71e4 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -779,20 +779,16 @@ hash_semantic_type_hasher (void const *m, size_t tablesize) void symbols_new (void) { - symbol_table = hash_initialize (HT_INITIAL_CAPACITY, - NULL, - hash_symbol_hasher, - hash_symbol_comparator, - symbol_free); - if (!symbol_table) - xalloc_die (); - semantic_type_table = hash_initialize (HT_INITIAL_CAPACITY, - NULL, - hash_semantic_type_hasher, - hash_semantic_type_comparator, - free); - if (!semantic_type_table) - xalloc_die (); + symbol_table = hash_xinitialize (HT_INITIAL_CAPACITY, + NULL, + hash_symbol_hasher, + hash_symbol_comparator, + symbol_free); + semantic_type_table = hash_xinitialize (HT_INITIAL_CAPACITY, + NULL, + hash_semantic_type_hasher, + hash_semantic_type_comparator, + free); } diff --git a/src/uniqstr.c b/src/uniqstr.c index d5c66846..3833b841 100644 --- a/src/uniqstr.c +++ b/src/uniqstr.c @@ -157,13 +157,11 @@ hash_uniqstr (void const *m, size_t tablesize) void uniqstrs_new (void) { - uniqstrs_table = hash_initialize (HT_INITIAL_CAPACITY, - NULL, - hash_uniqstr, - hash_compare_uniqstr, - free); - if (!uniqstrs_table) - xalloc_die (); + uniqstrs_table = hash_xinitialize (HT_INITIAL_CAPACITY, + NULL, + hash_uniqstr, + hash_compare_uniqstr, + free); } From d120a07e6be65657b5a017fa3503aa900fbfa595 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 9 Sep 2019 20:13:04 +0200 Subject: [PATCH 21/24] diagnostics: beware of unexpected EOF when quoting the source file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the input file contains lone CRs (aka, ^M, \r), the locations see a new line. Diagnostics look only at \n as end-of-line, so sometimes there is an offset in diagnostics. Worse yet: sometimes we loop endlessly waiting for \n to come from a continuous stream of EOF. Fix that: - check for EOF - beware not to call end_use_class if begin_use_class was not called (which would abort). This could happen if the actual line is shorter that the expected one. Prompted by a (private) report from Marc Schönefeld. * src/location.c (location_caret): here. * tests/diagnostics.at (Carriage return): New. --- src/location.c | 67 +++++++++++++++++++++++++++----------------- tests/diagnostics.at | 32 ++++++++++++++++++--- 2 files changed, 70 insertions(+), 29 deletions(-) diff --git a/src/location.c b/src/location.c index 80e71fb8..40fbc04e 100644 --- a/src/location.c +++ b/src/location.c @@ -229,7 +229,13 @@ location_caret (location loc, const char *style, FILE *out) /* Advance to the line's position, keeping track of the offset. */ while (caret_info.line < loc.start.line) - caret_info.line += getc (caret_info.source) == '\n'; + { + int c = getc (caret_info.source); + if (c == EOF) + /* Something is wrong, that line number does not exist. */ + return; + caret_info.line += c == '\n'; + } caret_info.offset = ftell (caret_info.source); /* Read the actual line. Don't update the offset, so that we keep a pointer @@ -238,32 +244,43 @@ location_caret (location loc, const char *style, FILE *out) int c = getc (caret_info.source); if (c != EOF) { + bool single_line = loc.start.line == loc.end.line; /* Quote the file (at most the first line in the case of multiline locations). */ - fprintf (out, "%5d | ", loc.start.line); - bool single_line = loc.start.line == loc.end.line; - /* Consider that single point location (with equal boundaries) - actually denote the character that they follow. */ - int byte_end = loc.end.byte + - (single_line && loc.start.byte == loc.end.byte); - /* Byte number. */ - int byte = 1; - while (c != EOF && c != '\n') - { - if (byte == loc.start.byte) - begin_use_class (style, out); - fputc (c, out); - c = getc (caret_info.source); - ++byte; - if (single_line - ? byte == byte_end - : c == '\n' || c == EOF) - end_use_class (style, out); - } - putc ('\n', out); - { - /* Print the carets with the same indentation as above. */ + fprintf (out, "%5d | ", loc.start.line); + /* Consider that single point location (with equal boundaries) + actually denote the character that they follow. */ + int byte_end = loc.end.byte + + (single_line && loc.start.byte == loc.end.byte); + /* Byte number. */ + int byte = 1; + /* Whether we opened the style. If the line is not as + expected (maybe the file was changed since the scanner + ran), we might reach the end before we actually saw the + opening column. */ + bool opened = false; + while (c != EOF && c != '\n') + { + if (byte == loc.start.byte) + { + begin_use_class (style, out); + opened = true; + } + fputc (c, out); + c = getc (caret_info.source); + ++byte; + if (opened + && (single_line + ? byte == byte_end + : c == '\n' || c == EOF)) + end_use_class (style, out); + } + putc ('\n', out); + } + + /* Print the carets with the same indentation as above. */ + { fprintf (out, " | %*s", loc.start.column - 1, ""); begin_use_class (style, out); putc ('^', out); @@ -275,8 +292,8 @@ location_caret (location loc, const char *style, FILE *out) for (int i = loc.start.column + 1; i < len; ++i) putc ('~', out); end_use_class (style, out); + putc ('\n', out); } - putc ('\n', out); } } } diff --git a/tests/diagnostics.at b/tests/diagnostics.at index 15815db3..d9398dd5 100644 --- a/tests/diagnostics.at +++ b/tests/diagnostics.at @@ -35,17 +35,23 @@ AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([[input.y]], [$2]) -AT_DATA([experr.orig], [$4]) +# For some reason, literal ^M in the input are removed and don't end +# in `input.y`. So use the two-character ^M represent it, and let +# Perl insert real CR characters. +AT_CHECK([perl -pi -e 's{\^M}{\r}gx' input.y]) + +AT_DATA([experr], [$4]) + +AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret --color=debug -Wall input.y], [$3], [], [experr]) # When no style, same messages, but without style. -AT_CHECK([perl -p -e 's{}{}g' experr]) +AT_CHECK([perl -pi -e 's{()}{ $[]1 eq "" ? $[]1 : "" }ge' experr]) + # Cannot use AT_BISON_CHECK easily as we need to change the # environment. # FIXME: Enhance AT_BISON_CHECK. AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret -Wall input.y], [$3], [], [experr]) -AT_CHECK([cp experr.orig experr]) -AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret --color=debug -Wall input.y], [$3], [], [experr]) AT_BISON_OPTION_POPDEFS @@ -255,6 +261,24 @@ input.y: warning: fix-its can be applied. Rerun with option ]]) +## ----------------- ## +## Carriage return. ## +## ----------------- ## + +# Carriage-return used to count as a newline in the scanner, and not +# in diagnostics. Resulting in all sort of nice bugs. + +AT_TEST([[Carriage return]], +[[^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M^M +%token " +%% +]], +[1], +[[input.y:37.8-38.0: error: missing '"' at end of line +input.y:37.8-38.0: error: syntax error, unexpected string, expecting char or identifier or +]]) + + m4_popdef([AT_TEST]) From 67444a6f0d5dd2bbac55614b7a0db28b9677975d Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 12 Sep 2019 09:07:48 +0200 Subject: [PATCH 22/24] =?UTF-8?q?news:=20more=20bug=20fixes=20thanks=20to?= =?UTF-8?q?=20Marc=20Sch=C3=B6nefeld?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index 5d67f0ba..9594b1cf 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,9 @@ GNU Bison NEWS New warnings from recent compilers have been addressed in the generated parsers (yacc.c, glr.c, glr.cc). + When lone carriage-return characters appeared in the input file, + diagnostics could hang forever. + * Noteworthy changes in release 3.4.1 (2019-05-22) [stable] ** Bug fixes From ec11f08fb3cbed202be9bce5b75b63d9fdd13f0c Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 12 Sep 2019 13:16:30 +0200 Subject: [PATCH 23/24] CI: always uninstall icc --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0e843e85..01bebe74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -450,4 +450,4 @@ script: - if test ${PART-2} = 2; then make maintainer-check-g++ VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }; fi after_script: - - if [[ $CC == "icc" ]]; then uninstall_intel_software || true; fi + - uninstall_intel_software || true From 69b22b49d42200f1031477ea54d121bd99ae7b00 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 12 Sep 2019 17:41:12 +0200 Subject: [PATCH 24/24] version 3.4.2 * NEWS: Record release date. --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 9594b1cf..2048eb71 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ GNU Bison NEWS -* Noteworthy changes in release ?.? (????-??-??) [?] +* Noteworthy changes in release 3.4.2 (2019-09-12) [stable] ** Bug fixes