From patchwork Sat Jan 8 00:06:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 49737 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 A6F053857C74 for ; Sat, 8 Jan 2022 00:07:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6F053857C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641600443; bh=wkeUAZxi5whaEwhwxc8p6LJQV98IHwXbWrvFBSBYRcA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=T5DOFSY4GwB3YZEtaNWVVLESsYlGjXepy8VxkF31lZ2nNelAgws3Cf6izv82b8gq9 C8yKr4YSszqWWAPBXGC1+0lRdYS2drsYx7JSB0vcpodFKq0VwVF2uh76jMm3w8KgVT CVpVakr1ffh0cIvRZEd/OQMMKmi+Km1dtHjo+D/8= 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 ESMTPS id 2959A3857C7C for ; Sat, 8 Jan 2022 00:06:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2959A3857C7C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-434-oTqFaQsRNYOJEDYC-H2CHg-1; Fri, 07 Jan 2022 19:06:50 -0500 X-MC-Unique: oTqFaQsRNYOJEDYC-H2CHg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 200B08042E0 for ; Sat, 8 Jan 2022 00:06:50 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.16.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5384A12E3E; Sat, 8 Jan 2022 00:06:48 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed] analyzer: add region::is_named_decl_p Date: Fri, 7 Jan 2022 19:06:45 -0500 Message-Id: <20220108000645.1075948-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.1 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 patch adds a debug function that I've found handy when debugging a problem with handling the decl yy_buffer_stack" in PR analyzer/103546. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r12-6376-gc1b7d28a5987e74232b7f054849f8bd8ccc7e7de. gcc/analyzer/ChangeLog: * region.cc (region::is_named_decl_p): New. * region.h (region::is_named_decl_p): New decl. gcc/ChangeLog: * doc/analyzer.texi (Other Debugging Techniques): Document region::is_named_decl_p. --- gcc/analyzer/region.cc | 14 ++++++++++++++ gcc/analyzer/region.h | 2 ++ gcc/doc/analyzer.texi | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc index befcaa495cd..161e7e1fb10 100644 --- a/gcc/analyzer/region.cc +++ b/gcc/analyzer/region.cc @@ -638,6 +638,20 @@ region::symbolic_for_unknown_ptr_p () const return false; } +/* Return true if this is a region for a decl with name DECL_NAME. + Intended for use when debugging (for assertions and conditional + breakpoints). */ + +DEBUG_FUNCTION bool +region::is_named_decl_p (const char *decl_name) const +{ + if (tree decl = maybe_get_decl ()) + if (DECL_NAME (decl) + && !strcmp (IDENTIFIER_POINTER (DECL_NAME (decl)), decl_name)) + return true; + return false; +} + /* region's ctor. */ region::region (complexity c, unsigned id, const region *parent, tree type) diff --git a/gcc/analyzer/region.h b/gcc/analyzer/region.h index fbb50a1817a..d97bbc1e3f1 100644 --- a/gcc/analyzer/region.h +++ b/gcc/analyzer/region.h @@ -189,6 +189,8 @@ public: const complexity &get_complexity () const { return m_complexity; } + bool is_named_decl_p (const char *decl_name) const; + protected: region (complexity c, unsigned id, const region *parent, tree type); diff --git a/gcc/doc/analyzer.texi b/gcc/doc/analyzer.texi index 657798101c2..62faac44d7f 100644 --- a/gcc/doc/analyzer.texi +++ b/gcc/doc/analyzer.texi @@ -545,3 +545,13 @@ and the exploded graph in compressed JSON form. One approach when tracking down where a particular bogus state is introduced into the @code{exploded_graph} is to add custom code to @code{program_state::validate}. + +The debug function @code{region::is_named_decl_p} can be used when debugging, +such as for assertions and conditional breakpoints. For example, when +tracking down a bug in handling a decl called @code{yy_buffer_stack}, I +temporarily added a: +@smallexample + gcc_assert (!m_base_region->is_named_decl_p ("yy_buffer_stack")); +@end smallexample +to @code{binding_cluster::mark_as_escaped} to trap a point where +@code{yy_buffer_stack} was mistakenly being treated as having escaped.