gcc/libcpp
Jakub Jelinek ac16f4327f libcpp: Fix up -fdirectives-only preprocessing [PR98882]
GCC 11 ICEs on all -fdirectives-only preprocessing when the files don't end
with a newline.

The problem is in the assertion, for empty TUs buffer->cur == buffer->rlimit
and so buffer->rlimit[-1] access triggers UB in the preprocessor, for
non-empty TUs it refers to the last character in the file, which can be
anything.
The preprocessor adds a '\n' character (or '\r', in particular if the
user file ends with '\r' then it adds another '\r' rather than '\n'), but
that is added after the limit, i.e. at buffer->rlimit[0].

Now, if the routine handles occassional bumping of pos to buffer->rlimit + 1,
I think it is just the assert that needs changing, usually we read from *pos
if pos < limit and then e.g. if it is '\r', look at the following character
(which could be one of those '\n' or '\r' at buffer->rlimit[0]).  There is
also the case where for '\\' before the limit we read following character
and if it is '\n', do one thing, if it is '\r' read another character.
But in that case if '\\' was the last char in the TU, the limit char will be
'\n', so we are ok.

2021-02-03  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/98882
	* lex.c (cpp_directive_only_process): Don't assert that rlimit[-1]
	is a newline, instead assert that rlimit[0] is either newline or
	carriage return.  When seeing '\\' followed by '\r', check limit
	before accessing pos[1].

	* gcc.dg/cpp/pr98882.c: New test.
2021-02-03 23:18:05 +01:00
..
include c++: Implement C++23 P0330 - Literal Suffixes for ptrdiff_t and size_t. 2021-02-03 12:12:31 -05:00
po Daily bump. 2021-01-08 00:16:23 +00:00
aclocal.m4 libcpp: Enable Intel CET on Intel CET enabled host for jit 2020-05-12 09:17:45 -07:00
ChangeLog Daily bump. 2021-01-28 00:16:56 +00:00
ChangeLog.jit
charset.c Update copyright years. 2021-01-04 10:26:59 +01:00
config.in
configure Require CET support only for the final GCC build 2020-07-30 05:36:24 -07:00
configure.ac libcpp, libdecnumber: configure and substitute AR 2020-05-23 21:59:02 +00:00
directives.c Update copyright years. 2021-01-04 10:26:59 +01:00
errors.c Update copyright years. 2021-01-04 10:26:59 +01:00
expr.c c++: Implement C++23 P0330 - Literal Suffixes for ptrdiff_t and size_t. 2021-02-03 12:12:31 -05:00
files.c Update copyright years. 2021-01-04 10:26:59 +01:00
generated_cpp_wcwidth.h libcpp: Update cpp_wcwidth() to Unicode 13.0.0 2020-11-07 09:36:43 -05:00
identifiers.c Update copyright years. 2021-01-04 10:26:59 +01:00
init.c c++: Implement C++23 P0330 - Literal Suffixes for ptrdiff_t and size_t. 2021-02-03 12:12:31 -05:00
internal.h Update copyright years. 2021-01-04 10:26:59 +01:00
lex.c libcpp: Fix up -fdirectives-only preprocessing [PR98882] 2021-02-03 23:18:05 +01:00
line-map.c Update copyright years. 2021-01-04 10:26:59 +01:00
location-example.txt
macro.c Update copyright years. 2021-01-04 10:26:59 +01:00
Makefile.in Update copyright years. 2021-01-04 10:26:59 +01:00
makeucnid.c Update copyright years. 2021-01-04 10:26:59 +01: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 Update copyright years. 2021-01-04 10:26:59 +01:00
traditional.c Update copyright years. 2021-01-04 10:26:59 +01:00
ucnid.h Update copyright years. 2021-01-04 10:26:59 +01:00
ucnid.tab Update copyright years. 2021-01-04 10:26:59 +01:00