From patchwork Sat Sep 26 01:36:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1371697 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=L9W0zb2p; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Byrwp1zThz9sSt for ; Sat, 26 Sep 2020 11:36:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB4FA3952C13; Sat, 26 Sep 2020 01:36:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB4FA3952C13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1601084193; bh=h6ONY7QJaeoFfUTYHLMGvV7u+ZcLIwQk47kCfYMMuQ0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=L9W0zb2p2FpgMTvH9yLa5pXpGL+iXYQ23WYV8r8KPdRS3ksL9/9iVbEXZRQz8xPH1 uQLflOq3rqFtwyvyVqV+SyiXZAnS9h8gnArquKDCrFl7jBKbZgPpaFDIb2TxHDaLX/ 15eWYBXOTomGA94KtyMXNkLMXg8WCWGx60RxhIbw= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id C56613952C13 for ; Sat, 26 Sep 2020 01:36:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C56613952C13 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-45-uVndMbFHPiu9xc5emui8tQ-1; Fri, 25 Sep 2020 21:36:27 -0400 X-MC-Unique: uVndMbFHPiu9xc5emui8tQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 352E010066FC for ; Sat, 26 Sep 2020 01:36:26 +0000 (UTC) Received: from t470.redhat.com (ovpn-112-230.phx2.redhat.com [10.3.112.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3CD95D9DC; Sat, 26 Sep 2020 01:36:25 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed] analyzer: fix ICEs treeifying offset_region [PR96646, PR96841] Date: Fri, 25 Sep 2020 21:36:24 -0400 Message-Id: <20200926013624.19213-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.5 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_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to master as r11-3471-g29f5db8ef81fac4db8e66e5f06fdf1d469e8161c. gcc/analyzer/ChangeLog: PR analyzer/96646 PR analyzer/96841 * region-model.cc (region_model::get_representative_path_var): When handling offset_region, wrap the MEM_REF's first argument in an ADDR_EXPR of pointer type, rather than simply using the tree for the parent region. Require the MEM_REF's second argument to be an integer constant. gcc/testsuite/ChangeLog: PR analyzer/96646 PR analyzer/96841 * gcc.dg/analyzer/pr96646.c: New test. * gcc.dg/analyzer/pr96841.c: New test. --- gcc/analyzer/region-model.cc | 7 +++++-- gcc/testsuite/gcc.dg/analyzer/pr96646.c | 24 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/analyzer/pr96841.c | 23 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr96646.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr96841.c diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 981fb779df2..a88a295a241 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -2140,11 +2140,14 @@ region_model::get_representative_path_var (const region *reg, path_var offset_pv = get_representative_path_var (offset_reg->get_byte_offset (), visited); - if (!offset_pv) + if (!offset_pv || TREE_CODE (offset_pv.m_tree) != INTEGER_CST) return path_var (NULL_TREE, 0); + tree addr_parent = build1 (ADDR_EXPR, + build_pointer_type (reg->get_type ()), + parent_pv.m_tree); return path_var (build2 (MEM_REF, reg->get_type (), - parent_pv.m_tree, offset_pv.m_tree), + addr_parent, offset_pv.m_tree), parent_pv.m_stack_depth); } diff --git a/gcc/testsuite/gcc.dg/analyzer/pr96646.c b/gcc/testsuite/gcc.dg/analyzer/pr96646.c new file mode 100644 index 00000000000..2ac5a03b0e5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr96646.c @@ -0,0 +1,24 @@ +/* { dg-additional-options "-O1" } */ + +struct zx { + struct zx *b4, *g0; +}; + +struct oo { + void *ph; + struct zx el; +}; + +inline void +k7 (struct zx *xj) +{ + xj->b4->g0 = 0; /* { dg-warning "dereference of NULL" } */ + xj->b4 = 0; +} + +void +n8 (struct oo *yx) +{ + k7 (&yx->el); + n8 (yx); +} diff --git a/gcc/testsuite/gcc.dg/analyzer/pr96841.c b/gcc/testsuite/gcc.dg/analyzer/pr96841.c new file mode 100644 index 00000000000..d9d35f3dce8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr96841.c @@ -0,0 +1,23 @@ +/* { dg-additional-options "-O1 -Wno-builtin-declaration-mismatch" } */ + +int +l8 (void); + +__SIZE_TYPE__ +malloc (__SIZE_TYPE__); + +void +th (int *); + +void +bv (__SIZE_TYPE__ ny) +{ + int ***mf; + + while (l8 ()) + { + *mf = 0; + (*mf)[ny] = (int *) malloc (sizeof (int)); + th ((*mf)[ny]); /* { dg-warning "leak" } */ + } +}