diff options
author | Lewis Hyatt <lhyatt@gmail.com> | 2024-03-22 12:55:27 -0400 |
---|---|---|
committer | Lewis Hyatt <lhyatt@gcc.gnu.org> | 2024-10-19 19:25:39 -0400 |
commit | 65c5bbe1c92f9c08e99d3a37c136f2ef9804a37f (patch) | |
tree | db81dc45464d28b24ab77dddaf1d8ab1872847c0 /libcpp/internal.h | |
parent | 7fa9fd47f161d6b8177439ae2b46a2048a5eaa24 (diff) | |
download | gcc-65c5bbe1c92f9c08e99d3a37c136f2ef9804a37f.zip gcc-65c5bbe1c92f9c08e99d3a37c136f2ef9804a37f.tar.gz gcc-65c5bbe1c92f9c08e99d3a37c136f2ef9804a37f.tar.bz2 |
diagnostics: libcpp: Improve locations for _Pragma lexing diagnostics [PR114423]
libcpp is not currently set up to be able to generate valid
locations for tokens lexed from a _Pragma string. Instead, after obtaining
the tokens, it sets their locations all to the location of the _Pragma
operator itself. This makes things like _Pragma("GCC diagnostic") work well
enough, but if any diagnostics are issued during lexing, prior to resetting
the token locations, those diagnostics get issued at the invalid
locations. Fix that up by adding a new field pfile->diagnostic_override_loc
that instructs libcpp to issue diagnostics at the alternate location.
libcpp/ChangeLog:
PR preprocessor/114423
* internal.h (struct cpp_reader): Add DIAGNOSTIC_OVERRIDE_LOC
field.
* directives.cc (destringize_and_run): Set the new field to the
location of the _Pragma operator.
* errors.cc (cpp_diagnostic_at): Support DIAGNOSTIC_OVERRIDE_LOC to
temporarily issue diagnostics at a different location.
(cpp_diagnostic_with_line): Likewise.
gcc/testsuite/ChangeLog:
PR preprocessor/114423
* c-c++-common/cpp/pragma-diagnostic-loc.c: New test.
* c-c++-common/cpp/diagnostic-pragma-1.c: Adjust expected output.
* g++.dg/pch/operator-1.C: Likewise.
Diffstat (limited to 'libcpp/internal.h')
-rw-r--r-- | libcpp/internal.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/libcpp/internal.h b/libcpp/internal.h index a658a8c..13186c5 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -616,6 +616,10 @@ struct cpp_reader zero of said file. */ location_t main_loc; + /* If non-zero, override diagnostic locations (other than DK_NOTE + diagnostics) to this one. */ + location_t diagnostic_override_loc; + /* Returns true iff we should warn about UTF-8 bidirectional control characters. */ bool warn_bidi_p () const |