From patchwork Sat Apr 24 23:57:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1470026 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) 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=uXA6HkLm; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4FSSls6VMpz9sVw for ; Sun, 25 Apr 2021 09:58:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB6073939C24; Sat, 24 Apr 2021 23:58:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB6073939C24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1619308690; bh=viFibF53RTmOQp8FJuTvumRNdmzteR2X0U+Z95HN+XM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=uXA6HkLmu/mxRyLBeA+8L/vULbQCAkPnTmSz3p2U3ZXHQy6urK9wazke1mo9NZtsi /grHWX0ZZiIbMNzJldwHsosWYXBRBf5hFuv8kBLZ5HfhXViaEobulrDSPPH8NSe3a6 ymE8SvN4ZPPyKLBz5vFHpewpREU+iqTJi9PudmeE= 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 08AA23857026 for ; Sat, 24 Apr 2021 23:58:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 08AA23857026 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-475-iwZhB06uNmyyJ6w3v9uQwQ-1; Sat, 24 Apr 2021 19:58:05 -0400 X-MC-Unique: iwZhB06uNmyyJ6w3v9uQwQ-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 25B28835BDA; Sat, 24 Apr 2021 23:58:04 +0000 (UTC) Received: from t14s.localdomain.com (ovpn-112-65.phx2.redhat.com [10.3.112.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99C1A17D43; Sat, 24 Apr 2021 23:58:03 +0000 (UTC) To: gcc-patches@gcc.gnu.org, jakub@redhat.com, Richard Biener Subject: [PATCH] analyzer: fix ICE on NULL change.m_expr [PR100244] Date: Sat, 24 Apr 2021 19:57:57 -0400 Message-Id: <20210424235757.1364669-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_LOW, RCVD_IN_MSPIKE_H4, 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" PR analyzer/100244 reports an ICE on a -Wanalyzer-free-of-non-heap due to a case where free_of_non_heap::describe_state_change can be passed a NULL change.m_expr for a suitably complicated symbolic value. Bulletproof it by checking for change.m_expr being NULL before dereferencing it. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk for gcc 12 as r12-108-g61bfff562e3b6091d5a0a412a7d496bd523868a8. This ICE is technically a regression for gcc 11. The fix is trivial and confined to the analyzer. OK to push to gcc 11 branch? gcc/analyzer/ChangeLog: PR analyzer/100244 * sm-malloc.cc (free_of_non_heap::describe_state_change): Bulletproof against change.m_expr being NULL. gcc/testsuite/ChangeLog: PR analyzer/100244 * g++.dg/analyzer/pr100244.C: New test. --- gcc/analyzer/sm-malloc.cc | 2 +- gcc/testsuite/g++.dg/analyzer/pr100244.C | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/analyzer/pr100244.C diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc index 1d5b8601b1f..f02b73ab90a 100644 --- a/gcc/analyzer/sm-malloc.cc +++ b/gcc/analyzer/sm-malloc.cc @@ -1303,7 +1303,7 @@ public: { /* Attempt to reconstruct what kind of pointer it is. (It seems neater for this to be a part of the state, though). */ - if (TREE_CODE (change.m_expr) == SSA_NAME) + if (change.m_expr && TREE_CODE (change.m_expr) == SSA_NAME) { gimple *def_stmt = SSA_NAME_DEF_STMT (change.m_expr); if (gcall *call = dyn_cast (def_stmt)) diff --git a/gcc/testsuite/g++.dg/analyzer/pr100244.C b/gcc/testsuite/g++.dg/analyzer/pr100244.C new file mode 100644 index 00000000000..261b3cfff57 --- /dev/null +++ b/gcc/testsuite/g++.dg/analyzer/pr100244.C @@ -0,0 +1,22 @@ +// { dg-additional-options "-O1 -Wno-free-nonheap-object" } + +inline void *operator new (__SIZE_TYPE__, void *__p) { return __p; } + +struct __aligned_buffer { + int _M_storage; + int *_M_addr() { return &_M_storage; } +}; + +struct _Hashtable_alloc { + int _M_single_bucket; + int *_M_buckets; + _Hashtable_alloc () { _M_buckets = &_M_single_bucket; } + ~_Hashtable_alloc () { delete _M_buckets; } // { dg-warning "not on the heap" } +}; + +void +test01 (__aligned_buffer buf) +{ + _Hashtable_alloc *tmp = new (buf._M_addr ()) _Hashtable_alloc; + tmp->~_Hashtable_alloc (); +}