]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Fix location for _Pragma tokens [PR97498]
authorLewis Hyatt <lhyatt@gmail.com>
Sat, 9 Jul 2022 20:12:21 +0000 (16:12 -0400)
committerLewis Hyatt <lhyatt@gmail.com>
Mon, 1 Aug 2022 17:38:24 +0000 (13:38 -0400)
commit98e2676558f6f50cfb90610e5a160642a24d1596
tree9711911c4058a941eac823cabfea90524c3e0396
parentd2bafe190c230fc0aeab1ac961bf7ae9f8b5b19f
c: Fix location for _Pragma tokens [PR97498]

The handling of #pragma GCC diagnostic uses input_location, which is not always
as precise as needed; in particular the relative location of some tokens and a
_Pragma directive will crucially determine whether a given diagnostic is enabled
or suppressed in the desired way. PR97498 shows how the C frontend ends up with
input_location pointing to the beginning of the line containing a _Pragma()
directive, resulting in the wrong behavior if the diagnostic to be modified
pertains to some tokens found earlier on the same line. This patch fixes that by
addressing two issues:

    a) libcpp was not assigning a valid location to the CPP_PRAGMA token
    generated by the _Pragma directive.
    b) C frontend was not setting input_location to something reasonable.

With this change, the C frontend is able to change input_location to point to
the _Pragma token as needed.

This is just a two-line fix (one for each of a) and b)), the testsuite changes
were needed only because the location on the tested warnings has been somewhat
improved, so the tests need to look for the new locations.

gcc/c/ChangeLog:

PR preprocessor/97498
* c-parser.cc (c_parser_pragma): Set input_location to the
location of the pragma, rather than the start of the line.

libcpp/ChangeLog:

PR preprocessor/97498
* directives.cc (destringize_and_run): Override the location of
the CPP_PRAGMA token from a _Pragma directive to the location of
the expansion point, as is done for the tokens lexed from it.

gcc/testsuite/ChangeLog:

PR preprocessor/97498
* c-c++-common/pr97498.c: New test.
* c-c++-common/gomp/pragma-3.c: Adapt for improved warning locations.
* c-c++-common/gomp/pragma-5.c: Likewise.
* gcc.dg/pragma-message.c: Likewise.

libgomp/ChangeLog:

* testsuite/libgomp.oacc-c-c++-common/reduction-5.c: Adapt for
improved warning locations.
* testsuite/libgomp.oacc-c-c++-common/vred2d-128.c: Likewise.

(cherry picked from commit 0587cef3d7962a8b0f44779589ba2920dd3d71e5)
gcc/c/c-parser.cc
gcc/testsuite/c-c++-common/gomp/pragma-3.c
gcc/testsuite/c-c++-common/gomp/pragma-5.c
gcc/testsuite/c-c++-common/pr97498.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pragma-message.c
libcpp/directives.cc
libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-5.c
libgomp/testsuite/libgomp.oacc-c-c++-common/vred2d-128.c