1 # Bison Regressions. -*- Autotest -*-
3 # Copyright (C) 2001-2010 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 AT_BANNER([[Regression tests.]])
21 ## ------------------ ##
22 ## Trivial grammars. ##
23 ## ------------------ ##
25 AT_SETUP([Trivial grammars])
27 AT_DATA_GRAMMAR([input.y],
29 void yyerror (char const *);
41 AT_BISON_CHECK([-o input.c input.y])
42 AT_COMPILE([input.o], [-c input.c])
43 AT_COMPILE([input.o], [-DYYDEBUG -c input.c])
49 ## ----------------- ##
50 ## YYSTYPE typedef. ##
51 ## ----------------- ##
53 AT_SETUP([YYSTYPE typedef])
55 AT_DATA_GRAMMAR([input.y],
57 void yyerror (char const *);
59 typedef union { char const *val; } YYSTYPE;
66 program: { $$ = ""; };
69 AT_BISON_CHECK([-o input.c input.y])
70 AT_COMPILE([input.o], [-c input.c])
76 ## ------------------------------------- ##
77 ## Early token definitions with --yacc. ##
78 ## ------------------------------------- ##
81 AT_SETUP([Early token definitions with --yacc])
83 # Found in GCJ: they expect the tokens to be defined before the user
84 # prologue, so that they can use the token definitions in it.
86 AT_DATA_GRAMMAR([input.y],
88 void yyerror (const char *s);
98 # error "MY_TOKEN not defined."
107 AT_BISON_CHECK([-y -o input.c input.y])
108 AT_COMPILE([input.o], [-c input.c])
114 ## ---------------------------------------- ##
115 ## Early token definitions without --yacc. ##
116 ## ---------------------------------------- ##
119 AT_SETUP([Early token definitions without --yacc])
121 # Found in GCJ: they expect the tokens to be defined before the user
122 # prologue, so that they can use the token definitions in it.
124 AT_DATA_GRAMMAR([input.y],
127 void yyerror (const char *s);
129 void print_my_token (void);
138 print_my_token (void)
140 enum yytokentype my_token = MY_TOKEN;
141 printf ("%d\n", my_token);
150 AT_BISON_CHECK([-o input.c input.y])
151 AT_COMPILE([input.o], [-c input.c])
157 ## ---------------- ##
158 ## Braces parsing. ##
159 ## ---------------- ##
162 AT_SETUP([Braces parsing])
165 [[/* Bison used to swallow the character after `}'. */
168 exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
172 AT_BISON_CHECK([-v -o input.c input.y])
174 AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
179 ## ------------------ ##
180 ## Duplicate string. ##
181 ## ------------------ ##
184 AT_SETUP([Duplicate string])
187 [[/* `Bison -v' used to dump core when two tokens are defined with the same
188 string, as LE and GE below. */
195 exp: '(' exp ')' | NUM ;
199 AT_BISON_CHECK([-v -o input.c input.y], 0, [],
200 [[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string
206 ## ------------------- ##
207 ## Rule Line Numbers. ##
208 ## ------------------- ##
210 AT_SETUP([Rule Line Numbers])
212 AT_KEYWORDS([report])
244 AT_BISON_CHECK([-o input.c -v input.y])
246 # Check the contents of the report.
247 AT_CHECK([cat input.output], [],
261 Terminals, with rules where they appear
270 Nonterminals, with rules where they appear
275 on left: 2 4, on right: 0
277 on left: 1, on right: 2
279 on left: 3, on right: 4
284 0 $accept: . expr $end
286 'a' shift, and go to state 1
288 $default reduce using rule 3 ($@2)
296 2 expr: 'a' . $@1 'b'
298 $default reduce using rule 1 ($@1)
305 0 $accept: expr . $end
307 $end shift, and go to state 5
314 'c' shift, and go to state 6
319 2 expr: 'a' $@1 . 'b'
321 'b' shift, and go to state 7
326 0 $accept: expr $end .
335 $default reduce using rule 4 (expr)
340 2 expr: 'a' $@1 'b' .
342 $default reduce using rule 2 (expr)
349 ## ---------------------- ##
350 ## Mixing %token styles. ##
351 ## ---------------------- ##
354 AT_SETUP([Mixing %token styles])
356 # Taken from the documentation.
358 [[%token <operator> OR "||"
359 %token <operator> LE 134 "<="
366 AT_BISON_CHECK([-v -o input.c input.y])
372 ## ---------------- ##
373 ## Invalid inputs. ##
374 ## ---------------- ##
377 AT_SETUP([Invalid inputs])
389 AT_BISON_CHECK([input.y], [1], [],
390 [[input.y:2.1: invalid character: `?'
391 input.y:3.14: invalid character: `}'
392 input.y:4.1: invalid character: `%'
393 input.y:4.2: invalid character: `&'
394 input.y:5.1-17: invalid directive: `%a-does-not-exist'
395 input.y:6.1-2: invalid directive: `%-'
396 input.y:7.1-8.0: missing `%}' at end of file
397 input.y:7.1-8.0: syntax error, unexpected %{...%}
403 AT_SETUP([Invalid inputs with {}])
415 AT_BISON_CHECK([input.y], [1], [],
416 [[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...}
423 ## ------------------- ##
424 ## Token definitions. ##
425 ## ------------------- ##
428 AT_SETUP([Token definitions])
430 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
431 AT_DATA_GRAMMAR([input.y],
435 void yyerror (const char *s);
439 %token MYEOF 0 "end of file"
444 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
445 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
447 exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
450 yyerror (char const *s)
452 fprintf (stderr, "%s\n", s);
471 # Checking the warning message guarantees that the trigraph "??!" isn't
472 # unnecessarily escaped here even though it would need to be if encoded in a
473 # C-string literal. Also notice that unnecessary escaping, such as "\?", from
474 # the user specification is eliminated.
475 AT_BISON_CHECK([-o input.c input.y], [[0]], [[]],
476 [[input.y:22.8-14: warning: symbol SPECIAL redeclared
477 input.y:22.8-63: warning: symbol `"\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!"' used more than once as a literal string
481 # Checking the error message here guarantees that yytname, which does contain
482 # C-string literals, does have the trigraph escaped correctly. Thus, the
483 # symbol name reported by the parser is exactly the same as that reported by
486 [[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!", expecting a
488 AT_PARSER_CHECK([./input], 1, [], [experr])
493 ## -------------------- ##
494 ## Characters Escapes. ##
495 ## -------------------- ##
498 AT_SETUP([Characters Escapes])
500 AT_DATA_GRAMMAR([input.y],
502 void yyerror (const char *s);
512 # Pacify font-lock-mode: "
514 AT_BISON_CHECK([-o input.c input.y])
515 AT_COMPILE([input.o], [-c input.c])
524 # The generation of the reduction was once wrong in Bison, and made it
525 # miss some reductions. In the following test case, the reduction on
526 # `undef_id_tok' in state 1 was missing. This is stripped down from
527 # the actual web2c.y.
529 AT_SETUP([Web2c Report])
531 AT_KEYWORDS([report])
534 [[%token undef_id_tok const_id_tok
536 %start CONST_DEC_PART
545 | CONST_DEC_LIST CONST_DEC
549 { } undef_id_tok '=' const_id_tok ';'
554 AT_BISON_CHECK([-v input.y])
555 AT_CHECK([cat input.output], 0,
558 0 $accept: CONST_DEC_PART $end
560 1 CONST_DEC_PART: CONST_DEC_LIST
562 2 CONST_DEC_LIST: CONST_DEC
563 3 | CONST_DEC_LIST CONST_DEC
567 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';'
570 Terminals, with rules where they appear
580 Nonterminals, with rules where they appear
585 on left: 1, on right: 0
587 on left: 2 3, on right: 1 3
589 on left: 5, on right: 2 3
591 on left: 4, on right: 5
596 0 $accept: . CONST_DEC_PART $end
598 $default reduce using rule 4 ($@1)
600 CONST_DEC_PART go to state 1
601 CONST_DEC_LIST go to state 2
602 CONST_DEC go to state 3
608 0 $accept: CONST_DEC_PART . $end
610 $end shift, and go to state 5
615 1 CONST_DEC_PART: CONST_DEC_LIST .
616 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
618 undef_id_tok reduce using rule 4 ($@1)
619 $default reduce using rule 1 (CONST_DEC_PART)
621 CONST_DEC go to state 6
627 2 CONST_DEC_LIST: CONST_DEC .
629 $default reduce using rule 2 (CONST_DEC_LIST)
634 5 CONST_DEC: $@1 . undef_id_tok '=' const_id_tok ';'
636 undef_id_tok shift, and go to state 7
641 0 $accept: CONST_DEC_PART $end .
648 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
650 $default reduce using rule 3 (CONST_DEC_LIST)
655 5 CONST_DEC: $@1 undef_id_tok . '=' const_id_tok ';'
657 '=' shift, and go to state 8
662 5 CONST_DEC: $@1 undef_id_tok '=' . const_id_tok ';'
664 const_id_tok shift, and go to state 9
669 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok . ';'
671 ';' shift, and go to state 10
676 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' .
678 $default reduce using rule 5 (CONST_DEC)
684 ## --------------- ##
686 ## --------------- ##
688 # The generation of the mapping `state -> action' was once wrong in
689 # extremely specific situations. web2c.y exhibits this situation.
690 # Below is a stripped version of the grammar. It looks like one can
691 # simplify it further, but just don't: it is tuned to exhibit a bug,
692 # which disapears when applying sane grammar transformations.
694 # It used to be wrong on yydefact only:
696 # static const yytype_uint8 yydefact[] =
698 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
699 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
703 # but let's check all the tables.
706 AT_SETUP([Web2c Actions])
708 AT_KEYWORDS([report])
712 statement: struct_stat;
713 struct_stat: /* empty. */ | if else;
714 if: "if" "const" "then" statement;
715 else: "else" statement;
719 AT_BISON_CHECK([-v -o input.c input.y])
721 # Check only the tables.
722 [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
724 AT_CHECK([[cat tables.c]], 0,
725 [[static const yytype_uint8 yytranslate[] =
727 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
728 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
729 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
730 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
731 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
732 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
733 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
734 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
735 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
736 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
737 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
738 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
739 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
740 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
741 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
742 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
743 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
744 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
745 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
746 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
747 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
748 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
749 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
750 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
751 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
752 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
755 static const yytype_uint8 yyrline[] =
759 static const char *const yytname[] =
761 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
762 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
764 static const yytype_uint16 yytoknum[] =
766 0, 256, 257, 258, 259, 260, 261
768 static const yytype_int8 yypact[] =
770 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
773 static const yytype_uint8 yydefact[] =
775 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
778 static const yytype_int8 yypgoto[] =
782 static const yytype_int8 yydefgoto[] =
786 static const yytype_uint8 yytable[] =
788 10, 1, 11, 5, 6, 0, 7, 9
790 static const yytype_int8 yycheck[] =
792 7, 3, 9, 4, 0, -1, 6, 5
794 static const yytype_uint8 yystos[] =
796 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
799 static const yytype_uint8 yyr1[] =
801 0, 7, 8, 9, 9, 10, 11
803 static const yytype_uint8 yyr2[] =
812 ## ------------------------- ##
813 ## yycheck Bound Violation. ##
814 ## ------------------------- ##
817 # _AT_DATA_DANCER_Y(BISON-OPTIONS)
818 # --------------------------------
819 # The following grammar, taken from Andrew Suffield's GPL'd implementation
820 # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
821 # yycheck's bounds where issuing a verbose error message. Keep this test
822 # so that possible bound checking compilers could check all the skeletons.
823 m4_define([_AT_DATA_DANCER_Y],
824 [AT_DATA_GRAMMAR([dancer.y],
826 static int yylex (AT_LALR1_CC_IF([int *], [void]));
827 AT_LALR1_CC_IF([#include <cstdlib>],
830 static void yyerror (const char *);])
833 %token ARROW INVALID NUMBER STRING DATA
837 /* Grammar follows */
842 header: '<' from ARROW to '>' type ':'
843 | '<' ARROW to '>' type ':'
877 [/* A C++ error reporting function. */
879 yy::parser::error (const std::string& m)
881 std::cerr << m << std::endl;
889 parser.set_debug_level (YYDEBUG);
891 return parser.parse ();
895 yyerror (const char *s)
897 fprintf (stderr, "%s\n", s);
901 yylex (AT_LALR1_CC_IF([int *lval], [void]))
903 static int const tokens[] =
907 static size_t toknum;
908 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
909 if (! (toknum < sizeof tokens / sizeof *tokens))
911 return tokens[toknum++];
920 ])# _AT_DATA_DANCER_Y
923 # AT_CHECK_DANCER(BISON-OPTIONS)
924 # ------------------------------
925 # Generate the grammar, compile it, run it.
926 m4_define([AT_CHECK_DANCER],
927 [AT_SETUP([Dancer $1])
928 AT_BISON_OPTION_PUSHDEFS([$1])
929 _AT_DATA_DANCER_Y([$1])
930 AT_BISON_CHECK([-o dancer.c dancer.y])
931 AT_FULL_COMPILE([dancer])
932 AT_PARSER_CHECK([./dancer], 1, [],
933 [syntax error, unexpected ':'
935 AT_BISON_OPTION_POPDEFS
940 AT_CHECK_DANCER([%glr-parser])
941 AT_CHECK_DANCER([%skeleton "lalr1.cc"])
944 ## ------------------------------------------ ##
945 ## Diagnostic that expects two alternatives. ##
946 ## ------------------------------------------ ##
949 # _AT_DATA_EXPECT2_Y(BISON-OPTIONS)
950 # --------------------------------
951 m4_define([_AT_DATA_EXPECT2_Y],
952 [AT_DATA_GRAMMAR([expect2.y],
954 static int yylex (AT_LALR1_CC_IF([int *], [void]));
955 AT_LALR1_CC_IF([#include <cstdlib>],
958 static void yyerror (const char *);])
976 [/* A C++ error reporting function. */
978 yy::parser::error (const std::string& m)
980 std::cerr << m << std::endl;
987 return parser.parse ();
991 yyerror (const char *s)
993 fprintf (stderr, "%s\n", s);
997 yylex (AT_LALR1_CC_IF([int *lval], [void]))
999 static int const tokens[] =
1003 static size_t toknum;
1004 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
1005 if (! (toknum < sizeof tokens / sizeof *tokens))
1007 return tokens[toknum++];
1016 ])# _AT_DATA_EXPECT2_Y
1019 # AT_CHECK_EXPECT2(BISON-OPTIONS)
1020 # ------------------------------
1021 # Generate the grammar, compile it, run it.
1022 m4_define([AT_CHECK_EXPECT2],
1023 [AT_SETUP([Expecting two tokens $1])
1024 AT_BISON_OPTION_PUSHDEFS([$1])
1025 _AT_DATA_EXPECT2_Y([$1])
1026 AT_BISON_CHECK([-o expect2.c expect2.y])
1027 AT_FULL_COMPILE([expect2])
1028 AT_PARSER_CHECK([./expect2], 1, [],
1029 [syntax error, unexpected '+', expecting A or B
1031 AT_BISON_OPTION_POPDEFS
1036 AT_CHECK_EXPECT2([%glr-parser])
1037 AT_CHECK_EXPECT2([%skeleton "lalr1.cc"])
1041 ## --------------------------------------------- ##
1042 ## Braced code in declaration in rules section. ##
1043 ## --------------------------------------------- ##
1045 AT_SETUP([Braced code in declaration in rules section])
1047 # Bison once mistook braced code in a declaration in the rules section to be a
1050 AT_DATA_GRAMMAR([input.y],
1053 static void yyerror (char const *msg);
1054 static int yylex (void);
1063 printf ("Bison would once convert this action to a midrule because of the"
1064 " subsequent braced code.\n");
1068 %destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a';
1069 %printer { fprintf (yyoutput, "PRINTER"); } 'a';
1074 yyerror (char const *msg)
1076 fprintf (stderr, "%s\n", msg);
1093 AT_BISON_CHECK([-t -o input.c input.y])
1095 AT_PARSER_CHECK([./input], 0,
1096 [[Bison would once convert this action to a midrule because of the subsequent braced code.
1100 Reducing stack by rule 1 (line 20):
1101 -> $$ = nterm start ()
1104 Reading a token: Next token is token 'a' (PRINTER)
1105 syntax error, unexpected 'a', expecting $end
1106 Error: popping nterm start ()
1108 Cleanup: discarding lookahead token 'a' (PRINTER)
1117 ## --------------------------------- ##
1118 ## String alias declared after use. ##
1119 ## --------------------------------- ##
1121 AT_SETUP([String alias declared after use])
1123 # Bison once incorrectly asserted that the symbol number for either a token or
1124 # its alias was the highest symbol number so far at the point of the alias
1125 # declaration. That was true unless the declaration appeared after their first
1126 # uses and other tokens appeared in between.
1134 AT_BISON_CHECK([-t -o input.c input.y])
1140 ## -------------------------------- ##
1141 ## Extra lookahead sets in report. ##
1142 ## -------------------------------- ##
1144 AT_SETUP([[Extra lookahead sets in report]])
1146 # Bison prints each reduction's lookahead set only next to the associated
1147 # state's one item that (1) is associated with the same rule as the reduction
1148 # and (2) has its dot at the end of its RHS. Previously, Bison also
1149 # erroneously printed the lookahead set next to all of the state's other items
1150 # associated with the same rule. This bug affected only the `.output' file and
1151 # not the generated parser source code.
1153 AT_DATA([[input.y]],
1155 start: a | 'a' a 'a' ;
1159 AT_BISON_CHECK([[--report=all input.y]])
1160 AT_CHECK([[sed -n '/^state 1$/,/^state 2$/p' input.output]], [[0]],
1163 2 start: 'a' . a 'a'
1167 'a' shift, and go to state 4
1169 $default reduce using rule 3 (a)
1181 ## ---------------------------------------- ##
1182 ## Token number in precedence declaration. ##
1183 ## ---------------------------------------- ##
1185 AT_SETUP([[Token number in precedence declaration]])
1187 # POSIX says token numbers can be declared in %left, %right, and %nonassoc, but
1188 # we lost this in Bison 1.50.
1190 AT_DATA_GRAMMAR([input.y],
1193 void yyerror (char const *);
1198 %left TK1 1 TK2 2 "tok alias" 3
1202 start: TK1 sr_conflict "tok alias" ;
1212 yyerror (char const *msg)
1214 fprintf (stderr, "%s\n", msg);
1220 static int const input[] = { 1, 2, 3, 0 };
1221 static int const *inputp = input;
1232 AT_BISON_CHECK([[-o input.c input.y]], [[0]],,
1233 [[input.y:24.5-19: warning: rule useless in parser due to conflicts: sr_conflict: TK2 "tok alias"
1235 AT_COMPILE([[input]])
1236 AT_PARSER_CHECK([[./input]])
1242 ## --------------------------- ##
1243 ## parse-gram.y: LALR = IELR. ##
1244 ## --------------------------- ##
1246 # If parse-gram.y's LALR and IELR parser tables ever begin to differ, we
1247 # need to fix parse-gram.y or start using IELR.
1249 AT_SETUP([[parse-gram.y: LALR = IELR]])
1251 # Avoid tests/bison's dark magic by processing a local copy of the
1252 # grammar. Avoid differences in synclines by telling bison that the
1253 # output files have the same name.
1254 [cp $abs_top_srcdir/src/parse-gram.y input.y]
1255 AT_BISON_CHECK([[-o input.c -Dlr.type=lalr input.y]])
1257 AT_BISON_CHECK([[-o input.c -Dlr.type=ielr input.y]])
1259 AT_CHECK([[diff -u lalr.c ielr.c]])
1265 ## -------------------------------------------- ##
1266 ## parse.error=verbose and YYSTACK_USE_ALLOCA. ##
1267 ## -------------------------------------------- ##
1269 AT_SETUP([[parse.error=verbose and YYSTACK_USE_ALLOCA]])
1271 AT_DATA_GRAMMAR([input.y],
1274 void yyerror (char const *);
1276 #define YYSTACK_USE_ALLOCA 1
1279 %define parse.error verbose
1283 start: check syntax_error syntax_error ;
1287 if (128 < sizeof yymsgbuf)
1290 "The initial size of yymsgbuf in yyparse has increased\n"
1291 "since this test group was last updated. As a result,\n"
1292 "this test group may no longer manage to induce a\n"
1293 "reallocation of the syntax error message buffer.\n"
1294 "This test group must be adjusted to produce a longer\n"
1295 "error message.\n");
1301 // Induce a syntax error message whose total length is more than
1302 // sizeof yymsgbuf in yyparse. Each token here is 64 bytes.
1304 "123456789112345678921234567893123456789412345678951234567896123A"
1305 | "123456789112345678921234567893123456789412345678951234567896123B"
1312 yyerror (char const *msg)
1314 fprintf (stderr, "%s\n", msg);
1320 /* Induce two syntax error messages (which requires full error
1321 recovery by shifting 3 tokens) in order to detect any loss of the
1322 reallocated buffer. */
1323 static char const *input = "abc";
1334 AT_BISON_CHECK([[-o input.c input.y]])
1335 AT_COMPILE([[input]])
1336 AT_PARSER_CHECK([[./input]], [[1]], [],
1337 [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1338 syntax error, unexpected $end, expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1345 ## ------------------------------ ##
1346 ## parse.error=verbose overflow. ##
1347 ## ------------------------------ ##
1349 # Imagine the case where YYSTACK_ALLOC_MAXIMUM = YYSIZE_MAXIMUM and an
1350 # invocation of yysyntax_error has caused yymsg_alloc to grow to exactly
1351 # YYSTACK_ALLOC_MAXIMUM (perhaps because the normal doubling of size had
1352 # to be clipped to YYSTACK_ALLOC_MAXIMUM). In an old version of yacc.c,
1353 # a subsequent invocation of yysyntax_error that overflows during its
1354 # size calculation would return YYSIZE_MAXIMUM to yyparse. Then,
1355 # yyparse would invoke yyerror using the old contents of yymsg.
1357 AT_SETUP([[parse.error=verbose overflow]])
1359 AT_DATA_GRAMMAR([input.y],
1362 void yyerror (char const *);
1365 /* This prevents this test case from having to induce error messages
1366 large enough to overflow size_t. */
1367 #define YYSIZE_T unsigned char
1369 /* Bring in malloc and set _STDLIB_H so yacc.c doesn't try to
1370 provide a malloc prototype using our YYSIZE_T. */
1373 # define _STDLIB_H 1
1376 /* Max depth is usually much smaller than YYSTACK_ALLOC_MAXIMUM, and
1377 we don't want gcc to warn everywhere this constant would be too big
1378 to make sense for our YYSIZE_T. */
1379 #define YYMAXDEPTH 100
1382 %define parse.error verbose
1386 start: syntax_error1 check syntax_error2 ;
1388 // Induce a syntax error message whose total length causes yymsg in
1389 // yyparse to be reallocated to size YYSTACK_ALLOC_MAXIMUM, which
1390 // should be 255. Each token here is 64 bytes.
1392 "123456789112345678921234567893123456789412345678951234567896123A"
1393 | "123456789112345678921234567893123456789412345678951234567896123B"
1394 | "123456789112345678921234567893123456789412345678951234567896123C"
1400 if (yymsg_alloc != YYSTACK_ALLOC_MAXIMUM
1401 || YYSTACK_ALLOC_MAXIMUM != YYSIZE_MAXIMUM
1402 || YYSIZE_MAXIMUM != 255)
1405 "The assumptions of this test group are no longer\n"
1406 "valid, so it may no longer catch the error it was\n"
1407 "designed to catch. Specifically, the following\n"
1408 "values should all be 255:\n\n");
1409 fprintf (stderr, " yymsg_alloc = %d\n", yymsg_alloc);
1410 fprintf (stderr, " YYSTACK_ALLOC_MAXIMUM = %d\n",
1411 YYSTACK_ALLOC_MAXIMUM);
1412 fprintf (stderr, " YYSIZE_MAXIMUM = %d\n", YYSIZE_MAXIMUM);
1420 "123456789112345678921234567893123456789412345678951234567896123A"
1421 | "123456789112345678921234567893123456789412345678951234567896123B"
1422 | "123456789112345678921234567893123456789412345678951234567896123C"
1423 | "123456789112345678921234567893123456789412345678951234567896123D"
1424 | "123456789112345678921234567893123456789412345678951234567896123E"
1430 yyerror (char const *msg)
1432 fprintf (stderr, "%s\n", msg);
1438 /* Induce two syntax error messages (which requires full error
1439 recovery by shifting 3 tokens). */
1440 static char const *input = "abc";
1447 /* Push parsers throw away the message buffer between tokens, so skip
1448 this test under maintainer-push-check. */
1455 AT_BISON_CHECK([[-o input.c input.y]])
1457 # gcc warns about tautologies and fallacies involving comparisons for
1458 # unsigned char. However, it doesn't produce these same warnings for
1459 # size_t and many other types when the warnings would seem to make just
1460 # as much sense. We ignore the warnings.
1461 [CFLAGS="$NO_WERROR_CFLAGS"]
1462 AT_COMPILE([[input]])
1464 AT_PARSER_CHECK([[./input]], [[2]], [],
1465 [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B or 123456789112345678921234567893123456789412345678951234567896123C