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: 16824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2445223wru; Mon, 7 Nov 2022 18:58:30 -0800 (PST) X-Google-Smtp-Source: AMsMyM5SuQ9n8FlgKm1k4C1IHYY4WuJCPrHCgjpP4nzbwa12OuEFeyDeWdNjOr/yFGmEWcV6h4DT X-Received: by 2002:a17:907:6d23:b0:78d:8f0f:1266 with SMTP id sa35-20020a1709076d2300b0078d8f0f1266mr51274813ejc.762.1667876310351; Mon, 07 Nov 2022 18:58:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667876310; cv=none; d=google.com; s=arc-20160816; b=yUde1hWaog+rN3tfvB/wXUGglJAHDAlb2lhNOymaQ0qZw47T2/glrWk6+o21ApXxy4 PJzWr8WomuDqIlpcvEZr1Xk6EtYHjqFfpdD0LzzyGBiq9oD9oVOv3WywiSv4bdLjCzHN W4KotynkV1WsHbGqLqfHpMloIvvF9BHkMa/fxUDkkbpOrq2DW3mgrht34rhP6qUTi9x/ keTOPKaXCZB3bZlj866eKY/Y7TWQXtjTwLKRUJsr+pHvSqjD9MuJhL0jfzrXXrVKLvPf RP3GCo8i+feoxsILFuXeg8vAo1oJi5XWDbUETzh2W6EcRx1al51aeeQgVEm661mov/k9 f0ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=v/wi6mVHrF/5zJd3hx1OAcZ5Xy/slkiAEMV7Wp3cj78=; b=A91NxkEZAo2AJB3pHVxnBDLvrvKTEzoDnBaLLs2jBUVQci3YwGdscCyyWBXuX0ACi4 8VPdHtsoq1prHD9mw6akaXN5SpwFw8Z3LIJiB6G2xlbESrN65YrPMf8PTmb3FxrWyytG 4qvEUbQ5QSd7NmFJg0VHa778EBtGwR81+Ra3z/+AKDL/wz9wf/TYyTpcqFh61dTkoWxj onrfZqiohKmqezB+8Eto5tVJc/L402bktcqLyMfadIlGLDxIyjchJ94PsOsQsBlSwmIl S/SVzfJlu1alwRAV4aqZ5I96V80QWhyosbMgT50ADoFkp+Lvj129Q4JOxpvheJLh+3Of cQJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KCYaccn1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z10-20020a1709060f0a00b0078331a3b123si568024eji.572.2022.11.07.18.58.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 18:58:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KCYaccn1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4EBA738582B6 for ; Tue, 8 Nov 2022 02:58:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EBA738582B6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667876300; 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=KCYaccn19WW/J9odXupU1t6zTKJNkoY/A1VMo2NZL0w6YVNaZ2v3wzKX9Qo7J9WB7 I5GQQk2Ekk8UheLD+LT/D6/uFHoRaVI0CrMHVs1EX6DMOMqmRKHy2QuqKaBzkhf3N2 Yi643P80fH1ScmG7memePf9xRKmGwptZfjuCNuW8= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748895069778414302?= X-GMAIL-MSGID: =?utf-8?q?1748895069778414302?= 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