1 # Executing Actions. -*- Autotest -*-
3 # Copyright (C) 2002, 2004-2005, 2007, 2009-2015, 2018-2019 Free
4 # Software Foundation, Inc.
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([[Sync Lines.]])
22 # _AT_SYNCLINES_COMPILE(FILE)
23 # ---------------------------
24 # Compile FILE expecting an error, and save in the file stdout the
25 # normalized output. Ignore the exit status, since some compilers
26 # (e.g. c89 on IRIX 6.5) trigger warnings on '#error', instead of
28 m4_define([_AT_SYNCLINES_COMPILE],
29 [AT_CHECK([$CC $CFLAGS $CPPFLAGS -c $1], [ignore], [], [stderr])
31 # Transform the file 'stderr' into something like this:
33 # input.y:4: #error "4"
35 # In case GCC displays column information, strip it down.
37 # input.y:4:2: #error "4" or
38 # input.y:4.2: #error "4" or
39 # input.y:4:2: error: #error "4"
41 # input.y:4: #error "4"
43 # It may also issue more context information:
45 # input.y: In function 'yyparse':
46 # input.y:8: #error "8"
48 # input.y:4: #error "8"
50 # The message may include a caret-error (indented by GCC 4.8,
53 # input.y:1:2: error: #error "1"
57 # Possibly distcc adds its bits.
59 # distcc[33187] ERROR: compile (null) on localhost failed
60 # syncline.c:1:2: error: #error "1"
61 # distcc[33185] ERROR: compile syncline.c on localhost failed
65 # distcc[35882] (dcc_connect_by_name) ERROR: failed to look up host "chrisimac": Unknown host
66 # distcc[35882] Warning: failed to distribute input.c to chrisimac/4, running locally instead
68 # The compiler might end by the number of messages issued (Clang 3.2):
70 # syncline.c:1:2: error: "1"
75 # When c++ is used to compiler C, we might have more messages (Clang 3.2):
77 # clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
80 # xlc reports things like:
82 # "input.yy", line 80.21: 1540-0218 (S) The call does not match any parameter list for "operator<<".
83 # "/usr/vacpp/include/iosfwd", line 32.6: 1506-205 (S) #error This file to be used only with IBM VisualAge C++ v4 and later compilers
85 # Newer GCCs go further and if the function is declared static, complain
88 # GCC 7 also underlines the error.
90 # syncline.c:4:2: error: #error "4"
94 # GCC 9 displays a left-hand margin with the line number:
96 # syncline.c: In function 'foo':
97 # syncline.c:4:2: error: #error "4"
100 AT_CHECK([["$PERL" -p -0777 - stderr <<\EOF || exit 77
101 # Remove left-hand margin.
104 # 1. Remove useless lines.
107 s/^distcc\[\d+\] .*\n//gm;
109 s/^clang: warning: treating 'c' input as 'c\+\+'.*\n//gm;
111 s/^[^:]*: In function '[^']+':\n//gm;
112 # Caret error (with possible '~' to underline).
113 s/^ *#error.*\n *\^~*\n//gm;
115 s/^1 error generated\.\n//gm;
117 # 2. Normalize the lines we kept.
119 # xlc messages. Remove also error identifier (e.g., "1540-0218 (S)").
120 s/^"(.*?)", line ([\w.]*): \d+-\d+ \(.\) /$][1:$][2: /gm;
122 s/^([^:]+:\d+)[.:][^:]+:(.+)$/$][1:$][2/gm;
123 # Map all combinations of "error: " and "#error: " to "#error ".
124 s/^([^:]+:\d+):( |#error|error|:)+/$][1: #error /gm;
132 # AT_SYNCLINES_COMPILE(FILE)
133 # --------------------------
134 # Compile FILE expecting an error, and save in the file 'stdout' the
135 # normalized output. If we can't get a trustable location
136 # from the compiler, just skip the test.
138 # It seems impossible to find a generic scheme to check the location
139 # of an error. Even requiring GCC is not sufficient, since for instance
140 # the version modified by Apple:
142 # | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
143 # | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
144 # | 19991024 (release) configure:2124: $? = 0
148 # | input.y:2: #error "2"
153 # | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
154 m4_define([AT_SYNCLINES_COMPILE],
155 [# Check if we can trust location translation.
156 AT_DATA([syncline.c],
164 _AT_SYNCLINES_COMPILE([syncline.c])
165 AT_REQUIRE([[test "`cat stdout`" = 'syncline.c:4: @%:@error "4"']])
167 # Then work for real.
168 _AT_SYNCLINES_COMPILE([$1])
172 # AT_TEST(TITLE, INPUT, ERROR-MSG)
173 # --------------------------------
174 # Check that compiling the parser produced from INPUT cause GCC
175 # to issue ERROR-MSG.
176 m4_pushdef([AT_TEST],
178 AT_BISON_OPTION_PUSHDEFS
180 AT_DATA([[input.y]], [$2])
181 AT_BISON_CHECK([-o input.c input.y])
182 AT_SYNCLINES_COMPILE([input.c])
183 AT_CHECK([cat stdout], 0, [$3])
184 AT_BISON_OPTION_POPDEFS
189 ## ------------------- ##
190 ## Prologue syncline. ##
191 ## ------------------- ##
194 AT_TEST([Prologue syncline],
199 ]AT_YYERROR_DECLARE_EXTERN[
200 ]AT_YYLEX_DECLARE_EXTERN[
206 [input.y:2: #error "2"
210 ## ----------------- ##
211 ## %union syncline. ##
212 ## ----------------- ##
214 AT_TEST([%union syncline],
220 ]AT_YYERROR_DECLARE_EXTERN[
221 ]AT_YYLEX_DECLARE_EXTERN[
227 [input.y:2: #error "2"
231 ## ---------------------- ##
232 ## %union name syncline. ##
233 ## ---------------------- ##
235 # Check that invalid union names are properly reported in the
237 AT_SETUP([%union name syncline])
238 AT_BISON_OPTION_PUSHDEFS
245 ]AT_YYERROR_DECLARE_EXTERN[
246 ]AT_YYLEX_DECLARE_EXTERN[
253 AT_BISON_CHECK([-o input.c input.y])
254 AT_SYNCLINES_COMPILE([input.c])
255 AT_CHECK([[grep '^input.y:1' stdout]], 0, [ignore])
256 AT_BISON_OPTION_POPDEFS
260 ## ----------------------- ##
261 ## Postprologue syncline. ##
262 ## ----------------------- ##
264 AT_TEST([Postprologue syncline],
266 ]AT_YYERROR_DECLARE_EXTERN[
267 ]AT_YYLEX_DECLARE_EXTERN[
283 [input.y:13: #error "13"
287 ## ----------------- ##
288 ## Action syncline. ##
289 ## ----------------- ##
291 AT_TEST([Action syncline],
293 ]AT_YYERROR_DECLARE_EXTERN[
294 ]AT_YYLEX_DECLARE_EXTERN[
302 [input.y:8: #error "8"
306 ## ------------------- ##
307 ## Epilogue syncline. ##
308 ## ------------------- ##
310 AT_TEST([Epilogue syncline],
312 ]AT_YYERROR_DECLARE_EXTERN[
313 ]AT_YYLEX_DECLARE_EXTERN[
320 [input.y:8: #error "8"
323 ## -------------------- ##
324 ## %code top syncline. ##
325 ## -------------------- ##
327 AT_TEST([%code top syncline],
332 ]AT_YYERROR_DECLARE_EXTERN[
333 ]AT_YYLEX_DECLARE_EXTERN[
339 [input.y:2: #error "2"
342 ## ---------------------- ##
343 ## %destructor syncline. ##
344 ## ---------------------- ##
346 AT_TEST([%destructor syncline],
351 ]AT_YYERROR_DECLARE_EXTERN[
352 ]AT_YYLEX_DECLARE_EXTERN[
359 exp: '0' { $$ = 0; };
362 [input.y:2: #error "2"
366 ## ------------------- ##
367 ## %printer syncline. ##
368 ## ------------------- ##
370 AT_TEST([%printer syncline],
376 ]AT_YYERROR_DECLARE_EXTERN[
377 ]AT_YYLEX_DECLARE_EXTERN[
384 exp: '0' { $$ = 0; };
387 [input.y:2: #error "2"
394 ## ------------------ ##
395 ## syncline escapes. ##
396 ## ------------------ ##
398 # AT_TEST([SKELETON])
399 # -------------------
400 m4_pushdef([AT_TEST],
401 [AT_SETUP([syncline escapes: $1])
403 AT_BISON_OPTION_PUSHDEFS([%skeleton "$1"])
405 # ICC is unable to handle these file names: it fails to pass them
406 # properly to the linker, and is unable to save a file named this way.
407 # Don't try with such compilers.
408 AT_DATA([\"\\\"\".AT_LANG_EXT],
409 [[int main (void) { return 0; }
412 AT_REQUIRE([AT_CXX_IF([$CXX $CXXFLAGS], [$CC $CFLAGS]) $CPPFLAGS \"\\\"\".]AT_LANG_EXT[ -o \"\\\"\"],
413 [0], [ignore], [ignore])
415 AT_DATA_GRAMMAR([\"\\\"\".y],
431 # Maybe we tried to create a file name that the file system does not
433 AT_SKIP_IF([[test ! -f \"\\\"\".y]])
434 AT_FULL_COMPILE([\"\\\"\"])
435 AT_BISON_OPTION_POPDEFS
440 m4_map_args([AT_TEST], [yacc.c], [glr.c], [lalr1.cc], [glr.cc])
450 # AT_TEST([SKELETON])
451 # -------------------
452 m4_pushdef([AT_TEST],
453 [AT_SETUP([%no-lines: $1])
455 AT_BISON_OPTION_PUSHDEFS([%skeleton "$1" %defines])
456 AT_DATA_GRAMMAR([input.y],
457 [[%skeleton "$1" %defines
459 ]AT_YYERROR_DECLARE_EXTERN[
460 ]AT_YYLEX_DECLARE_EXTERN[
469 # Generate without.* without the #line. Don't use -o without.c which
470 # would change the content (e.g., CPP guard depend on the output file
472 AT_BISON_CHECK([--no-lines -o input.AT_LANG_EXT -d input.y])
473 AT_CHECK([mv input.]AT_LANG_EXT[ without.]AT_LANG_EXT[])
474 AT_CHECK([mv input.]AT_LANG_HDR[ without.]AT_LANG_HDR[])
475 # There is no #line at all.
476 AT_CHECK([grep '#line' *.]AT_LANG_EXT[ *.]AT_LANG_HDR[], 1)
478 # Generate with.* without the #line.
479 AT_BISON_CHECK([-o input.AT_LANG_EXT -d input.y])
480 AT_CHECK([mv input.]AT_LANG_EXT[ with.]AT_LANG_EXT[])
481 AT_CHECK([mv input.]AT_LANG_HDR[ with.]AT_LANG_HDR[])
483 # The implementation file with --no-line is exactly the
484 # original one with #lines removed.
485 AT_CHECK([grep -v '#line' with.]AT_LANG_EXT[ >expout])
486 AT_CHECK([cat without.AT_LANG_EXT], 0, [expout])
488 # Likewise for the header.
489 AT_CHECK([grep -v '#line' with.]AT_LANG_HDR[ >expout])
490 AT_CHECK([cat without.AT_LANG_HDR], 0, [expout])
492 AT_BISON_OPTION_POPDEFS
497 m4_map_args([AT_TEST], [yacc.c], [glr.c], [lalr1.cc], [glr.cc])
503 ## ---------------- ##
504 ## Output columns. ##
505 ## ---------------- ##
507 AT_SETUP([Output columns])
509 # This test is fragile: its point is to check the compiler's error
510 # message, but it seems too hard to do portability (even between
511 # version of GCC). So instead, let's just check the generated code
514 AT_BISON_OPTION_PUSHDEFS
517 ]AT_YYERROR_DECLARE_EXTERN[
518 ]AT_YYLEX_DECLARE_EXTERN[
520 %define api.value.type union
522 %destructor { /* --BEGIN */
525 %printer { /* --BEGIN */
533 exp: exp '+' exp { /* --BEGIN */
540 AT_BISON_CHECK([-o input.c input.y])
541 AT_CHECK([[sed -ne '/--BEGIN/,/--END/{' \
542 -e '/input.c/s/ [0-9]* / LINE /;' \
558 (yyval.exp) = (yyvsp[-2].exp) + (yyvsp[0].exp);
559 (yyloc) = (yylsp[-2]) + (yylsp[0]);
563 AT_BISON_OPTION_POPDEFS