1 # Bison Regressions. -*- Autotest -*-
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 AT_BANNER([[Regression tests.]])
22 ## ------------------ ##
23 ## Trivial grammars. ##
24 ## ------------------ ##
26 AT_SETUP([Trivial grammars])
28 AT_DATA_GRAMMAR([input.y],
30 void yyerror (char const *);
42 AT_BISON_CHECK([-o input.c input.y])
43 AT_COMPILE([input.o], [-c input.c])
44 AT_COMPILE([input.o], [-DYYDEBUG -c input.c])
50 ## ----------------- ##
51 ## YYSTYPE typedef. ##
52 ## ----------------- ##
54 AT_SETUP([YYSTYPE typedef])
56 AT_DATA_GRAMMAR([input.y],
58 void yyerror (char const *);
60 typedef union { char const *val; } YYSTYPE;
67 program: { $$ = ""; };
70 AT_BISON_CHECK([-o input.c input.y])
71 AT_COMPILE([input.o], [-c input.c])
77 ## ------------------------------------- ##
78 ## Early token definitions with --yacc. ##
79 ## ------------------------------------- ##
82 AT_SETUP([Early token definitions with --yacc])
84 # Found in GCJ: they expect the tokens to be defined before the user
85 # prologue, so that they can use the token definitions in it.
87 AT_DATA_GRAMMAR([input.y],
89 void yyerror (const char *s);
99 # error "MY_TOKEN not defined."
108 AT_BISON_CHECK([-y -o input.c input.y])
109 AT_COMPILE([input.o], [-c input.c])
115 ## ---------------------------------------- ##
116 ## Early token definitions without --yacc. ##
117 ## ---------------------------------------- ##
120 AT_SETUP([Early token definitions without --yacc])
122 # Found in GCJ: they expect the tokens to be defined before the user
123 # prologue, so that they can use the token definitions in it.
125 AT_DATA_GRAMMAR([input.y],
128 void yyerror (const char *s);
130 void print_my_token (void);
139 print_my_token (void)
141 enum yytokentype my_token = MY_TOKEN;
142 printf ("%d\n", my_token);
151 AT_BISON_CHECK([-o input.c input.y])
152 AT_COMPILE([input.o], [-c input.c])
158 ## ---------------- ##
159 ## Braces parsing. ##
160 ## ---------------- ##
163 AT_SETUP([Braces parsing])
166 [[/* Bison used to swallow the character after `}'. */
169 exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
173 AT_BISON_CHECK([-v -o input.c input.y])
175 AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
180 ## ------------------ ##
181 ## Duplicate string. ##
182 ## ------------------ ##
185 AT_SETUP([Duplicate string])
188 [[/* `Bison -v' used to dump core when two tokens are defined with the same
189 string, as LE and GE below. */
196 exp: '(' exp ')' | NUM ;
200 AT_BISON_CHECK([-v -o input.c input.y], 0, [],
201 [[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string
207 ## ------------------- ##
208 ## Rule Line Numbers. ##
209 ## ------------------- ##
211 AT_SETUP([Rule Line Numbers])
213 AT_KEYWORDS([report])
245 AT_BISON_CHECK([-o input.c -v input.y])
247 # Check the contents of the report.
248 AT_CHECK([cat input.output], [],
262 Terminals, with rules where they appear
271 Nonterminals, with rules where they appear
276 on left: 2 4, on right: 0
278 on left: 1, on right: 2
280 on left: 3, on right: 4
285 0 $accept: . expr $end
287 'a' shift, and go to state 1
289 $default reduce using rule 3 ($@2)
297 2 expr: 'a' . $@1 'b'
299 $default reduce using rule 1 ($@1)
306 0 $accept: expr . $end
308 $end shift, and go to state 5
315 'c' shift, and go to state 6
320 2 expr: 'a' $@1 . 'b'
322 'b' shift, and go to state 7
327 0 $accept: expr $end .
336 $default reduce using rule 4 (expr)
341 2 expr: 'a' $@1 'b' .
343 $default reduce using rule 2 (expr)
350 ## ---------------------- ##
351 ## Mixing %token styles. ##
352 ## ---------------------- ##
355 AT_SETUP([Mixing %token styles])
357 # Taken from the documentation.
359 [[%token <operator> OR "||"
360 %token <operator> LE 134 "<="
367 AT_BISON_CHECK([-v -o input.c input.y])
373 ## ---------------- ##
374 ## Invalid inputs. ##
375 ## ---------------- ##
378 AT_SETUP([Invalid inputs])
390 AT_BISON_CHECK([input.y], [1], [],
391 [[input.y:2.1: invalid character: `?'
392 input.y:3.14: invalid character: `}'
393 input.y:4.1: invalid character: `%'
394 input.y:4.2: invalid character: `&'
395 input.y:5.1-17: invalid directive: `%a-does-not-exist'
396 input.y:6.1-2: invalid directive: `%-'
397 input.y:7.1-8.0: missing `%}' at end of file
398 input.y:7.1-8.0: syntax error, unexpected %{...%}
404 AT_SETUP([Invalid inputs with {}])
416 AT_BISON_CHECK([input.y], [1], [],
417 [[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...}
424 ## ------------------- ##
425 ## Token definitions. ##
426 ## ------------------- ##
429 AT_SETUP([Token definitions])
431 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
432 AT_DATA_GRAMMAR([input.y],
436 void yyerror (const char *s);
440 %token MYEOF 0 "end of file"
445 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
446 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
448 exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
451 yyerror (char const *s)
453 fprintf (stderr, "%s\n", s);
472 # Checking the warning message guarantees that the trigraph "??!" isn't
473 # unnecessarily escaped here even though it would need to be if encoded in a
474 # C-string literal. Also notice that unnecessary escaping, such as "\?", from
475 # the user specification is eliminated.
476 AT_BISON_CHECK([-o input.c input.y], [[0]], [[]],
477 [[input.y:22.8-14: warning: symbol SPECIAL redeclared
478 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
482 # Checking the error message here guarantees that yytname, which does contain
483 # C-string literals, does have the trigraph escaped correctly. Thus, the
484 # symbol name reported by the parser is exactly the same as that reported by
487 [[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!", expecting a
489 AT_PARSER_CHECK([./input], 1, [], [experr])
494 ## -------------------- ##
495 ## Characters Escapes. ##
496 ## -------------------- ##
499 AT_SETUP([Characters Escapes])
501 AT_DATA_GRAMMAR([input.y],
503 void yyerror (const char *s);
513 # Pacify font-lock-mode: "
515 AT_BISON_CHECK([-o input.c input.y])
516 AT_COMPILE([input.o], [-c input.c])
525 # The generation of the reduction was once wrong in Bison, and made it
526 # miss some reductions. In the following test case, the reduction on
527 # `undef_id_tok' in state 1 was missing. This is stripped down from
528 # the actual web2c.y.
530 AT_SETUP([Web2c Report])
532 AT_KEYWORDS([report])
535 [[%token undef_id_tok const_id_tok
537 %start CONST_DEC_PART
546 | CONST_DEC_LIST CONST_DEC
550 { } undef_id_tok '=' const_id_tok ';'
555 AT_BISON_CHECK([-v input.y])
556 AT_CHECK([cat input.output], 0,
559 0 $accept: CONST_DEC_PART $end
561 1 CONST_DEC_PART: CONST_DEC_LIST
563 2 CONST_DEC_LIST: CONST_DEC
564 3 | CONST_DEC_LIST CONST_DEC
568 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';'
571 Terminals, with rules where they appear
581 Nonterminals, with rules where they appear
586 on left: 1, on right: 0
588 on left: 2 3, on right: 1 3
590 on left: 5, on right: 2 3
592 on left: 4, on right: 5
597 0 $accept: . CONST_DEC_PART $end
599 $default reduce using rule 4 ($@1)
601 CONST_DEC_PART go to state 1
602 CONST_DEC_LIST go to state 2
603 CONST_DEC go to state 3
609 0 $accept: CONST_DEC_PART . $end
611 $end shift, and go to state 5
616 1 CONST_DEC_PART: CONST_DEC_LIST .
617 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
619 undef_id_tok reduce using rule 4 ($@1)
620 $default reduce using rule 1 (CONST_DEC_PART)
622 CONST_DEC go to state 6
628 2 CONST_DEC_LIST: CONST_DEC .
630 $default reduce using rule 2 (CONST_DEC_LIST)
635 5 CONST_DEC: $@1 . undef_id_tok '=' const_id_tok ';'
637 undef_id_tok shift, and go to state 7
642 0 $accept: CONST_DEC_PART $end .
649 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
651 $default reduce using rule 3 (CONST_DEC_LIST)
656 5 CONST_DEC: $@1 undef_id_tok . '=' const_id_tok ';'
658 '=' shift, and go to state 8
663 5 CONST_DEC: $@1 undef_id_tok '=' . const_id_tok ';'
665 const_id_tok shift, and go to state 9
670 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok . ';'
672 ';' shift, and go to state 10
677 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' .
679 $default reduce using rule 5 (CONST_DEC)
685 ## --------------- ##
687 ## --------------- ##
689 # The generation of the mapping `state -> action' was once wrong in
690 # extremely specific situations. web2c.y exhibits this situation.
691 # Below is a stripped version of the grammar. It looks like one can
692 # simplify it further, but just don't: it is tuned to exhibit a bug,
693 # which disapears when applying sane grammar transformations.
695 # It used to be wrong on yydefact only:
697 # static const yytype_uint8 yydefact[] =
699 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
700 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
704 # but let's check all the tables.
707 AT_SETUP([Web2c Actions])
709 AT_KEYWORDS([report])
713 statement: struct_stat;
714 struct_stat: /* empty. */ | if else;
715 if: "if" "const" "then" statement;
716 else: "else" statement;
720 AT_BISON_CHECK([-v -o input.c input.y])
722 # Check only the tables.
723 [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
725 AT_CHECK([[cat tables.c]], 0,
726 [[static const yytype_uint8 yytranslate[] =
728 0, 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, 2, 2, 2, 2,
753 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
756 static const yytype_uint8 yyprhs[] =
760 static const yytype_int8 yyrhs[] =
762 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
763 4, 5, 8, -1, 6, 8, -1
765 static const yytype_uint8 yyrline[] =
769 static const char *const yytname[] =
771 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
772 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
774 static const yytype_uint16 yytoknum[] =
776 0, 256, 257, 258, 259, 260, 261
778 static const yytype_uint8 yyr1[] =
780 0, 7, 8, 9, 9, 10, 11
782 static const yytype_uint8 yyr2[] =
786 static const yytype_uint8 yydefact[] =
788 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
791 static const yytype_int8 yydefgoto[] =
795 static const yytype_int8 yypact[] =
797 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
800 static const yytype_int8 yypgoto[] =
804 static const yytype_uint8 yytable[] =
806 10, 1, 11, 5, 6, 0, 7, 9
808 static const yytype_int8 yycheck[] =
810 7, 3, 9, 4, 0, -1, 6, 5
812 static const yytype_uint8 yystos[] =
814 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
822 ## ------------------------- ##
823 ## yycheck Bound Violation. ##
824 ## ------------------------- ##
827 # _AT_DATA_DANCER_Y(BISON-OPTIONS)
828 # --------------------------------
829 # The following grammar, taken from Andrew Suffield's GPL'd implementation
830 # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
831 # yycheck's bounds where issuing a verbose error message. Keep this test
832 # so that possible bound checking compilers could check all the skeletons.
833 m4_define([_AT_DATA_DANCER_Y],
834 [AT_DATA_GRAMMAR([dancer.y],
836 static int yylex (AT_LALR1_CC_IF([int *], [void]));
840 static void yyerror (const char *);])
843 %token ARROW INVALID NUMBER STRING DATA
847 /* Grammar follows */
852 header: '<' from ARROW to '>' type ':'
853 | '<' ARROW to '>' type ':'
887 [/* A C++ error reporting function. */
889 yy::parser::error (const location&, const std::string& m)
891 std::cerr << m << std::endl;
899 parser.set_debug_level (YYDEBUG);
901 return parser.parse ();
905 yyerror (const char *s)
907 fprintf (stderr, "%s\n", s);
911 yylex (AT_LALR1_CC_IF([int *lval], [void]))
913 static int const tokens[] =
917 static size_t toknum;
918 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
919 if (! (toknum < sizeof tokens / sizeof *tokens))
921 return tokens[toknum++];
930 ])# _AT_DATA_DANCER_Y
933 # AT_CHECK_DANCER(BISON-OPTIONS)
934 # ------------------------------
935 # Generate the grammar, compile it, run it.
936 m4_define([AT_CHECK_DANCER],
937 [AT_SETUP([Dancer $1])
938 AT_BISON_OPTION_PUSHDEFS([$1])
939 _AT_DATA_DANCER_Y([$1])
940 AT_BISON_CHECK([-o dancer.c dancer.y])
941 AT_FULL_COMPILE([dancer])
942 AT_PARSER_CHECK([./dancer], 1, [],
943 [syntax error, unexpected ':'
945 AT_BISON_OPTION_POPDEFS
950 AT_CHECK_DANCER([%glr-parser])
951 AT_CHECK_DANCER([%skeleton "lalr1.cc"])
954 ## ------------------------------------------ ##
955 ## Diagnostic that expects two alternatives. ##
956 ## ------------------------------------------ ##
959 # _AT_DATA_EXPECT2_Y(BISON-OPTIONS)
960 # --------------------------------
961 m4_define([_AT_DATA_EXPECT2_Y],
962 [AT_DATA_GRAMMAR([expect2.y],
964 static int yylex (AT_LALR1_CC_IF([int *], [void]));
968 static void yyerror (const char *);])
986 [/* A C++ error reporting function. */
988 yy::parser::error (const location&, const std::string& m)
990 std::cerr << m << std::endl;
997 return parser.parse ();
1001 yyerror (const char *s)
1003 fprintf (stderr, "%s\n", s);
1007 yylex (AT_LALR1_CC_IF([int *lval], [void]))
1009 static int const tokens[] =
1013 static size_t toknum;
1014 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
1015 if (! (toknum < sizeof tokens / sizeof *tokens))
1017 return tokens[toknum++];
1026 ])# _AT_DATA_EXPECT2_Y
1029 # AT_CHECK_EXPECT2(BISON-OPTIONS)
1030 # ------------------------------
1031 # Generate the grammar, compile it, run it.
1032 m4_define([AT_CHECK_EXPECT2],
1033 [AT_SETUP([Expecting two tokens $1])
1034 AT_BISON_OPTION_PUSHDEFS([$1])
1035 _AT_DATA_EXPECT2_Y([$1])
1036 AT_BISON_CHECK([-o expect2.c expect2.y])
1037 AT_FULL_COMPILE([expect2])
1038 AT_PARSER_CHECK([./expect2], 1, [],
1039 [syntax error, unexpected '+', expecting A or B
1041 AT_BISON_OPTION_POPDEFS
1046 AT_CHECK_EXPECT2([%glr-parser])
1047 AT_CHECK_EXPECT2([%skeleton "lalr1.cc"])
1051 ## --------------------------------------------- ##
1052 ## Braced code in declaration in rules section. ##
1053 ## --------------------------------------------- ##
1055 AT_SETUP([Braced code in declaration in rules section])
1057 # Bison once mistook braced code in a declaration in the rules section to be a
1060 AT_DATA_GRAMMAR([input.y],
1063 static void yyerror (char const *msg);
1064 static int yylex (void);
1073 printf ("Bison would once convert this action to a midrule because of the"
1074 " subsequent braced code.\n");
1078 %destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a';
1079 %printer { fprintf (yyoutput, "PRINTER"); } 'a';
1084 yyerror (char const *msg)
1086 fprintf (stderr, "%s\n", msg);
1103 AT_BISON_CHECK([-t -o input.c input.y])
1105 AT_PARSER_CHECK([./input], 0,
1106 [[Bison would once convert this action to a midrule because of the subsequent braced code.
1110 Reducing stack by rule 1 (line 20):
1111 -> $$ = nterm start ()
1114 Reading a token: Next token is token 'a' (PRINTER)
1115 syntax error, unexpected 'a', expecting $end
1116 Error: popping nterm start ()
1118 Cleanup: discarding lookahead token 'a' (PRINTER)
1127 ## --------------------------------- ##
1128 ## String alias declared after use. ##
1129 ## --------------------------------- ##
1131 AT_SETUP([String alias declared after use])
1133 # Bison once incorrectly asserted that the symbol number for either a token or
1134 # its alias was the highest symbol number so far at the point of the alias
1135 # declaration. That was true unless the declaration appeared after their first
1136 # uses and other tokens appeared in between.
1144 AT_BISON_CHECK([-t -o input.c input.y])
1150 ## -------------------------------- ##
1151 ## Extra lookahead sets in report. ##
1152 ## -------------------------------- ##
1154 AT_SETUP([[Extra lookahead sets in report]])
1156 # Bison prints each reduction's lookahead set only next to the associated
1157 # state's one item that (1) is associated with the same rule as the reduction
1158 # and (2) has its dot at the end of its RHS. Previously, Bison also
1159 # erroneously printed the lookahead set next to all of the state's other items
1160 # associated with the same rule. This bug affected only the `.output' file and
1161 # not the generated parser source code.
1163 AT_DATA([[input.y]],
1165 start: a | 'a' a 'a' ;
1169 AT_BISON_CHECK([[--report=all input.y]])
1170 AT_CHECK([[sed -n '/^state 1$/,/^state 2$/p' input.output]], [[0]],
1173 2 start: 'a' . a 'a'
1177 'a' shift, and go to state 4
1179 $default reduce using rule 3 (a)
1191 ## ---------------------------------------- ##
1192 ## Token number in precedence declaration. ##
1193 ## ---------------------------------------- ##
1195 AT_SETUP([[Token number in precedence declaration]])
1197 # POSIX says token numbers can be declared in %left, %right, and %nonassoc, but
1198 # we lost this in Bison 1.50.
1200 AT_DATA_GRAMMAR([input.y],
1203 void yyerror (char const *);
1208 %left TK1 1 TK2 2 "tok alias" 3
1212 start: TK1 sr_conflict "tok alias" ;
1222 yyerror (char const *msg)
1224 fprintf (stderr, "%s\n", msg);
1230 static int const input[] = { 1, 2, 3, 0 };
1231 static int const *inputp = input;
1242 AT_BISON_CHECK([[-o input.c input.y]], [[0]],,
1243 [[input.y:24.5-19: warning: rule useless in parser due to conflicts: sr_conflict: TK2 "tok alias"
1245 AT_COMPILE([[input]])
1246 AT_PARSER_CHECK([[./input]])
1252 ## --------------------------- ##
1253 ## parse-gram.y: LALR = IELR. ##
1254 ## --------------------------- ##
1256 # If parse-gram.y's LALR and IELR parser tables ever begin to differ, we
1257 # need to fix parse-gram.y or start using IELR.
1259 AT_SETUP([[parse-gram.y: LALR = IELR]])
1261 # Avoid differences in synclines by telling bison that the output files
1262 # have the same name.
1263 [cp $abs_top_srcdir/src/parse-gram.y input.y]
1264 AT_BISON_CHECK([[-o input.c -Dlr.type=lalr input.y]])
1266 AT_BISON_CHECK([[-o input.c -Dlr.type=ielr input.y]])
1268 AT_CHECK([[diff -u lalr.c ielr.c]])
1274 ## --------------------------------------- ##
1275 ## %error-verbose and YYSTACK_USE_ALLOCA. ##
1276 ## --------------------------------------- ##
1278 AT_SETUP([[%error-verbose and YYSTACK_USE_ALLOCA]])
1280 AT_DATA_GRAMMAR([input.y],
1283 void yyerror (char const *);
1285 #define YYSTACK_USE_ALLOCA 1
1292 start: check syntax_error syntax_error ;
1296 if (128 < sizeof yymsgbuf)
1299 "The initial size of yymsgbuf in yyparse has increased\n"
1300 "since this test group was last updated. As a result,\n"
1301 "this test group may no longer manage to induce a\n"
1302 "reallocation of the syntax error message buffer.\n"
1303 "This test group must be adjusted to produce a longer\n"
1304 "error message.\n");
1310 // Induce a syntax error message whose total length is more than
1311 // sizeof yymsgbuf in yyparse. Each token here is 64 bytes.
1313 "123456789112345678921234567893123456789412345678951234567896123A"
1314 | "123456789112345678921234567893123456789412345678951234567896123B"
1321 yyerror (char const *msg)
1323 fprintf (stderr, "%s\n", msg);
1329 /* Induce two syntax error messages (which requires full error
1330 recovery by shifting 3 tokens) in order to detect any loss of the
1331 reallocated buffer. */
1332 static char const *input = "abc";
1343 AT_BISON_CHECK([[-o input.c input.y]])
1344 AT_COMPILE([[input]])
1345 AT_PARSER_CHECK([[./input]], [[1]], [],
1346 [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1347 syntax error, unexpected $end, expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1354 ## ------------------------- ##
1355 ## %error-verbose overflow. ##
1356 ## ------------------------- ##
1358 # Imagine the case where YYSTACK_ALLOC_MAXIMUM = YYSIZE_MAXIMUM and an
1359 # invocation of yysyntax_error has caused yymsg_alloc to grow to exactly
1360 # YYSTACK_ALLOC_MAXIMUM (perhaps because the normal doubling of size had
1361 # to be clipped to YYSTACK_ALLOC_MAXIMUM). Now imagine a subsequent
1362 # invocation of yysyntax_error that overflows during its size
1363 # calculation and thus returns YYSIZE_MAXIMUM to yyparse. Then, yyparse
1364 # will invoke yyerror using the old contents of yymsg. This bug needs
1367 AT_SETUP([[%error-verbose overflow]])
1371 AT_DATA_GRAMMAR([input.y],
1374 void yyerror (char const *);
1377 /* This prevents this test case from having to induce error messages
1378 large enough to overflow size_t. */
1379 #define YYSIZE_T unsigned char
1381 /* Bring in malloc so yacc.c doesn't try to provide a malloc prototype
1382 using our YYSIZE_T. */
1385 /* Max depth is usually much smaller than YYSTACK_ALLOC_MAXIMUM, and
1386 we don't want gcc to warn everywhere this constant would be too big
1387 to make sense for our YYSIZE_T. */
1388 #define YYMAXDEPTH 100
1395 start: syntax_error1 check syntax_error2 ;
1397 // Induce a syntax error message whose total length causes yymsg in
1398 // yyparse to be reallocated to size YYSTACK_ALLOC_MAXIMUM, which
1399 // should be 255. Each token here is 64 bytes.
1401 "123456789112345678921234567893123456789412345678951234567896123A"
1402 | "123456789112345678921234567893123456789412345678951234567896123B"
1403 | "123456789112345678921234567893123456789412345678951234567896123C"
1409 if (yymsg_alloc != YYSTACK_ALLOC_MAXIMUM
1410 || YYSTACK_ALLOC_MAXIMUM != YYSIZE_MAXIMUM
1411 || YYSIZE_MAXIMUM != 255)
1414 "The assumptions of this test group are no longer\n"
1415 "valid, so it may no longer catch the error it was\n"
1416 "designed to catch. Specifically, the following\n"
1417 "values should all be 255:\n\n");
1418 fprintf (stderr, " yymsg_alloc = %d\n", yymsg_alloc);
1419 fprintf (stderr, " YYSTACK_ALLOC_MAXIMUM = %d\n",
1420 YYSTACK_ALLOC_MAXIMUM);
1421 fprintf (stderr, " YYSIZE_MAXIMUM = %d\n", YYSIZE_MAXIMUM);
1429 "123456789112345678921234567893123456789412345678951234567896123A"
1430 | "123456789112345678921234567893123456789412345678951234567896123B"
1431 | "123456789112345678921234567893123456789412345678951234567896123C"
1432 | "123456789112345678921234567893123456789412345678951234567896123D"
1433 | "123456789112345678921234567893123456789412345678951234567896123E"
1439 yyerror (char const *msg)
1441 fprintf (stderr, "%s\n", msg);
1447 /* Induce two syntax error messages (which requires full error
1448 recovery by shifting 3 tokens). */
1449 static char const *input = "abc";
1456 /* Push parsers throw away the message buffer between tokens, so skip
1457 this test under maintainer-push-check. */
1464 AT_BISON_CHECK([[-o input.c input.y]])
1466 # gcc warns about tautologies and fallacies involving comparisons for
1467 # unsigned char. However, it doesn't produce these same warnings for
1468 # size_t and many other types when the warnings would seem to make just
1469 # as much sense. We ignore the warnings.
1470 [CFLAGS="$NO_WERROR_CFLAGS"]
1471 AT_COMPILE([[input]])
1473 AT_PARSER_CHECK([[./input]], [[2]], [],
1474 [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B or 123456789112345678921234567893123456789412345678951234567896123C