From patchwork Mon Sep 23 14:17:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1166084 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-509447-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="LxnG2UdJ"; 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 46cRHT1t8Bz9sP6 for ; Tue, 24 Sep 2019 00:17:57 +1000 (AEST) 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=vQBwphAgJYkHBSB+6Wh7lm4RRlTYZrn8rhgJFpQYNPnHCf8/09 3YplYKvQxhASCDQW6wkzaG5vzgbyulePGoLh0gXnW0hqfKTXbpj1Waj6iQm1oQtr Jjquq7Qvdd/ivsRVT4EtIePjcrztxSv+0g8wYz2LdG1l5ep4VpfL+gB44= 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=GHUvmotpSEvzLY3t0TahyT7usg4=; b=LxnG2UdJ76Fgc7V7Vdnr ZZp7VkFCgodEfUSJrmZZ6ersoiz84sDp0/RqxHabe8qUqQwssmalHkd0PbFVdlxZ 5fTdfelUOI7xVL1rNMIwWpLoIrxhcdMdbxwBjFPz2vglUS5wl/zmtt4dmQFN/71h FkC/eyJ/+3t36Fq27GHLrjg= Received: (qmail 78546 invoked by alias); 23 Sep 2019 14:17:49 -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 78538 invoked by uid 89); 23 Sep 2019 14:17:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 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; Mon, 23 Sep 2019 14:17:48 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B3683AB9B for ; Mon, 23 Sep 2019 14:17:45 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Subject: [PR 91832] Do not ICE on negative offsets in ipa-sra User-Agent: Notmuch/0.29.1 (https://notmuchmail.org) Emacs/26.3 (x86_64-suse-linux-gnu) Date: Mon, 23 Sep 2019 16:17:45 +0200 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi, IPA-SRA asserts that an offset obtained from get_ref_base_and_extent is non-negative (after it verifies it is based on a parameter). That assumption is invalid as the testcase shows. One could probably also write a testcase with defined behavior, but unless I see a reasonable one where the transformation is really desirable, I'd like to just punt on those cases. Bootstrapped and tested on x86_64-linux. OK for trunk? Thanks, Martin 2019-09-23 Martin Jambor PR ipa/91832 * ipa-sra.c (scan_expr_access): Check that offset is non-negative. testsuite/ * gcc.dg/ipa/pr91832.c: New test. --- gcc/ipa-sra.c | 7 ++++++- gcc/testsuite/gcc.dg/ipa/pr91832.c | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr91832.c diff --git a/gcc/ipa-sra.c b/gcc/ipa-sra.c index a32defb59bd..0ccebbd4607 100644 --- a/gcc/ipa-sra.c +++ b/gcc/ipa-sra.c @@ -1692,7 +1692,12 @@ scan_expr_access (tree expr, gimple *stmt, isra_scan_context ctx, disqualify_split_candidate (desc, "Encountered a bit-field access."); return; } - gcc_assert (offset >= 0); + if (offset < 0) + { + disqualify_split_candidate (desc, "Encountered an access at a " + "negative offset."); + return; + } gcc_assert ((offset % BITS_PER_UNIT) == 0); gcc_assert ((size % BITS_PER_UNIT) == 0); if ((offset / BITS_PER_UNIT) >= (UINT_MAX - ISRA_ARG_SIZE_LIMIT) diff --git a/gcc/testsuite/gcc.dg/ipa/pr91832.c b/gcc/testsuite/gcc.dg/ipa/pr91832.c new file mode 100644 index 00000000000..4a0d62ec1d9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr91832.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct A1 { + char a1[1]; +}; + +void fn2(char a); + +void fn1(struct A1 *p1) { + fn2(p1->a1[-1]); +}