public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8583] libcpp: location comparison within macro [PR100796] Date: Wed, 16 Jun 2021 18:33:49 +0000 (GMT) [thread overview] Message-ID: <20210616183349.560AB396C82F@sourceware.org> (raw) https://gcc.gnu.org/g:bb2e908638758097e261bca1a4825d171a18af9c commit r11-8583-gbb2e908638758097e261bca1a4825d171a18af9c Author: Jason Merrill <jason@redhat.com> Date: Mon Jun 14 17:37:43 2021 -0400 libcpp: location comparison within macro [PR100796] The patch for 96391 changed linemap_compare_locations to give up on comparing locations from macro expansions if we don't have column information. But in this testcase, the BOILERPLATE macro is multiple lines long, so we do want to compare locations within the macro. So this patch moves the LINE_MAP_MAX_LOCATION_WITH_COLS check inside the block, to use it for failing gracefully. PR c++/100796 PR preprocessor/96391 libcpp/ChangeLog: * line-map.c (linemap_compare_locations): Only use comparison with LINE_MAP_MAX_LOCATION_WITH_COLS to avoid abort. gcc/testsuite/ChangeLog: * g++.dg/plugin/location-overflow-test-pr100796.c: New test. * g++.dg/plugin/plugin.exp: Run it. Diff: --- .../plugin/location-overflow-test-pr100796.c | 25 ++++++++++++++++++++++ libcpp/line-map.c | 20 +++++++++-------- gcc/testsuite/g++.dg/plugin/plugin.exp | 3 ++- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/gcc/testsuite/g++.dg/plugin/location-overflow-test-pr100796.c b/gcc/testsuite/g++.dg/plugin/location-overflow-test-pr100796.c new file mode 100644 index 00000000000..7fa964c07e5 --- /dev/null +++ b/gcc/testsuite/g++.dg/plugin/location-overflow-test-pr100796.c @@ -0,0 +1,25 @@ +// PR c++/100796 +// { dg-additional-options "-Wsuggest-override -fplugin-arg-location_overflow_plugin-value=0x60000001" } +// Passing LINE_MAP_MAX_LOCATION_WITH_COLS meant we stopped distinguishing between lines in a macro. + +#define DO_PRAGMA(text) _Pragma(#text) +#define WARNING_PUSH DO_PRAGMA(GCC diagnostic push) +#define WARNING_POP DO_PRAGMA(GCC diagnostic pop) +#define WARNING_DISABLE(text) DO_PRAGMA(GCC diagnostic ignored text) +#define NO_OVERRIDE_WARNING WARNING_DISABLE("-Wsuggest-override") + +#define BOILERPLATE \ + WARNING_PUSH \ + NO_OVERRIDE_WARNING \ + void f(); \ + WARNING_POP + +struct B +{ + virtual void f(); +}; + +struct D: B +{ + BOILERPLATE +}; diff --git a/libcpp/line-map.c b/libcpp/line-map.c index a03d6760a8e..1a6902acdb7 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -1421,23 +1421,25 @@ linemap_compare_locations (line_maps *set, if (l0 == l1 && pre_virtual_p - && post_virtual_p - && l0 <= LINE_MAP_MAX_LOCATION_WITH_COLS) + && post_virtual_p) { /* So pre and post represent two tokens that are present in a same macro expansion. Let's see if the token for pre was before the token for post in that expansion. */ - unsigned i0, i1; const struct line_map *map = first_map_in_common (set, pre, post, &l0, &l1); if (map == NULL) - /* This should not be possible. */ - abort (); - - i0 = l0 - MAP_START_LOCATION (map); - i1 = l1 - MAP_START_LOCATION (map); - return i1 - i0; + /* This should not be possible while we have column information, but if + we don't, the tokens could be from separate macro expansions on the + same line. */ + gcc_assert (l0 > LINE_MAP_MAX_LOCATION_WITH_COLS); + else + { + unsigned i0 = l0 - MAP_START_LOCATION (map); + unsigned i1 = l1 - MAP_START_LOCATION (map); + return i1 - i0; + } } if (IS_ADHOC_LOC (l0)) diff --git a/gcc/testsuite/g++.dg/plugin/plugin.exp b/gcc/testsuite/g++.dg/plugin/plugin.exp index 5cd4b4bff90..74e12df207c 100644 --- a/gcc/testsuite/g++.dg/plugin/plugin.exp +++ b/gcc/testsuite/g++.dg/plugin/plugin.exp @@ -73,7 +73,8 @@ set plugin_test_list [list \ ../../gcc.dg/plugin/diagnostic-test-string-literals-3.c \ ../../gcc.dg/plugin/diagnostic-test-string-literals-4.c } \ { ../../gcc.dg/plugin/location_overflow_plugin.c \ - location-overflow-test-pr96391.c } \ + location-overflow-test-pr96391.c \ + location-overflow-test-pr100796.c } \ { show_template_tree_color_plugin.c \ show-template-tree-color.C \ show-template-tree-color-labels.C \
reply other threads:[~2021-06-16 18:33 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210616183349.560AB396C82F@sourceware.org \ --to=jason@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).