From patchwork Fri Dec 7 14:59:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1009502 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-491886-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jFHdK216"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43BFxk19glz9s3l for ; Sat, 8 Dec 2018 01:59:52 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=ww/7o35LanJsTRNE8PMq4hyWHh8y6qSIskdOa33DReVX475F6X a2OMxd9RrhWJ5ATdTTZHi5lTSYM2TB3QuNZXh9iaeqT/eb4wJVVxfLIwe1Zzp8a4 dzyv6SpgH4Ms5g4sLFojx0VOXN492yhzfB/yE0nD9Ogr+f4vnIQSSEFy4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=miegbvtop3aD7cXeT6Kk4HpdGHA=; b=jFHdK216iE6P2SkM1ZFa 2XcjUF8hBj5xWBF4b4VBJzVcveNZxmCV8RRmcR7mTp1VPX2R8HQ5VfsSjigHAgcd GqC1kg80YCBmRx0XQ61tapXlBOb/F5EQXAwWc/G8kjWy91XoRyDRZNWlB4mZDdLl XSrPNYcEsRbDO05MgpuZ14I= Received: (qmail 31816 invoked by alias); 7 Dec 2018 14:59:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 31806 invoked by uid 89); 7 Dec 2018 14:59:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Dec 2018 14:59:43 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0A137B07E for ; Fri, 7 Dec 2018 14:59:41 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Subject: [PR 88214] Check that an argument is pointer before attempting agg jf construction from it User-Agent: Notmuch/0.26 (https://notmuchmail.org) Emacs/26.1 (x86_64-suse-linux-gnu) Date: Fri, 07 Dec 2018 15:59:40 +0100 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi, ICE in PR 88214 happens because a type-mismatch in K&R C code makes IPA-CP analysis call ao_ref_init_from_ptr_and_size on an integer SSA_NAME, this function in turn constructs a temporary MEM_REF based on that integer SSA_NAME and then later on call_may_clobber_ref_p_1 treats the MEM_REF base as a pointer, gets its SSA_NAME_PTR_INFO and tries to work with bitmaps there. But because the SSA_NAME is an integer, there is no SSA_NAME_PTR_INFO, there is range info instead and this leads to a crash. On a related note, would people object to adding the following assert, which would have made this bug much more straightforward to find? index 85a5de7..66cf2f2 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -710,6 +710,7 @@ ao_ref_init_from_ptr_and_size (ao_ref *ref, tree ptr, tree size) } else { + gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr))); ref->base = build2 (MEM_REF, char_type_node, ptr, null_pointer_node); ref->offset = 0; The bug itself can be fixed with the patch below. I have verified it avoids the ICE on powerpc64-linux and did a full bootstrap and test on an x86_64-linux. The patch is simple enough that I believe that is good enough. 2018-12-06 Martin Jambor PR ipa/88214 * ipa-prop.c (determine_locally_known_aggregate_parts): Make sure we check pointers against pointers. testsuite/ * gcc.dg/ipa/pr88214.c: New test. --- gcc/ipa-prop.c | 3 ++- gcc/testsuite/gcc.dg/ipa/pr88214.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr88214.c diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 74052350ac1..4dbe26829e3 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -1569,7 +1569,8 @@ determine_locally_known_aggregate_parts (gcall *call, tree arg, if (TREE_CODE (arg) == SSA_NAME) { tree type_size; - if (!tree_fits_uhwi_p (TYPE_SIZE (TREE_TYPE (arg_type)))) + if (!tree_fits_uhwi_p (TYPE_SIZE (TREE_TYPE (arg_type))) + || !POINTER_TYPE_P (TREE_TYPE (arg))) return; check_ref = true; arg_base = arg; diff --git a/gcc/testsuite/gcc.dg/ipa/pr88214.c b/gcc/testsuite/gcc.dg/ipa/pr88214.c new file mode 100644 index 00000000000..4daa9829e75 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr88214.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void i(); + short a; + void b(e) char * e; + { + i(); + b(a); + }