From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2108) id 85AE4389EC59; Tue, 15 Nov 2022 16:22:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 85AE4389EC59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668529374; bh=bBf1+4V2868RO4X54ZVc1E47AN6RGeJymzi0346r8Mo=; h=From:To:Subject:Date:From; b=vFswukURB5WJhxq3Xzi2m9vnL+kJO/D03Tt97B43lL6mOaxCxnJ/hlF9ljrgul6mc C3xiYfjLV0N188RIDrrYDSI/kix6ux4AbWJlTXyrrmW+HWv6ZZYVyxSgVdIUTBBK/c CAVlM5RRQ7NzjBZkixqrgwmxvdwy5R+3Oeea/2R0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Lewis Hyatt To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4069] diagnostics: Fix macro tracking for ad-hoc locations X-Act-Checkin: gcc X-Git-Author: Lewis Hyatt X-Git-Refname: refs/heads/master X-Git-Oldrev: 3037f11fb86eda234a27ab26748958f71a805005 X-Git-Newrev: 6238cc20f0e588f272569230b33458fedf755ab2 Message-Id: <20221115162254.85AE4389EC59@sourceware.org> Date: Tue, 15 Nov 2022 16:22:54 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6238cc20f0e588f272569230b33458fedf755ab2 commit r13-4069-g6238cc20f0e588f272569230b33458fedf755ab2 Author: Lewis Hyatt Date: Tue Nov 1 17:50:27 2022 -0400 diagnostics: Fix macro tracking for ad-hoc locations The result of linemap_resolve_location() can be an ad-hoc location, if that is what was stored in a relevant macro map. maybe_unwind_expanded_macro_loc() did not previously handle this case, causing it to print the wrong tracking information for an example such as the new testcase macro-trace-1.c. Fix that by checking for ad-hoc locations where needed. gcc/ChangeLog: * tree-diagnostic.cc (maybe_unwind_expanded_macro_loc): Handle ad-hoc location in return value of linemap_resolve_location(). gcc/testsuite/ChangeLog: * c-c++-common/cpp/macro-trace-1.c: New test. Diff: --- gcc/testsuite/c-c++-common/cpp/macro-trace-1.c | 4 ++++ gcc/tree-diagnostic.cc | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/c-c++-common/cpp/macro-trace-1.c b/gcc/testsuite/c-c++-common/cpp/macro-trace-1.c new file mode 100644 index 00000000000..34cfbb3dad3 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/macro-trace-1.c @@ -0,0 +1,4 @@ +/* This token is long enough to require an ad-hoc location. Make sure that + the macro trace still prints properly. */ +#define X "0123456789012345678901234567689" /* { dg-error {expected .* before string constant} } */ +X /* { dg-note {in expansion of macro 'X'} } */ diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc index 0d79fe3c3c1..5cf3a1c17d2 100644 --- a/gcc/tree-diagnostic.cc +++ b/gcc/tree-diagnostic.cc @@ -190,14 +190,17 @@ maybe_unwind_expanded_macro_loc (diagnostic_context *context, location_t l = linemap_resolve_location (line_table, resolved_def_loc, LRK_SPELLING_LOCATION, &m); - if (l < RESERVED_LOCATION_COUNT || LINEMAP_SYSP (m)) + location_t l0 = l; + if (IS_ADHOC_LOC (l0)) + l0 = get_location_from_adhoc_loc (line_table, l0); + if (l0 < RESERVED_LOCATION_COUNT || LINEMAP_SYSP (m)) continue; /* We need to print the context of the macro definition only when the locus of the first displayed diagnostic (displayed before this trace) was inside the definition of the macro. */ - int resolved_def_loc_line = SOURCE_LINE (m, l); + const int resolved_def_loc_line = SOURCE_LINE (m, l0); if (ix == 0 && saved_location_line != resolved_def_loc_line) { diagnostic_append_note (context, resolved_def_loc,