From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1035) id 527023AA981B; Wed, 28 Apr 2021 16:59:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 527023AA981B MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Earnshaw To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-222] arm: fix UB due to missing mode check [PR100311] X-Act-Checkin: gcc X-Git-Author: Richard Earnshaw X-Git-Refname: refs/heads/master X-Git-Oldrev: e1543e694dadf1ea70eb72325219bc0cdc914a35 X-Git-Newrev: 59f5d16f2c5db4d9592c8ce6453afe81334bb012 Message-Id: <20210428165944.527023AA981B@sourceware.org> Date: Wed, 28 Apr 2021 16:59:44 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Apr 2021 16:59:44 -0000 https://gcc.gnu.org/g:59f5d16f2c5db4d9592c8ce6453afe81334bb012 commit r12-222-g59f5d16f2c5db4d9592c8ce6453afe81334bb012 Author: Richard Earnshaw Date: Wed Apr 28 17:56:38 2021 +0100 arm: fix UB due to missing mode check [PR100311] Some places in the compiler iterate over all the fixed registers to check if that register can be used in a particular mode. The idiom is to iterate over the register and then for that register, if it supports the current mode to check all that register and any additional registers needed (HARD_REGNO_NREGS). If these two checks are not fully aligned then it is possible to generate a buffer overrun when testing data objects that are sized by the number of hard regs in the machine. The VPR register is a case where these checks were not consistent and because this is the last HARD register the result was that we ended up overflowing the fixed_regs array. gcc: PR target/100311 * config/arm/arm.c (arm_hard_regno_mode_ok): Only allow VPR to be used in HImode. Diff: --- gcc/config/arm/arm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 6641e3fb4dc..0371d9818fd 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -25269,7 +25269,7 @@ arm_hard_regno_mode_ok (unsigned int regno, machine_mode mode) return false; if (IS_VPR_REGNUM (regno)) - return true; + return mode == HImode; if (TARGET_THUMB1) /* For the Thumb we only allow values bigger than SImode in