From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by sourceware.org (Postfix) with ESMTPS id 486FA385828B for ; Fri, 4 Nov 2022 13:44:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 486FA385828B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qt1-x830.google.com with SMTP id l15so3026654qtv.4 for ; Fri, 04 Nov 2022 06:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=laMRoAiupSiOC8PN/0h2ma2LY5xFfsQzbcKZMWMjeaw=; b=EhU8a6qsVvwRcwg/DleNIHY53rSq9Brr8nQRVLT3C4b2n10hDH8XrVfZkFiZgv05Ha NWiWb16r+UcHRXZuFVq6bhf+dmR/UwN5yUAEMur1ToiCv9Hlbf3chdAaqcrclb8WR6Sc rc5VpXmRFhUft4X+3MrxPS1SCjYMznV/rZHyL+C+R8zeU2tyxXBf5p6rmMkCfmbZCcQ+ xMGlRD6XOJFUtf07ks5a9yvATg1t6FEOFe7PF+TpngZ6Joi5hpZHwDXNkIOMEG+Ie6yK VA5Y9kcMSbwombau9Cc4+f9bi6vRAZpzfj8tCogGg/5W0HrN2IkFqtODwZdaNJoSlSde Qb5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=laMRoAiupSiOC8PN/0h2ma2LY5xFfsQzbcKZMWMjeaw=; b=vc4wLlnh5eqiFFLFpasRICNSHtYUM5HXXQmzN0HavrLiNjDmbboGxVabfZoVJYm167 puwXrV2Rb0u4+4LvANFGkTX/KC9qGqHR1jmfqRVpTBBTTI85O+VQiMPyofx+8y/EccgV Go0qHKwdt9WCZhWC1FcSKb9jKPZywjjHvUC4Ja/2Fr0fAe7aCt30PAGCaIcwrZlJv4n3 SrVczn56OILKnQLMWPGy10XDYW8S2/udgJ3kTB1wHHTZVcTlV9HYWIF3TMOX7nedsE/3 ARCJ1Cw1bKytD1gYEbLm5f+nJLzRmNbGeL4SABVV9bN3NPAfdZYItLEPNiz4nGEH/yYQ xQJQ== X-Gm-Message-State: ACrzQf3xGTPV1bn58baKM7ZWgaw5S3qUO2UcmUbSpAktyG2/5a0Sq8lp CxAhtRJX6+AKe1YJcTw9bGEjVvoycUA= X-Google-Smtp-Source: AMsMyM4eCAfIhaVCSMtpTaKa6EegsXJiSwEAz14bhUYwEZ2dMhlS+NY/9inPG0K7tnRTFfSqLfGHTg== X-Received: by 2002:ac8:4256:0:b0:3a4:fd1c:a5ca with SMTP id r22-20020ac84256000000b003a4fd1ca5camr29355409qtm.77.1667569481573; Fri, 04 Nov 2022 06:44:41 -0700 (PDT) Received: from localhost.localdomain (96-67-140-173-static.hfc.comcastbusiness.net. [96.67.140.173]) by smtp.gmail.com with ESMTPSA id ey21-20020a05622a4c1500b003988b3d5280sm2470577qtb.70.2022.11.04.06.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:44:41 -0700 (PDT) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 1/6] diagnostics: Fix macro tracking for ad-hoc locations Date: Fri, 4 Nov 2022 09:44:09 -0400 Message-Id: <44cead99227a4bbb93860813c168163999b8d164.1667514153.git.lhyatt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3038.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. --- gcc/testsuite/c-c++-common/cpp/macro-trace-1.c | 4 ++++ gcc/tree-diagnostic.cc | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/cpp/macro-trace-1.c 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,