From patchwork Tue Nov 8 02:57:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 60156 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3498D385841D for ; Tue, 8 Nov 2022 02:58:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3498D385841D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667876285; bh=v/wi6mVHrF/5zJd3hx1OAcZ5Xy/slkiAEMV7Wp3cj78=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=UrHynaBKgucE7jo3rYDD/H5wcOuIi+Wp3tTsPpmBkysrbPZUvpTXu13BeIwL4FGgI SR6rEVxpyNZdc8910vQxiTwt0wWfIykEDLjGB4IFAQoOvbIwYRW/SMYum9rnx7eCjh N3b1mA8XlJNRnKc/BkeACI3UUwEe61n1RT+8DxWg= 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 6E9703858C53 for ; Tue, 8 Nov 2022 02:57:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E9703858C53 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-617-bVHaS4GOOsOwQgACkM2kaQ-1; Mon, 07 Nov 2022 21:57:31 -0500 X-MC-Unique: bVHaS4GOOsOwQgACkM2kaQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AEBE185A583 for ; Tue, 8 Nov 2022 02:57:30 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 893ED140EBF5; Tue, 8 Nov 2022 02:57:30 +0000 (UTC) To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] analyzer: introduce succeed_or_fail_call_info Date: Mon, 7 Nov 2022 21:57:29 -0500 Message-Id: <20221108025729.2493732-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 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_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This makes some followup code much cleaner. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r13-3769-gbe9fdbda1cbcd6. gcc/analyzer/ChangeLog: * call-info.cc (success_call_info::get_desc): Delete. (failed_call_info::get_desc): Likewise. (succeed_or_fail_call_info::get_desc): New. * call-info.h (class succeed_or_fail_call_info): New. (class success_call_info): Convert to a subclass of succeed_or_fail_call_info. (class failed_call_info): Likewise. Signed-off-by: David Malcolm --- gcc/analyzer/call-info.cc | 21 ++++++--------------- gcc/analyzer/call-info.h | 34 ++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/gcc/analyzer/call-info.cc b/gcc/analyzer/call-info.cc index ffdab73b165..7a1c4edfcae 100644 --- a/gcc/analyzer/call-info.cc +++ b/gcc/analyzer/call-info.cc @@ -141,24 +141,15 @@ call_info::call_info (const call_details &cd) gcc_assert (m_fndecl); } -/* class success_call_info : public call_info. */ - -/* Implementation of call_info::get_desc vfunc for success_call_info. */ - -label_text -success_call_info::get_desc (bool can_colorize) const -{ - return make_label_text (can_colorize, "when %qE succeeds", get_fndecl ()); -} - -/* class failed_call_info : public call_info. */ - -/* Implementation of call_info::get_desc vfunc for failed_call_info. */ +/* class succeed_or_fail_call_info : public call_info. */ label_text -failed_call_info::get_desc (bool can_colorize) const +succeed_or_fail_call_info::get_desc (bool can_colorize) const { - return make_label_text (can_colorize, "when %qE fails", get_fndecl ()); + if (m_success) + return make_label_text (can_colorize, "when %qE succeeds", get_fndecl ()); + else + return make_label_text (can_colorize, "when %qE fails", get_fndecl ()); } } // namespace ana diff --git a/gcc/analyzer/call-info.h b/gcc/analyzer/call-info.h index 4bb7dd7e198..2fd50776f0a 100644 --- a/gcc/analyzer/call-info.h +++ b/gcc/analyzer/call-info.h @@ -51,17 +51,36 @@ private: }; /* Subclass of call_info for a "success" outcome of a call, - adding a "when `FNDECL' succeeds" message. + adding either a + "when `FNDECL' succeeds" message (when 'success' is true) + or a + "when `FNDECL' fails" message (when 'success' is false). This is still abstract: the custom_edge_info::update_model vfunc must be implemented. */ -class success_call_info : public call_info +class succeed_or_fail_call_info : public call_info { public: label_text get_desc (bool can_colorize) const final override; protected: - success_call_info (const call_details &cd) : call_info (cd) {} + succeed_or_fail_call_info (const call_details &cd, bool success) + : call_info (cd), m_success (success) {} + + bool m_success; +}; + +/* Subclass of call_info for a "success" outcome of a call, + adding a "when `FNDECL' succeeds" message. + This is still abstract: the custom_edge_info::update_model vfunc + must be implemented. */ + +class success_call_info : public succeed_or_fail_call_info +{ +protected: + success_call_info (const call_details &cd) + : succeed_or_fail_call_info (cd, true) + {} }; /* Subclass of call_info for a "failure" outcome of a call, @@ -69,13 +88,12 @@ protected: This is still abstract: the custom_edge_info::update_model vfunc must be implemented. */ -class failed_call_info : public call_info +class failed_call_info : public succeed_or_fail_call_info { -public: - label_text get_desc (bool can_colorize) const final override; - protected: - failed_call_info (const call_details &cd) : call_info (cd) {} + failed_call_info (const call_details &cd) + : succeed_or_fail_call_info (cd, false) + {} }; } // namespace ana