From 80db1029e67e5d42fa6329489558b114fdfea880 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 7 Aug 2021 09:30:24 +0200 Subject: m4: catch suspicions of unevaluated macros Check in m4's output if there are sequences such as m4_foo or b4_foo, which are probably resulting from incorrect m4 processing. It actually already is useful: - it caught a leaking b4_lac_if leaking from glr.c, where LAC is not supported, hence b4_lac_if is not defined. - it also caught references to location.hh in position.hh when location.hh does not exist. - while making "Code injection" robust to these new warnings (it is its very purpose to let b4_canary pass unevaluated), I saw that it did not check lalr1.d, and when adding lalr1.d, it revealed it did underquote ocurrences of token value types. * src/scan-skel.l (macro): New abbreviation. Use it. * data/skeletons/glr.c: Don't use b4_lac_if, we don't have it. * data/skeletons/location.cc: Don't generate position.hh when we don't generate location.hh. * data/skeletons/d.m4 (b4_basic_symbol_constructor_define): Fix underquotation. * data/skeletons/bison.m4 (b4_canary): New. * tests/input.at (Code injection): Use it, and check lalr1.d too. --- src/scan-skel.l | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/scan-skel.l b/src/scan-skel.l index 20049cfb..60232a2e 100644 --- a/src/scan-skel.l +++ b/src/scan-skel.l @@ -53,6 +53,9 @@ static void fail_for_invalid_at (char const *at); static void output_mapped_file (char const *name); %} +/* Identifiers of our M4 macros. */ +macro [bm]4_[a-zA-Z_0-9]* + %x SC_AT_DIRECTIVE_ARGS %x SC_AT_DIRECTIVE_SKIP_WS @@ -87,7 +90,21 @@ static void output_mapped_file (char const *name); /* This pattern must not match more than the previous @ patterns. */ @[^@{}''(\n]* fail_for_invalid_at (yytext); \n out_lineno++; ECHO; -[^@\n]+ ECHO; +[^bm@\n]+ ECHO; + + /* If there are still identifiers that look like macros, such as + b4_synbol, this probably an error, say a typo in M4, or + overquotation. */ +{macro} { + location loc = empty_loc; + loc.start.file = map_file_name (out_name); + loc.start.line = out_lineno; + loc.end = loc.start; + complain (&loc, Wother, + "suspicious sequence in the output: %s", yytext); + ECHO; + } +. ECHO; <> { if (out_name) -- cgit v1.2.1