From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 B47A83858029 for ; Tue, 21 Nov 2023 22:20:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B47A83858029 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 B47A83858029 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=1700605231; cv=none; b=opQSXFxNQM33xdK/xYw7lkbXhDbmjKYERKUJIf8tyU6Znga/h6gXjJGfD0jXLeNZIQ8Gb26syYOxw6MUH7XjvG6mU3N+lzgFQcgvrd2YQNNHMJDrAzKSzhs4IOAleSwxmAwpdyJYvHw3PA8iMU9A+hmmpOXJqxuZ7Z4mlyQAp8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700605231; c=relaxed/simple; bh=vRM4dvP9BEVRIESxsNrac/KBdtw0acKZ9BNr3A864Qc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Cx7dhOjanNS2/F3Kry8WgpV2y+qqZeCZ7eDGc/WYAjuovCfVp/B6tf+ae9/c3YVoO5EJIDm8ZlYSIV++MoteD5I94zoWCcnm6wwA3Jarr4uCkj9DUtq3Z8vfH/LCY/3ajWGV+KOZUfr7IEx/+0+w2ZrRtqrm81iNHilv4x+ugFA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700605226; 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=Ivg+2HvohPDOK5O4k2zYjLG8evDvqh1FI6s3YI1dli3Z2lm6qs1ogAnrlL0+BdXuW0R0+3 tfV9vff401amm/+fpLt+f2iT9E7TjM+94fYitLIpVKJOPcBZv4lVfyTNJUc2te/VTauavr 5VaeL3wBVyiYMbP8N9vr4zeExlGO4tw= 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 (); -- 2.26.3