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.133.124]) by sourceware.org (Postfix) with ESMTPS id EF94C385840F for ; Tue, 21 Nov 2023 22:20:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF94C385840F 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 EF94C385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700605231; cv=none; b=iZ1KHUe+0P/m+iMmfynmQ96pc9Jbs7pWgIkCO9wBYPtHL03wQjhBi9VmV07gn5cNDXeRvIS1UWxs+p0A0kKY3eT6vwaJHlTPsFZdNXPi+pfCotCIv0gaJSKpDllKRt/aRc+HynlkrMlO4lh5lOJUxJ+sn4jHn9MxsZdev94iqYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700605231; c=relaxed/simple; bh=gPfVLSADLtEzxZavv1pl77wazMaszidnW4r3sOajOrI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=xboMrH8KQRlxB8w8kMByIGBAY5wCNwtpBLzIG6iH43ObMK3XE4O4eY0ZNy/g+zfxu5qB+hQ1dM3aq6/1wMRdZMhdJ7JY20sM8g8l+fvnIOTBtlAOYq6tU5vJPWRCUPHlk5ieHJuY8Bl9i2mOYL84+3o1PEvofZF5+LQtJsXQGOw= 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=4GEU7RTHuKifL2bjRYO0qtYyd71v2uSEt2Eq9sqcqNc=; b=IfgvuJCczpnfhwY2vXGkTJzyK8rV8GJsVkse51KcqFi/BaSrprKC+Tb27YIZLPK6isqMI0 zpxYzFwvHS8W+8lX7smGW7U68xPPEEK/R5i2vj6m4EFIFA/ynpCx7ScCOi1TLgM1Qfzbwg Si8SCHsKj63EVxCJzwP/FdPW6329uq0= 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-562-mKaSiFmFOZiHtepWJijRog-1; Tue, 21 Nov 2023 17:20:25 -0500 X-MC-Unique: mKaSiFmFOZiHtepWJijRog-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 DBCF23812580; Tue, 21 Nov 2023 22:20:22 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A0B7492BFA; 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 4/5] diagnostics: add diagnostic_context::get_location_text Date: Tue, 21 Nov 2023 17:20:17 -0500 Message-Id: <20231121222019.646253-5-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_H3,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 List-Id: No functional change intended. gcc/ChangeLog: * diagnostic.cc (diagnostic_get_location_text): Convert to... (diagnostic_context::get_location_text): ...this, and convert return type from char * to label_text. (diagnostic_build_prefix): Update for above change. (default_diagnostic_start_span_fn): Likewise. (selftest::assert_location_text): Likewise. * diagnostic.h (diagnostic_context::get_location_text): New decl. --- gcc/diagnostic.cc | 35 +++++++++++++++-------------------- gcc/diagnostic.h | 2 ++ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index b4ebcd29457c..4f66fa6acaa8 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -558,14 +558,12 @@ maybe_line_and_column (int line, int col) return result; } -/* Return a malloc'd string describing a location e.g. "foo.c:42:10". - The caller is responsible for freeing the memory. */ +/* Return a string describing a location e.g. "foo.c:42:10". */ -static char * -diagnostic_get_location_text (diagnostic_context *context, - expanded_location s) +label_text +diagnostic_context::get_location_text (const expanded_location &s) const { - pretty_printer *pp = context->printer; + pretty_printer *pp = this->printer; const char *locus_cs = colorize_start (pp_show_color (pp), "locus"); const char *locus_ce = colorize_stop (pp_show_color (pp)); const char *file = s.file ? s.file : progname; @@ -574,13 +572,13 @@ diagnostic_get_location_text (diagnostic_context *context, if (strcmp (file, special_fname_builtin ())) { line = s.line; - if (context->m_show_column) - col = context->converted_column (s); + if (m_show_column) + col = this->converted_column (s); } const char *line_col = maybe_line_and_column (line, col); - return build_message_string ("%s%s%s:%s", locus_cs, file, - line_col, locus_ce); + return label_text::take (build_message_string ("%s%s%s:%s", locus_cs, file, + line_col, locus_ce)); } static const char *const diagnostic_kind_text[] = { @@ -610,12 +608,11 @@ diagnostic_build_prefix (diagnostic_context *context, text_ce = colorize_stop (pp_show_color (pp)); } - expanded_location s = diagnostic_expand_location (diagnostic); - char *location_text = diagnostic_get_location_text (context, s); + const expanded_location s = diagnostic_expand_location (diagnostic); + label_text location_text = context->get_location_text (s); - char *result = build_message_string ("%s %s%s%s", location_text, + char *result = build_message_string ("%s %s%s%s", location_text.get (), text_cs, text, text_ce); - free (location_text); return result; } @@ -1091,9 +1088,8 @@ void default_diagnostic_start_span_fn (diagnostic_context *context, expanded_location exploc) { - char *text = diagnostic_get_location_text (context, exploc); - pp_string (context->printer, text); - free (text); + label_text text = context->get_location_text (exploc); + pp_string (context->printer, text.get ()); pp_newline (context->printer); } @@ -2852,9 +2848,8 @@ assert_location_text (const char *expected_loc_text, xloc.data = NULL; xloc.sysp = false; - char *actual_loc_text = diagnostic_get_location_text (&dc, xloc); - ASSERT_STREQ (expected_loc_text, actual_loc_text); - free (actual_loc_text); + label_text actual_loc_text = dc.get_location_text (xloc); + ASSERT_STREQ (expected_loc_text, actual_loc_text.get ()); } /* Verify that diagnostic_get_location_text works as expected. */ diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 958068fea926..8b7f147c0d28 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -543,6 +543,8 @@ public: return m_option_callbacks.m_lang_mask; } + label_text get_location_text (const expanded_location &s) const; + private: bool includes_seen_p (const line_map_ordinary *map); -- 2.26.3