gcc/libcpp
Jakub Jelinek 55dfce4d5c libcpp: Fix up handling of deferred pragmas [PR102432]
The https://gcc.gnu.org/pipermail/gcc-patches/2020-November/557903.html
change broke the following testcases.  The problem is when a pragma
namespace allows expansion (i.e. p->is_nspace && p->allow_expansion),
e.g. the omp or acc namespaces do, then when parsing the second pragma
token we do it with pfile->state.in_directive set,
pfile->state.prevent_expansion clear and pfile->state.in_deferred_pragma
clear (the last one because we don't know yet if it will be a deferred
pragma or not).  If the pragma line only contains a single name
and newline after it, and there exists a function-like macro with the
same name, the preprocessor needs to peek in funlike_invocation_p
the next token whether it isn't ( but in this case it will see a newline.
As pfile->state.in_directive is set, we don't read anything after the
newline, pfile->buffer->need_line is set and CPP_EOF is lexed, which
funlike_invocation_p doesn't push back.  Because name is a function-like
macro and on the pragma line there is no ( after the name, it isn't
expanded, and control flow returns to do_pragma.  If name is valid
deferred pragma, we set pfile->state.in_deferred_pragma (and really
need it set so that e.g. end_directive later on doesn't eat all the
tokens from the pragma line).

Before Nathan's change (which unfortunately didn't contain rationale
on why it is better to do it like that), this wasn't a problem,
next _cpp_lex_direct called when we want next token would return
CPP_PRAGMA_EOF when it saw buffer->need_line, which would turn off
pfile->state.in_deferred_pragma and following get token would already
read the next line.  But Nathan's patch replaced it with an assertion
failure that now triggers and CPP_PRAGMA_EOL is done only when lexing
the '\n'.  Except for this special case that works fine, but in
this case it doesn't because when peeking the token we still didn't know
that it will be a deferred pragma.
I've tried to fix that up in do_pragma by detecting this and pushing
CPP_PRAGMA_EOL as lookahead, but that doesn't work because end_directive
still needs to see pfile->state.in_deferred_pragma set.

So, this patch affectively reverts part of Nathan's change, CPP_PRAGMA_EOL
addition isn't done only when parsing the '\n', but is now done in both
places, in the first one instead of the assertion failure.

2021-12-04  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/102432
	* lex.c (_cpp_lex_direct): If buffer->need_line while
	pfile->state.in_deferred_pragma, return CPP_PRAGMA_EOL token instead
	of assertion failure.

	* c-c++-common/gomp/pr102432.c: New test.
	* c-c++-common/goacc/pr102432.c: New test.
2021-12-04 11:00:09 +01:00
..
include pch: Add support for PCH for relocatable executables [PR71934] 2021-12-03 11:03:30 +01:00
po Daily bump. 2021-08-17 00:16:32 +00:00
ChangeLog Daily bump. 2021-12-04 00:16:46 +00:00
ChangeLog.jit
Makefile.in Make etags path used by build system configurable 2021-11-29 13:24:12 -05:00
aclocal.m4
charset.c libcpp: Enable P1949R7 for C++98 too [PR100977] 2021-12-01 10:21:20 +01:00
config.in
configure Make etags path used by build system configurable 2021-11-29 13:24:12 -05:00
configure.ac Make etags path used by build system configurable 2021-11-29 13:24:12 -05:00
directives.c libcpp: Fix _Pragma expansion [PR102409] 2021-10-29 22:55:32 +02:00
errors.c diagnostics: escape non-ASCII source bytes for certain diagnostics 2021-11-01 09:35:46 -04:00
expr.c preprocessor: Fix pp-number lexing of digit separators [PR83873, PR97604] 2021-05-06 23:20:35 +00:00
files.c diagnostics: Support for -finput-charset [PR93067] 2021-08-25 11:15:28 -04:00
generated_cpp_wcwidth.h
identifiers.c Update copyright years. 2021-01-04 10:26:59 +01:00
init.c libcpp: Enable P1949R7 for C++98 too [PR100977] 2021-12-01 10:21:20 +01:00
internal.h libcpp: Fix _Pragma stringification [PR103165] 2021-11-22 22:29:20 +01:00
lex.c libcpp: Fix up handling of deferred pragmas [PR102432] 2021-12-04 11:00:09 +01:00
line-map.c diagnostics: escape non-ASCII source bytes for certain diagnostics 2021-11-01 09:35:46 -04:00
location-example.txt
macro.c libcpp: Fix up #__VA_OPT__ handling [PR103415] 2021-12-01 10:07:59 +01:00
makeucnid.c libcpp: Implement C++23 P1949R7 - C++ Identifier Syntax using Unicode Standard Annex 31 2021-09-01 22:33:06 +02:00
mkdeps.c preprocessor: Make quoting : [PR 95253] 2021-01-15 08:56:20 -08:00
pch.c Update copyright years. 2021-01-04 10:26:59 +01:00
symtab.c Update copyright years. 2021-01-04 10:26:59 +01:00
system.h libcpp: Fix ATTR_LIKELY definition PR preprocessor/103355 2021-11-23 16:06:42 +00:00
traditional.c Update copyright years. 2021-01-04 10:26:59 +01:00
ucnid.h libcpp: Implement C++23 P1949R7 - C++ Identifier Syntax using Unicode Standard Annex 31 2021-09-01 22:33:06 +02:00
ucnid.tab Update copyright years. 2021-01-04 10:26:59 +01:00