From patchwork Mon Sep 30 16:03:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1991081 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Qoqb2Tc6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHQrk5RPmz1xsc for ; Tue, 1 Oct 2024 02:05:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EB37B38650E0 for ; Mon, 30 Sep 2024 16:05:08 +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.133.124]) by sourceware.org (Postfix) with ESMTP id 84EED385020A for ; Mon, 30 Sep 2024 16:03:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84EED385020A 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 84EED385020A 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=1727712216; cv=none; b=Ov1jbLAuG1ewHXGppdbC62ArY7jOUchLgcby+KghdMJoLCdiDldJ1HHHN+njusKdfpj8Ze+CIR2Q3/4wdM4NrPJdFdi13b+S5lfl8H8LnZTAgOvqWrwApPF7FWrd271UILCQBOF5nSzNoieBC/f8mQc1RQFYRxyNYcczHau+qIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727712216; c=relaxed/simple; bh=jgIDr8jUBaGCzBlH7sjl+w6p2UAs7iybcHUgblRHXSg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=x3XMDcDxH9kC7S2jqBWRlRjIC23r9ZZPAZCvmXzlgj0mlM8xi0xz0mkn52skoZ/NbHTTy3pWiRiVbetldByHbi+NP5J+YPTkAOT7Ot4BK2iWLj3gBhrwF3sHLRuZX78ElpqaSg5GqHkAmaUcPnXRvomz9f0yMSoM1UFvJ4HhLUg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727712213; 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; bh=ofTFQ24cN+LJgnL3NYHfOpxdLW42A3hl0MlSeQyO3TU=; b=Qoqb2Tc6LPMC9m7g1YNkktAEM5+Z6q5e9PIA3qvh6GhUkMA53aD7oviNwQ4e75OWCWXh+5 k0q22wsuV5EeuT6qvXAShL7iheg0flLh2HvrahvAEJWGYvt1E8reIJ067AiXApC7EDk/Z8 hA/9UZXN31num52EyihX+zp+zgWruWo= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-RBBws1NvMtid3FSSMTYXWg-1; Mon, 30 Sep 2024 12:03:30 -0400 X-MC-Unique: RBBws1NvMtid3FSSMTYXWg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.40]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 35E90195608A for ; Mon, 30 Sep 2024 16:03:29 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.17.150]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8E93319560AA; Mon, 30 Sep 2024 16:03:28 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed: r15-3977] diagnostics: require callers of diagnostic_show_locus to be explicit about the printer [PR116613] Date: Mon, 30 Sep 2024 12:03:27 -0400 Message-ID: <20240930160327.2857210-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org As work towards supporting multiple diagnostic outputs (where each output has its own pretty_printer), update diagnostic_show_locus so that the pretty_printer must always be explicitly passed in. No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r15-3977-ge7a8fbe2fed83b. gcc/c-family/ChangeLog: PR other/116613 * c-format.cc (selftest::test_type_mismatch_range_labels): Explicitly pass in dc.m_printer to diagnostic_show_locus. gcc/ChangeLog: PR other/116613 * diagnostic-show-locus.cc (diagnostic_context::maybe_show_locus): Convert param "pp" from * to &. Drop logic for using the context's m_printer when the param is null. * diagnostic.h (diagnostic_context::maybe_show_locus): Convert param "pp" from * to &. (diagnostic_show_locus): Drop default "nullptr" value for pp param. Assert that it and context are nonnull. Pass pp by reference to maybe_show_locus. gcc/testsuite/ChangeLog: PR other/116613 * gcc.dg/plugin/expensive_selftests_plugin.c (test_richloc): Explicitly pass in dc.m_printer to diagnostic_show_locus. Signed-off-by: David Malcolm --- gcc/c-family/c-format.cc | 2 +- gcc/diagnostic-show-locus.cc | 8 ++------ gcc/diagnostic.h | 8 +++++--- gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc index 614b43266a31..f4a65a5019c3 100644 --- a/gcc/c-family/c-format.cc +++ b/gcc/c-family/c-format.cc @@ -5578,7 +5578,7 @@ test_type_mismatch_range_labels () richloc.add_range (param, SHOW_RANGE_WITHOUT_CARET, ¶m_label); test_diagnostic_context dc; - diagnostic_show_locus (&dc, &richloc, DK_ERROR); + diagnostic_show_locus (&dc, &richloc, DK_ERROR, dc.m_printer); if (c_dialect_cxx ()) /* "char*", without a space. */ ASSERT_STREQ (" printf (\"msg: %i\\n\", msg);\n" diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc index a1d66cf493d6..b575dc51a78c 100644 --- a/gcc/diagnostic-show-locus.cc +++ b/gcc/diagnostic-show-locus.cc @@ -3265,7 +3265,7 @@ add_location_if_nearby (const diagnostic_context &dc, void diagnostic_context::maybe_show_locus (const rich_location &richloc, diagnostic_t diagnostic_kind, - pretty_printer *pp, + pretty_printer &pp, diagnostic_source_effect_info *effects) { const location_t loc = richloc.get_loc (); @@ -3287,12 +3287,8 @@ diagnostic_context::maybe_show_locus (const rich_location &richloc, m_last_location = loc; - if (!pp) - pp = m_printer; - gcc_assert (pp); - diagnostic_source_print_policy source_policy (*this); - source_policy.print (*pp, richloc, diagnostic_kind, effects); + source_policy.print (pp, richloc, diagnostic_kind, effects); } diagnostic_source_print_policy:: diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 54b7f307f849..447e3b183d92 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -529,7 +529,7 @@ public: void maybe_show_locus (const rich_location &richloc, diagnostic_t diagnostic_kind, - pretty_printer *pp, + pretty_printer &pp, diagnostic_source_effect_info *effect_info); void emit_diagram (const diagnostic_diagram &diagram); @@ -970,11 +970,13 @@ inline void diagnostic_show_locus (diagnostic_context *context, rich_location *richloc, diagnostic_t diagnostic_kind, - pretty_printer *pp = nullptr, + pretty_printer *pp, diagnostic_source_effect_info *effect_info = nullptr) { + gcc_assert (context); gcc_assert (richloc); - context->maybe_show_locus (*richloc, diagnostic_kind, pp, effect_info); + gcc_assert (pp); + context->maybe_show_locus (*richloc, diagnostic_kind, *pp, effect_info); } /* Because we read source files a second time after the frontend did it the diff --git a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c index 3c534005a419..554dad6fa35a 100644 --- a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c @@ -48,7 +48,7 @@ test_richloc (rich_location *richloc) { /* Run the diagnostic and fix-it printing code. */ test_diagnostic_context dc; - diagnostic_show_locus (&dc, richloc, DK_ERROR); + diagnostic_show_locus (&dc, richloc, DK_ERROR, dc.m_printer); /* Generate a diff. */ edit_context ec (global_dc->get_file_cache ());