From patchwork Fri Dec 9 02:29:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 61720 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 3431D388A76A for ; Fri, 9 Dec 2022 02:29:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3431D388A76A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670552996; bh=/8ihDX+qI0cIm/HqlgBBk+t/W7DukxQGU7xCF9J3wyU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=FcgrSfrk/kU1zLzOIyhbiNTSyIOCaIuTOaItFi18g4ZS0L4drImWvSuV2WVWfFQhC AdFCdUSMxEdFNJ1nA3QVA8uqz5FzWENZcjcB6DG6Pzv5hQ5NEuZKjJ6kQ/oXwvRawS mcmgUkZUx6TaUO/3P5btQmP4bLd4guPDGxq2nINo= 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 879CD3872553 for ; Fri, 9 Dec 2022 02:29:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 879CD3872553 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-50-6FB3VqBHPHWGvD6cu9xwVQ-1; Thu, 08 Dec 2022 21:29:23 -0500 X-MC-Unique: 6FB3VqBHPHWGvD6cu9xwVQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BC439380451D for ; Fri, 9 Dec 2022 02:29:22 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92A8E40C2065; Fri, 9 Dec 2022 02:29:22 +0000 (UTC) To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] analyzer: fix ICE on region creation during get_referenced_base_regions [PR108003] Date: Thu, 8 Dec 2022 21:29:19 -0500 Message-Id: <20221209022919.32279-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.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_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TLD_CHINA, 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" Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r13-4578-g7dc0ecafe60b22. gcc/analyzer/ChangeLog: PR analyzer/108003 * call-summary.cc (call_summary_replay::convert_region_from_summary_1): Convert heap_regs_in_use from auto_sbitmap to auto_bitmap. * region-model-manager.cc (region_model_manager::get_or_create_region_for_heap_alloc): Convert from sbitmap to bitmap. * region-model-manager.h: Likewise. * region-model.cc (region_model::get_or_create_region_for_heap_alloc): Convert from auto_sbitmap to auto_bitmap. (region_model::get_referenced_base_regions): Likewise. * region-model.h: Include "bitmap.h" rather than "sbitmap.h". (region_model::get_referenced_base_regions): Convert from auto_sbitmap to auto_bitmap. gcc/testsuite/ChangeLog: PR analyzer/108003 * g++.dg/analyzer/pr108003.C: New test. Signed-off-by: David Malcolm --- gcc/analyzer/call-summary.cc | 2 +- gcc/analyzer/region-model-manager.cc | 2 +- gcc/analyzer/region-model-manager.h | 2 +- gcc/analyzer/region-model.cc | 4 +-- gcc/analyzer/region-model.h | 4 +-- gcc/testsuite/g++.dg/analyzer/pr108003.C | 37 ++++++++++++++++++++++++ 6 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/analyzer/pr108003.C diff --git a/gcc/analyzer/call-summary.cc b/gcc/analyzer/call-summary.cc index 31674736ac5..a18a1b1b40a 100644 --- a/gcc/analyzer/call-summary.cc +++ b/gcc/analyzer/call-summary.cc @@ -726,7 +726,7 @@ call_summary_replay::convert_region_from_summary_1 (const region *summary_reg) /* If we have a heap-allocated region in the summary, then it was allocated within the callee. Create a new heap-allocated region to summarize this. */ - auto_sbitmap heap_regs_in_use (mgr->get_num_regions ()); + auto_bitmap heap_regs_in_use; get_caller_model ()->get_referenced_base_regions (heap_regs_in_use); return mgr->get_or_create_region_for_heap_alloc (heap_regs_in_use); } diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc index 0fb96386f28..dad7c411446 100644 --- a/gcc/analyzer/region-model-manager.cc +++ b/gcc/analyzer/region-model-manager.cc @@ -1698,7 +1698,7 @@ get_region_for_unexpected_tree_code (region_model_context *ctxt, const region * region_model_manager:: -get_or_create_region_for_heap_alloc (const sbitmap &base_regs_in_use) +get_or_create_region_for_heap_alloc (const bitmap &base_regs_in_use) { /* Try to reuse an existing region, if it's unreferenced in the client state. */ diff --git a/gcc/analyzer/region-model-manager.h b/gcc/analyzer/region-model-manager.h index 13fbe483f6d..ca9a498f12f 100644 --- a/gcc/analyzer/region-model-manager.h +++ b/gcc/analyzer/region-model-manager.h @@ -155,7 +155,7 @@ public: The number of these within the analysis can grow arbitrarily. They are still owned by the manager. */ const region * - get_or_create_region_for_heap_alloc (const sbitmap &base_regs_in_use); + get_or_create_region_for_heap_alloc (const bitmap &base_regs_in_use); const region *create_region_for_alloca (const frame_region *frame); void log_stats (logger *logger, bool show_objs) const; diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 18eaf22a5d1..f6cd34f4c22 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -4904,7 +4904,7 @@ region_model::get_or_create_region_for_heap_alloc (const svalue *size_in_bytes, /* Determine which regions are referenced in this region_model, so that we can reuse an existing heap_allocated_region if it's not in use on this path. */ - auto_sbitmap base_regs_in_use (m_mgr->get_num_regions ()); + auto_bitmap base_regs_in_use; get_referenced_base_regions (base_regs_in_use); const region *reg = m_mgr->get_or_create_region_for_heap_alloc (base_regs_in_use); @@ -4917,7 +4917,7 @@ region_model::get_or_create_region_for_heap_alloc (const svalue *size_in_bytes, reachable in this region_model. */ void -region_model::get_referenced_base_regions (auto_sbitmap &out_ids) const +region_model::get_referenced_base_regions (auto_bitmap &out_ids) const { reachable_regions reachable_regs (const_cast (this)); m_store.for_each_cluster (reachable_regions::init_cluster_cb, diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index 291bb2ff45a..626b10d2538 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -26,7 +26,7 @@ along with GCC; see the file COPYING3. If not see (Zhongxing Xu, Ted Kremenek, and Jian Zhang) http://lcs.ios.ac.cn/~xuzb/canalyze/memmodel.pdf */ -#include "sbitmap.h" +#include "bitmap.h" #include "selftest.h" #include "analyzer/svalue.h" #include "analyzer/region.h" @@ -390,7 +390,7 @@ class region_model region_model_context *ctxt); const region *create_region_for_alloca (const svalue *size_in_bytes, region_model_context *ctxt); - void get_referenced_base_regions (auto_sbitmap &out_ids) const; + void get_referenced_base_regions (auto_bitmap &out_ids) const; tree get_representative_tree (const svalue *sval) const; tree get_representative_tree (const region *reg) const; diff --git a/gcc/testsuite/g++.dg/analyzer/pr108003.C b/gcc/testsuite/g++.dg/analyzer/pr108003.C new file mode 100644 index 00000000000..c93e9596992 --- /dev/null +++ b/gcc/testsuite/g++.dg/analyzer/pr108003.C @@ -0,0 +1,37 @@ +/* Regression test for ICE. */ +/* { dg-additional-options "-Wno-analyzer-possible-null-argument" } */ +/* { dg-additional-options "-Wno-analyzer-malloc-leak" } */ +/* { dg-additional-options "-Wno-analyzer-possible-null-dereference" } */ + +/* { dg-additional-options "-O1 --param analyzer-max-svalue-depth=5" } */ + +struct locale { + class _Impl; + _Impl *_M_impl; + + template + locale (const locale &, _Facet *); + + static locale + classic (); +}; + +struct locale::_Impl { + _Impl (_Impl, int); +}; + +template +locale::locale (const locale &, _Facet *) +{ + new _Impl (*_M_impl, 1); +} + +struct codecvt { + virtual void do_max_lengththrow (); +}; + +void +test01 () +{ + locale (locale::classic (), new codecvt); +}