From patchwork Fri Nov 4 13:44:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 1699546 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=yBRXDPeK; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N3hhP58Jwz1yqS for ; Sat, 5 Nov 2022 00:45:09 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 43EB13858025 for ; Fri, 4 Nov 2022 13:45:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43EB13858025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667569507; bh=laMRoAiupSiOC8PN/0h2ma2LY5xFfsQzbcKZMWMjeaw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=yBRXDPeKcEnLGT9f+l6ce5CHnfw1HyfzlZr0feoM+Y3PlztrjGwU/7x2+41YJd56/ 8vBLs7M5tlFdCIPuLlPAq0dG+u+Gw0fONGKDYdP57OLSDfeWpBmmI+IqIw0CE/tpb4 7wmXHxrrJV4mdovP9sArz9OADeya3j8XzB3UTpOY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 Received: by mail-qt1-x830.google.com with SMTP id l15so3026654qtv.4 for ; Fri, 04 Nov 2022 06:44:42 -0700 (PDT) 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) To: gcc-patches@gcc.gnu.org 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Lewis Hyatt via Gcc-patches From: Lewis Hyatt Reply-To: Lewis Hyatt Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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,