From patchwork Tue Apr 28 17:53:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1278648 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=none (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=qld1cQ4g; 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 49BTlP71NLz9sSK for ; Wed, 29 Apr 2020 03:53:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6DDC43948A93; Tue, 28 Apr 2020 17:53:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DDC43948A93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588096398; bh=xac10UlMQrBaPsT5sMxwLUAe9eh1ZgrM4xTFc0LWnK0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qld1cQ4gspxmcngJz7RLO7eJhYivVqTGxdE/18zmPmctSNDzV7Yj+QlZmOmvY8OXw CeTvAlrotuK4dqU6oIg9Iza8R6WqCXJOb+i+tvWTl0wQWaYs1ol2yWRhHY+ykJp1vn zhjZryHTEnfdP3IFYl6C53ki8RKBL2Pgix+Qtxtc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id A57463851C12 for ; Tue, 28 Apr 2020 17:53:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A57463851C12 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-154-DLWoIdkhPP27Rp2LV4v6pg-1; Tue, 28 Apr 2020 13:53:07 -0400 X-MC-Unique: DLWoIdkhPP27Rp2LV4v6pg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D2AE18FE864 for ; Tue, 28 Apr 2020 17:53:06 +0000 (UTC) Received: from t470.redhat.com (ovpn-114-112.phx2.redhat.com [10.3.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69369600DB; Tue, 28 Apr 2020 17:53:03 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed] analyzer: fix ICE copying struct [PR 94816] Date: Tue, 28 Apr 2020 13:53:01 -0400 Message-Id: <20200428175301.31620-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-26.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, 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/94816 reports an ICE when attempting to copy a struct containing a field for which add_region_for_type for fails (on an OFFSET_TYPE): the region for the src field comes from make_region_for_unexpected_tree_code which gives it a NULL type, and then the copy calls add_region_for_type which unconditionally dereferences the NULL type. This patch fixes the ICE by checking for NULL types in add_region_for_type. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to master as r10-8015-g5eae0ac76dcb6aac1d1d6c4edd8852e0035792e4 gcc/analyzer/ChangeLog: PR analyzer/94816 * engine.cc (impl_region_model_context::on_unexpected_tree_code): Handle NULL tree. * region-model.cc (region_model::add_region_for_type): Handle NULL type. * region-model.h (test_region_model_context::on_unexpected_tree_code): Handle NULL tree. gcc/testsuite/ChangeLog: PR analyzer/94816 * g++.dg/analyzer/pr94816.C: New test. --- gcc/analyzer/engine.cc | 2 +- gcc/analyzer/region-model.cc | 9 ++++++--- gcc/analyzer/region-model.h | 2 +- gcc/testsuite/g++.dg/analyzer/pr94816.C | 13 +++++++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/analyzer/pr94816.C diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 880e70fb2ba..c73d493a3d8 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -699,7 +699,7 @@ impl_region_model_context::on_unexpected_tree_code (tree t, logger * const logger = get_logger (); if (logger) logger->log ("unhandled tree code: %qs in %qs at %s:%i", - get_tree_code_name (TREE_CODE (t)), + t ? get_tree_code_name (TREE_CODE (t)) : "(null)", loc.get_impl_location ().m_function, loc.get_impl_location ().m_file, loc.get_impl_location ().m_line); diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 22049a34d29..0794be9a583 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -6448,10 +6448,13 @@ region_id region_model::add_region_for_type (region_id parent_rid, tree type, region_model_context *ctxt) { - gcc_assert (TYPE_P (type)); + if (type) + { + gcc_assert (TYPE_P (type)); - if (region *new_region = make_region_for_type (parent_rid, type)) - return add_region (new_region); + if (region *new_region = make_region_for_type (parent_rid, type)) + return add_region (new_region); + } /* If we can't handle TYPE, return a placeholder region, and stop exploring this path. */ diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index ad3dd1d13ef..6d427c4c654 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -2205,7 +2205,7 @@ public: FINAL OVERRIDE { internal_error ("unhandled tree code: %qs", - get_tree_code_name (TREE_CODE (t))); + t ? get_tree_code_name (TREE_CODE (t)) : "(null)"); } private: diff --git a/gcc/testsuite/g++.dg/analyzer/pr94816.C b/gcc/testsuite/g++.dg/analyzer/pr94816.C new file mode 100644 index 00000000000..e241a44e376 --- /dev/null +++ b/gcc/testsuite/g++.dg/analyzer/pr94816.C @@ -0,0 +1,13 @@ +/* { dg-additional-options "-O" } */ + +struct jr; + +struct ch { + int jr::*rx; +}; + +ch +ad () +{ + return ch (); +}