From patchwork Thu Apr 26 13:20:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim MacArthur X-Patchwork-Id: 155265 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 06603B6FA1 for ; Thu, 26 Apr 2012 23:21:36 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1336051297; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=UgAs9YD JjmSHT2+0n66aUKe2ElA=; b=ks/IZ0ITiAdoudC3J3t+QJVqjLhghVtsJei1FEC SzyEf3vnJKzyKNPkG14IuTwMajNO0VGa35Lv+pmxblm3PTI87/D+0gD5QMg0oQtk Fs+rPHVz0aXQqWnG56VZHAb+KytBKtD3qJZRcRLBrWM1KumDz/9eUUpNBCN0VhmG zj8U= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:X-MC-Unique:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=iqLMqkaO9RMS/HNk+SBNtBSfgnTPB9pRBTqhCbq4sxJQ4LiN6jokc7UIFnC07W yYqqSBk54sqqQe/BJce/glkKGQ5L9Lms9+1uDps385Z02lObIpdcuy1MbpojvLcg UlXysyd12KlTcsPGIPAcc2IF7DBdv/ZoUtWb6Q84SwveY=; Received: (qmail 10212 invoked by alias); 26 Apr 2012 13:21:34 -0000 Received: (qmail 10199 invoked by uid 22791); 26 Apr 2012 13:21:33 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_LOW, SUBJ_OBFU_PUNCT_FEW, SUBJ_OBFU_PUNCT_MANY X-Spam-Check-By: sourceware.org Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 Apr 2012 13:21:13 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Thu, 26 Apr 2012 14:20:52 +0100 Received: from [10.1.79.45] ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 26 Apr 2012 14:21:57 +0100 Message-ID: <4F994B99.1010606@arm.com> Date: Thu, 26 Apr 2012 14:20:25 +0100 From: Jim MacArthur User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.28) Gecko/20120313 Thunderbird/3.1.20 MIME-Version: 1.0 To: gcc-patches@gcc.gnu.org Subject: [patch] More thorough checking in reg_fits_class_p X-MC-Unique: 112042614205216201 X-IsSubscribed: yes 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 The current code in reg_fits_class_p appears to be incorrect; since offset may be negative, it's necessary to check both ends of the range otherwise an array overrun or underrun may occur when calling in_hard_reg_set_p. in_hard_reg_set_p should also be checked for each register in the range of regno .. regno+offset. A negative offset can occur on a big-endian target. For example, on AArch64, subreg_regno_offset (0, DImode, 0, TImode) returns -1. We discovered this problem while developing unrelated code for big-endian support in the AArch64 back end. I've tested this with an x86 bootstrap which shows no errors, and with our own AArch64 back end. Ok for trunk? gcc/Changelog entry: 2012-04-26 Jim MacArthur * recog.c (reg_fits_class_p): Check every register between regno and regno+offset is in the hard register set. diff --git a/gcc/recog.c b/gcc/recog.c index 8fb96a0..825bfb1 100644 --- a/gcc/recog.c +++ b/gcc/recog.c @@ -2759,14 +2759,28 @@ bool reg_fits_class_p (const_rtx operand, reg_class_t cl, int offset, enum machine_mode mode) { - int regno = REGNO (operand); + unsigned int regno = REGNO (operand); if (cl == NO_REGS) return false; - return (HARD_REGISTER_NUM_P (regno) - && in_hard_reg_set_p (reg_class_contents[(int) cl], - mode, regno + offset)); + /* We should not assume all registers in the range regno to regno + offset are + valid just because each end of the range is. */ + if (HARD_REGISTER_NUM_P (regno) && HARD_REGISTER_NUM_P (regno + offset)) + { + unsigned int i; + + unsigned int start = MIN (regno, regno + offset); + unsigned int end = MAX (regno, regno + offset); + for (i = start; i <= end; i++) + { + if (!in_hard_reg_set_p (reg_class_contents[(int) cl], + mode, i)) + return false; + } + return true; + } + return false; } /* Split single instruction. Helper function for split_all_insns and