From patchwork Fri Nov 3 18:02:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 161389 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1222344vqu; Fri, 3 Nov 2023 11:03:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH8t6AE3LK2ZB4cwHXFuL0nCDM+OIjeMNTbPRQcJRgDnREDyxGtOwCBKtPu4trkK2Q2ZThv X-Received: by 2002:a05:620a:280a:b0:77a:1d5b:2ccb with SMTP id f10-20020a05620a280a00b0077a1d5b2ccbmr19933610qkp.6.1699034599205; Fri, 03 Nov 2023 11:03:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1699034599; cv=pass; d=google.com; s=arc-20160816; b=Qmf9Mmh4coTyavbuykd69h8pTgEi/yJsF1U1NTDB/UXy9Q9aJ6LmVfSg1ehBzivyBn jUVN7bnKfUjfZIFf6D7yKBS8ujbrORw/392QC60GwerIrc53aJlebWidWty6A5aycOmr FhL5cl0H5V38wuu9QAVBQcjBO3yZ/J8GE+ybXeEju6zx8zQbojxif9qkc/zOh4EXh5Us ywIKxyK6iqmnOFMWOzP5TM9xEtJFiiW5XCBWExB9rn8Asjlova3jND4DQfNv6dvjyHn+ t3+Kv/UfmUUsWyNaDwDAvtfUYMs9ryQd5PB4EMccetoFHVvPgcQc4NoU2x2IuleMgGPM eYeg== 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:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=y+iSot2WBT43+hWN0ITkAaasih7AY78aIC6t0KBdFFM=; fh=NXemEfxTRbZtBxUkxR2ehQUaYlcDfMdzPkO8MChVQE4=; b=kczNN3FtmaxYRO/DQwTvC4sErYy2whPQ3ydWnOVPgsgZ56g4GtTPKgB57xgUn45kZQ jrRxFMIAO8FnS1tE+mtr2HH/mFn9+pZ9XtHtIuLP5gxLFOYiq5hQFpWlG7LIC93wihO+ RpmxbWT0xCQMLSxzkZSn1Xx68BwVk/sGfUfBhoMMypiuMmHxEFTN7cF7s2veo68FyTh8 UhaSVnHBHPgzEI/I6Rsht/a0Na7ZzL6DzGRts4ZCDV9GPDNOMkUwdOon0OgeAxoSrHEj vm/xcR15Bfi80jcTotlFzdG6AhcNXKtkOSkhYqeP2JW7FNgDERV8oCVweiPTQn6kP7GT uFWQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F7Lol6Jh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id e17-20020a05620a015100b0077893a5a7fdsi1932431qkn.740.2023.11.03.11.03.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 11:03:19 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F7Lol6Jh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 E8F203858409 for ; Fri, 3 Nov 2023 18:03:18 +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 188093858D28 for ; Fri, 3 Nov 2023 18:02:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 188093858D28 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 188093858D28 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=1699034576; cv=none; b=PXItRlMszXGCyQoepg2fJbcDYZZUMmCWPUo6/vVZIDFUlKb1cRtuQjM0KJqAwiE/X53olr63q3U2B9MnGA8Pt5x37dGwM/qtG+qklstXAO6wdmxI6FaXicaVcMYB9IVxoetQnuCk9Cz7bFXjAwUgtkTYwPC9NRLC3sgMTmocIcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699034576; c=relaxed/simple; bh=TqYERt5//X50SdulU2l1bx5qwC5uzs3JuoXcBZ3ClZQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=snYTqkO8Jx5Qg/Y+hHBUV9Ve8AxbwPetIukjcUnAbaAW4mXBHWm31mNYAP9z3EmMCsmOFASYMdyZQwW6/xZQ38v3NDooNqRUqXcRkUiQPKJGuU3uTXvwdVcGudhge0qj26Ur+7Ww3YNzBP3y+tOKZF2m5mzuwTdTVAQTwXeVS6I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699034565; 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=y+iSot2WBT43+hWN0ITkAaasih7AY78aIC6t0KBdFFM=; b=F7Lol6JhUNQ/ZPZvg182YiOd3KcZMhMCSODQVrui24IIbqYWSDg+B9DT+Bdip1hg4K2q01 2NLja2OaGXBg8YxBO/EgjHoKdp/21cbmrCFsyvu2VUWWNRD0iiWCNABhj4HtVVXjwLFGAv sZG9iNNdDPbl+YpJhqcQwdFhU97heVs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-eud236aWOH2if2FYXgBkmQ-1; Fri, 03 Nov 2023 14:02:44 -0400 X-MC-Unique: eud236aWOH2if2FYXgBkmQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 2C60481B562 for ; Fri, 3 Nov 2023 18:02:44 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.8.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 015BF502E; Fri, 3 Nov 2023 18:02:43 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] diagnostics: consolidate group-handling fields in diagnostic_context Date: Fri, 3 Nov 2023 14:02:41 -0400 Message-Id: <20231103180241.2338051-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: 1781566903598600947 X-GMAIL-MSGID: 1781566903598600947 No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-5112-gae8abcb81ed814. gcc/ChangeLog: * diagnostic.cc (diagnostic_initialize): Update for consolidation of group-based fields. (diagnostic_report_diagnostic): Likewise. (diagnostic_context::begin_group): New, based on body of auto_diagnostic_group's ctor. (diagnostic_context::end_group): New, based on body of auto_diagnostic_group's dtor. (auto_diagnostic_group::auto_diagnostic_group): Convert to a call to begin_group. (auto_diagnostic_group::~auto_diagnostic_group): Convert to a call to end_group. * diagnostic.h (diagnostic_context::begin_group): New decl. (diagnostic_context::end_group): New decl. (diagnostic_context::diagnostic_group_nesting_depth): Rename to... (diagnostic_context::m_diagnostic_groups.m_nesting_depth): ...this. (diagnostic_context::diagnostic_group_emission_count): Rename to... (diagnostic_context::m_diagnostic_groups::m_emission_count): ...this. --- gcc/diagnostic.cc | 42 ++++++++++++++++++++++++++++-------------- gcc/diagnostic.h | 19 ++++++++++++++----- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 0f392358aef..0759fae916e 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -218,8 +218,8 @@ diagnostic_initialize (diagnostic_context *context, int n_opts) context->tabstop = 8; context->escape_format = DIAGNOSTICS_ESCAPE_FORMAT_UNICODE; context->edit_context_ptr = NULL; - context->diagnostic_group_nesting_depth = 0; - context->diagnostic_group_emission_count = 0; + context->m_diagnostic_groups.m_nesting_depth = 0; + context->m_diagnostic_groups.m_emission_count = 0; context->m_output_format = new diagnostic_text_output_format (*context); context->set_locations_cb = nullptr; context->ice_handler_cb = NULL; @@ -1570,9 +1570,9 @@ diagnostic_report_diagnostic (diagnostic_context *context, ++diagnostic_kind_count (context, diagnostic->kind); /* Is this the initial diagnostic within the stack of groups? */ - if (context->diagnostic_group_emission_count == 0) + if (context->m_diagnostic_groups.m_emission_count == 0) context->m_output_format->on_begin_group (); - context->diagnostic_group_emission_count++; + context->m_diagnostic_groups.m_emission_count++; pp_format (context->printer, &diagnostic->message); context->m_output_format->on_begin_diagnostic (diagnostic); @@ -2296,28 +2296,42 @@ fancy_abort (const char *file, int line, const char *function) internal_error ("in %s, at %s:%d", function, trim_filename (file), line); } +/* struct diagnostic_context. */ + +void +diagnostic_context::begin_group () +{ + m_diagnostic_groups.m_nesting_depth++; +} + +void +diagnostic_context::end_group () +{ + if (--m_diagnostic_groups.m_nesting_depth == 0) + { + /* Handle the case where we've popped the final diagnostic group. + If any diagnostics were emitted, give the context a chance + to do something. */ + if (m_diagnostic_groups.m_emission_count > 0) + m_output_format->on_end_group (); + m_diagnostic_groups.m_emission_count = 0; + } +} + /* class auto_diagnostic_group. */ /* Constructor: "push" this group into global_dc. */ auto_diagnostic_group::auto_diagnostic_group () { - global_dc->diagnostic_group_nesting_depth++; + global_dc->begin_group (); } /* Destructor: "pop" this group from global_dc. */ auto_diagnostic_group::~auto_diagnostic_group () { - if (--global_dc->diagnostic_group_nesting_depth == 0) - { - /* Handle the case where we've popped the final diagnostic group. - If any diagnostics were emitted, give the context a chance - to do something. */ - if (global_dc->diagnostic_group_emission_count > 0) - global_dc->m_output_format->on_end_group (); - global_dc->diagnostic_group_emission_count = 0; - } + global_dc->end_group (); } /* class diagnostic_text_output_format : public diagnostic_output_format. */ diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index a2c8740cbd0..ed1b6c0c7b1 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -226,6 +226,12 @@ public: the context of a diagnostic message. */ struct diagnostic_context { +public: + void begin_group (); + void end_group (); + +public: + /* Where most of the diagnostic formatting work is done. */ pretty_printer *printer; @@ -443,12 +449,15 @@ struct diagnostic_context applied, for generating patches. */ edit_context *edit_context_ptr; - /* How many diagnostic_group instances are currently alive. */ - int diagnostic_group_nesting_depth; + /* Fields relating to diagnostic groups. */ + struct { + /* How many diagnostic_group instances are currently alive. */ + int m_nesting_depth; - /* How many diagnostics have been emitted since the bottommost - diagnostic_group was pushed. */ - int diagnostic_group_emission_count; + /* How many diagnostics have been emitted since the bottommost + diagnostic_group was pushed. */ + int m_emission_count; + } m_diagnostic_groups; /* How to output diagnostics (text vs a structured format such as JSON). Must be non-NULL; owned by context. */