From patchwork Tue Nov 21 22:20:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 168005 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp949829vqb; Tue, 21 Nov 2023 14:21:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHj03VCKtXrd+bCPiGh6iuimgbe1Y5kmAZB17vPQUpgDQbLrLeiI4y4mQhF5+zZZTKNSaOE X-Received: by 2002:a05:620a:2812:b0:77d:5751:51c8 with SMTP id f18-20020a05620a281200b0077d575151c8mr448508qkp.77.1700605272321; Tue, 21 Nov 2023 14:21:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700605272; cv=pass; d=google.com; s=arc-20160816; b=RBlfOIXtx9vCn9HAi9cmk3w9bhmSWoiPh7Ki7NFCGpp4utWewXEYNWlHsNJc6cwC0X Bs0wfxNBnenffbr9KhAdpTWwTdob0mZ3ZtA2OMTPIxjk+wymXMCQehuVCyJK2hC8iD88 EXXFsv0VThlpT5tjypwRqimP2ymfPZv3L4KbVxs7K3NqnZHK2+oV0YutgcAQNEZCOAem /QMQNH3zDWRKHvVIhes3ZTBUX0Be89xQnY9oPggwo2Iv9CMZ+OXYjs0xZ86NYYM4VcV/ kH/XG+95VSo+Czu1WemK4QC3PzyOUXo/Lg0Q9xyVqUMF8YP32e/HJE3+g/g4Nsdesisw LG6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=Uvvlossdf8boUbECl6hyDbubQLkAqPxICLA3Tz+TLPs=; fh=rfR2SIXf27jLXVYT4RHMSVZgLIsrp2E1IHKtUM1Ws70=; b=EjBb8ebDFRNq4jRwIVTuWRkAxu78ZJWOM2OF3b8ShxhRqYLCeDfFCAkrodz8aPibIX nmCfuaC4aP9VtdqKQFTYaZ7/qsnhy5n2P2NAfqWTNgq5YuCwwFdphjxA9p9LlLzF2X3d 5j6JgDlmctiq8rQSlKmpu+lGfx9Z5vMs94txxg9KRSf2c9u/phxEhXR05ebpEA1Zj/f8 x8Z4VxA7IA3TIjtnP/r/mORARRELtQ6oBSsf3amefz+zVqexTmZrMce9oCvz8wri3wGy lPdiN0AGEY4vKcV9uL1p2x4/2ebFAqY5xt9jl/erIBxyrEZWqjBb0VGC/cgT1bpOcj40 bYVA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b6NIsAYA; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i26-20020ae9ee1a000000b0076ceb5934f6si9645509qkg.64.2023.11.21.14.21.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 14:21:12 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b6NIsAYA; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DCBDE3857719 for ; Tue, 21 Nov 2023 22:20:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E2A3A38582B8 for ; Tue, 21 Nov 2023 22:20:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E2A3A38582B8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E2A3A38582B8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700605226; cv=none; b=nZ9EK1CU8ItPqrwfUV+/NG+41TnXehilqRuQaPFUN5TW4984LJoVEKMGd6YxHHEuuCffYoiiji48Ao3ZhP1oISrlzXFwmGOaRc8gmB6e4HvKfKsMqjC1jKTwkh/Ublf9TbHJWM1fxW06XFpwh1KlAp58Umh3duvahxJZqTK4v98= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700605226; c=relaxed/simple; bh=vRM4dvP9BEVRIESxsNrac/KBdtw0acKZ9BNr3A864Qc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=TIcrbdTWCqSqmGU6nBJ0dljRxTq63ad+CB+EkC9S5gioMOcdYFwAW9h+PSN87GTVv6ljE/vUyH8EVx9RWqX3dJFM7mX7JP0u7TbnN2n6RXr/KH3r2dqcihn7pIihAa+MqdLeQPPUfxDxo7V91h/fccUgGkjoATDIPV02FYkqNOg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700605224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Uvvlossdf8boUbECl6hyDbubQLkAqPxICLA3Tz+TLPs=; b=b6NIsAYApSo7cfa5RIyMFSVIkZTGWX4LoOPDrtzs155aKM4q+dAaDWIbxqHBfjeXu5hrJL /DvqDLdR95hpgYQgT/mdpYR98Xa9NYRc7QjTk1ZyQpDsWb6IHayQOMNb/sc2a+RvntTN1J Jo1hAsB8qzCyFPoeweawDIEUOEfICB0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-HVA08a4NNl24GNwwmn-EhQ-1; Tue, 21 Nov 2023 17:20:23 -0500 X-MC-Unique: HVA08a4NNl24GNwwmn-EhQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B5C93812581; Tue, 21 Nov 2023 22:20:23 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC60B492BFA; Tue, 21 Nov 2023 22:20:22 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org, binutils@sourceware.org Cc: Nick Clifton , Simon Sobisch , David Malcolm Subject: [PATCH 5/5] diagnostics: don't print annotation lines when there's no column info Date: Tue, 21 Nov 2023 17:20:18 -0500 Message-Id: <20231121222019.646253-6-dmalcolm@redhat.com> In-Reply-To: <20231121222019.646253-1-dmalcolm@redhat.com> References: <20231106222959.2707741-1-dmalcolm@redhat.com> <20231121222019.646253-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783213873978542068 X-GMAIL-MSGID: 1783213873978542068 gcc/ChangeLog: * diagnostic-show-locus.cc (layout::maybe_add_location_range): Don't print annotation lines for ranges when there's no column info. (selftest::test_one_liner_no_column): New. (selftest::test_diagnostic_show_locus_one_liner): Call it. --- gcc/diagnostic-show-locus.cc | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc index 563d2826f249..55e7166b9448 100644 --- a/gcc/diagnostic-show-locus.cc +++ b/gcc/diagnostic-show-locus.cc @@ -1295,6 +1295,15 @@ layout::maybe_add_location_range (const location_range *loc_range, sanely relative to the primary location. */ return false; + /* If there's no column information, then don't try to print + annotation lines for this range. */ + enum range_display_kind range_display_kind + = loc_range->m_range_display_kind; + if (start.column == 0 + || finish.column == 0 + || caret.column == 0) + range_display_kind = SHOW_LINES_WITHOUT_RANGE; + /* Everything is now known to be in the correct source file, but it may require further sanitization. */ layout_range ri (exploc_with_display_col (m_file_cache, @@ -1303,7 +1312,7 @@ layout::maybe_add_location_range (const location_range *loc_range, exploc_with_display_col (m_file_cache, finish, m_policy, LOCATION_ASPECT_FINISH), - loc_range->m_range_display_kind, + range_display_kind, exploc_with_display_col (m_file_cache, caret, m_policy, LOCATION_ASPECT_CARET), @@ -3297,6 +3306,20 @@ test_one_liner_simple_caret () pp_formatted_text (dc.printer)); } +/* No column information (column == 0). + No annotation line should be printed. */ + +static void +test_one_liner_no_column () +{ + test_diagnostic_context dc; + location_t caret = linemap_position_for_column (line_table, 0); + rich_location richloc (line_table, caret); + diagnostic_show_locus (&dc, &richloc, DK_ERROR); + ASSERT_STREQ (" foo = bar.field;\n", + pp_formatted_text (dc.printer)); +} + /* Caret and range. */ static void @@ -3848,6 +3871,7 @@ test_diagnostic_show_locus_one_liner (const line_table_case &case_) ASSERT_EQ (16, LOCATION_COLUMN (line_end)); test_one_liner_simple_caret (); + test_one_liner_no_column (); test_one_liner_caret_and_range (); test_one_liner_multiple_carets_and_ranges (); test_one_liner_fixit_insert_before ();