From patchwork Thu Oct 29 15:30:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 537915 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 8867B14076E for ; Fri, 30 Oct 2015 02:30:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=aIh0ImKn; dkim-atps=neutral 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:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=NBdgZTYk1bqTiTZl Afx0BRhlmaVDGjoEkgTGH3kLHaCpW8d3SlqTf3c/gcJfmZ4uyCcbNfho3DEg6Sbl b5dtxf544R91wh6IqNV9QdOBxWrOOj7errPoUFY5ISw/9OzzbTZNkAbIevGBIKMp MztMi0rqCJO4n/V3c8jVV8mzKcc= 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:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=gVvwoThfaO5Dpb/QHgnJ6C f5W0Y=; b=aIh0ImKnp6NAw9/YnV3z5YuCnxQuWWhUSxWEYwHyqufHBoU9bJwUA2 Hr8PqiC3Y7eh9jw/TX2jxqgIRkA6u0z9LY0gyfBa24I1+LcyjQ5IqjFz8UUTbfze nyFGC2cU7L1EXAl0FQRYY8MDHOdkY1jMd9vgVNpG7aT4iQ8dQ4JhM= Received: (qmail 7920 invoked by alias); 29 Oct 2015 15:30:14 -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 7880 invoked by uid 89); 29 Oct 2015 15:30:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Oct 2015 15:30:13 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-24-844eF7g8TBCleiRVozGFMg-1; Thu, 29 Oct 2015 15:30:08 +0000 Received: from localhost ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 29 Oct 2015 15:30:07 +0000 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Robustify REAL_MODE_FORMAT Date: Thu, 29 Oct 2015 15:30:07 +0000 Message-ID: <87eggdu1z4.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: 844eF7g8TBCleiRVozGFMg-1 Make sure that REAL_MODE_FORMAT aborts if it is passed an invalid mode, rather than stepping beyond the bounds of an array. It turned out that some code was passing non-float modes to the real.h routines. Tested on x86_64-linux-gnu, arm-linux-gnueabi and aarch64-linux-gnu. OK to install? Thanks, Richard gcc/ * real.h (REAL_MODE_FORMAT): Abort if the mode isn't a SCALAR_FLOAT_MODE_P. diff --git a/gcc/real.h b/gcc/real.h index e65b526..d3b14e5 100644 --- a/gcc/real.h +++ b/gcc/real.h @@ -167,7 +167,9 @@ extern const struct real_format * (real_format_for_mode[DECIMAL_FLOAT_MODE_P (MODE) \ ? (((MODE) - MIN_MODE_DECIMAL_FLOAT) \ + (MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1)) \ - : ((MODE) - MIN_MODE_FLOAT)]) + : GET_MODE_CLASS (MODE) == MODE_FLOAT \ + ? ((MODE) - MIN_MODE_FLOAT) \ + : (gcc_unreachable (), 0)]) #define FLOAT_MODE_FORMAT(MODE) \ (REAL_MODE_FORMAT (SCALAR_FLOAT_MODE_P (MODE)? (MODE) \