diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-02-01 20:42:49 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-02-01 20:42:49 +0100 |
commit | efc46b550f035281e51c340f73fbc9a79655e852 (patch) | |
tree | db24d6e1e8d6050bd61ba5f68a2d9474a201edaa /libcpp | |
parent | fa882c3e3bf642e0ef30772e4b54a2851497db96 (diff) | |
download | gcc-efc46b550f035281e51c340f73fbc9a79655e852.zip gcc-efc46b550f035281e51c340f73fbc9a79655e852.tar.gz gcc-efc46b550f035281e51c340f73fbc9a79655e852.tar.bz2 |
libcpp: Avoid PREV_WHITE and other random content on CPP_PADDING tokens
The funlike_invocation_p macro never triggered, the other
asserts did on some tests, see below for a full list.
This seems to be caused by #pragma/_Pragma handling.
do_pragma does:
pfile->directive_result.src_loc = pragma_token_virt_loc;
pfile->directive_result.type = CPP_PRAGMA;
pfile->directive_result.flags = pragma_token->flags;
pfile->directive_result.val.pragma = p->u.ident;
when it sees a pragma, while start_directive does:
pfile->directive_result.type = CPP_PADDING;
and so does _cpp_do__Pragma.
Now, for #pragma lex.cc will just ignore directive_result if
it has CPP_PADDING type:
if (_cpp_handle_directive (pfile, result->flags & PREV_WHITE))
{
if (pfile->directive_result.type == CPP_PADDING)
continue;
result = &pfile->directive_result;
}
but destringize_and_run does not:
if (pfile->directive_result.type == CPP_PRAGMA)
{
...
}
else
{
count = 1;
toks = XNEW (cpp_token);
toks[0] = pfile->directive_result;
and from there it will copy type member of CPP_PADDING, but all the
other members from the last CPP_PRAGMA before it.
Small testcase for it with no option (at least no -fopenmp or -fopenmp-simd).
#pragma GCC push_options
#pragma GCC ignored "-Wformat"
#pragma GCC pop_options
void
foo ()
{
_Pragma ("omp simd")
for (int i = 0; i < 64; i++)
;
}
Here is a patch that replaces those
toks = XNEW (cpp_token);
toks[0] = pfile->directive_result;
lines with
toks = &pfile->avoid_paste;
2022-02-01 Jakub Jelinek <jakub@redhat.com>
* directives.cc (destringize_and_run): Push &pfile->avoid_paste
instead of a copy of pfile->directive_result for the CPP_PADDING
case.
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/directives.cc | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/libcpp/directives.cc b/libcpp/directives.cc index 60fd274..f804a44 100644 --- a/libcpp/directives.cc +++ b/libcpp/directives.cc @@ -1954,8 +1954,7 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in, else { count = 1; - toks = XNEW (cpp_token); - toks[0] = pfile->directive_result; + toks = &pfile->avoid_paste; /* If we handled the entire pragma internally, make sure we get the line number correct for the next token. */ |