From patchwork Tue Dec 19 16:58:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 850926 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-469567-incoming=patchwork.ozlabs.org@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.b="FARYRSWD"; 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 3z1PHy5g6Nz9sNc for ; Wed, 20 Dec 2017 03:58: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 :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=efCiYfnbDNL7AZh9SUmmIkgcJYAQAVmLHtncuj0hxUC5TI YV9ptRRoaNIuFRs0Qve8Ud0qgtqPaSU7T4XrcZyKN8ghbzG3y+FhB9KpZZyGo1VV JWeNdD4rdFDKCrIREllazKbzoB7QNdfP877KJ7XQVVgg30WqnT8Y9arLt5vuA= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=yny3ZXIgV7Yn4ZexzrCcvTYDOnI=; b=FARYRSWDCqlWjNSgpi0G +zaW3TkC9Z5cPgw3ZOmuGQJ0GwJIAZsZNlzq87h3CaXzaP9VBrNFDONl9E2J48/N 0q6QJqu2PNEaiq9GAwWc12DohZr7/32nb2tPnARDtZXU7xj5Esr047xgEnId+4mo aMXLGgHpEIOVVQ3AjZUygkU= Received: (qmail 25789 invoked by alias); 19 Dec 2017 16:58:43 -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 25735 invoked by uid 89); 19 Dec 2017 16:58:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=aval X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 19 Dec 2017 16:58:41 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B20A115A2 for ; Tue, 19 Dec 2017 08:58:39 -0800 (PST) Received: from [10.2.207.77] (e100706-lin.cambridge.arm.com [10.2.207.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5DEDE3F487 for ; Tue, 19 Dec 2017 08:58:39 -0800 (PST) Message-ID: <5A39453D.5080906@foss.arm.com> Date: Tue, 19 Dec 2017 16:58:37 +0000 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" Subject: [PATCH][arm] PR target/82975: Guard against reg_renumber being NULL in arm.h Hi all, In this bug we ICE when checking REGNO_OK_FOR_INDEX_P on arm during pre-IRA scheduling. This is because REGNO_OK_FOR_INDEX_P ends up checking the reg_renumber array. Before IRA reg_renumber is NULL and thus we segfault. The fix is to guard the use of reg_renumber in the logic in TEST_REGNO in arm.h. On aarch64, for example, we also guard against the reg_renumber == NULL case. This fixes the ICE. I also remove the part of the comment that muses on when reg_renumber is available as with this patch it should now be safe to use at any point. Bootstrapped and tested on arm-none-linux-gnueabihf. Committed to trunk as r255830. Thanks, Kyrill 2017-12-19 Kyrylo Tkachov PR target/82975 * config/arm/arm.h (TEST_REGNO): Check reg_renumber is set before accessing it. Adjust comment. 2017-12-19 Kyrylo Tkachov PR target/82975 * gcc.dg/pr82975.c: New test. commit 57beb9c5faf502ef6fb5a40bc0fa54541238b0c1 Author: Kyrylo Tkachov Date: Mon Dec 18 12:06:55 2017 +0000 [arm] PR target/82975: Guard against reg_renumber being NULL in arm.h diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h index 47931e1..90478fc 100644 --- a/gcc/config/arm/arm.h +++ b/gcc/config/arm/arm.h @@ -1626,7 +1626,8 @@ enum arm_auto_incmodes has been allocated, which happens in reginfo.c during register allocation. */ #define TEST_REGNO(R, TEST, VALUE) \ - ((R TEST VALUE) || ((unsigned) reg_renumber[R] TEST VALUE)) + ((R TEST VALUE) \ + || (reg_renumber && ((unsigned) reg_renumber[R] TEST VALUE))) /* Don't allow the pc to be used. */ #define ARM_REGNO_OK_FOR_BASE_P(REGNO) \ diff --git a/gcc/testsuite/gcc.dg/pr82975.c b/gcc/testsuite/gcc.dg/pr82975.c new file mode 100644 index 0000000..e6c13bc --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr82975.c @@ -0,0 +1,19 @@ +/* PR target/82975. */ +/* { dg-do compile } */ +/* { dg-options "-mtune=cortex-a57 -fno-sched-pressure -O2" } */ + +typedef __SIZE_TYPE__ size_t; + +struct S1 +{ + char pad1; + char val; + short pad2; +}; + +extern char t[256]; + +void foo (struct S1 a, size_t i) +{ + t[i] = a.val; +}