From patchwork Fri Jun 20 17:36:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 362308 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 411AE140092 for ; Sat, 21 Jun 2014 03:36:55 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=IhkzsLhqWYnguvL4J9AlLjD5edLI+YU6dCY7IH92u6I40TQVc9 MutwTYO/14/ymLNezQ88P11L5JVzVIttRBkEkNKWlUDzk0lDDGNy5jKKE/ve2yhk A8mbO1mL4ujnA6ADorKuo1Zk3Fxlb0H5fTzFiu6j9Y3U4z0vuHwIbLZrY= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=1XBepQ+IToDtp0a8MKcxyQF7sdQ=; b=r2JZoeuCFdXvLghWrSPI kcv4M0rM8sB+rMQS5Ab+0t7pv7jQ6Wj/YEmQ22sK7Vdw9moHVAZyZIStI0YCflQ7 xZsobbz/bgivshwkM7ni8mvRb0gRbZdNFfQ/TF5rV3JboI7FmHrZn30tF0UyXh2C MGwXjpi8Ug1PBHwV/6ZtFRU= Received: (qmail 10056 invoked by alias); 20 Jun 2014 17:36:48 -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 10045 invoked by uid 89); 20 Jun 2014 17:36:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 20 Jun 2014 17:36:46 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5KHajjq019758 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 20 Jun 2014 13:36:45 -0400 Received: from redhat.com (ovpn-116-31.ams2.redhat.com [10.36.116.31]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5KHaf1H002564 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Fri, 20 Jun 2014 13:36:43 -0400 Date: Fri, 20 Jun 2014 19:36:41 +0200 From: Marek Polacek To: GCC Patches Cc: Jakub Jelinek , Jeff Law , Richard Henderson Subject: [PATCH] Fix arrays in rtx.u + add minor rtx verification Message-ID: <20140620173640.GC14420@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) When implementing -fsanitize=bounds I noticed a whole slew of errors about accessing u.fld[] field in rtx_def. Turned out this is indeed a bug, the array should have a size of 8; u.hwint[] array had similar issue. Thus fixed, plus I added some verification code to genpreds.c (can't do it in gengenrtl.c as that doesn't include rtl.h) so this won't happen again. Verified that the bootstrap crashes by bootstrapping with changed RTX_FLD_WIDTH/RTX_HWINT_WIDTH, otherwise the bootstrapp passes. Ok for trunk? 2014-06-20 Marek Polacek * genpreds.c (verify_rtx_codes): New function. (main): Call it. * rtl.h (RTX_FLD_WIDTH, RTX_HWINT_WIDTH): Define. (struct rtx_def): Use them. Marek diff --git gcc/genpreds.c gcc/genpreds.c index b14a4ac..3826757 100644 --- gcc/genpreds.c +++ gcc/genpreds.c @@ -1471,6 +1471,40 @@ parse_option (const char *opt) return 0; } +/* Verify RTX codes. We can't call fatal_error here, so call + gcc_unreachable after error to really abort. */ + +static void +verify_rtx_codes (void) +{ + unsigned int i, j; + + for (i = 0; i < NUM_RTX_CODE; i++) + if (strchr (GET_RTX_FORMAT (i), 'w') == NULL) + { + if (strlen (GET_RTX_FORMAT (i)) > RTX_FLD_WIDTH) + { + error ("insufficient size of RTX_FLD_WIDTH"); + gcc_unreachable (); + } + } + else + { + const size_t len = strlen (GET_RTX_FORMAT (i)); + for (j = 0; j < len; j++) + if (GET_RTX_FORMAT (i)[j] != 'w') + { + error ("rtx format does not contain only hwint entries"); + gcc_unreachable (); + } + if (len > RTX_HWINT_WIDTH) + { + error ("insufficient size of RTL_MAX_HWINT_WIDTH"); + gcc_unreachable (); + } + } +} + /* Master control. */ int main (int argc, char **argv) @@ -1518,5 +1552,7 @@ main (int argc, char **argv) if (have_error || ferror (stdout) || fflush (stdout) || fclose (stdout)) return FATAL_EXIT_CODE; + verify_rtx_codes (); + return SUCCESS_EXIT_CODE; } diff --git gcc/rtl.h gcc/rtl.h index 6ec91a8..3f2e774 100644 --- gcc/rtl.h +++ gcc/rtl.h @@ -264,6 +264,12 @@ struct GTY((variable_size)) hwivec_def { #define CWI_PUT_NUM_ELEM(RTX, NUM) \ (RTL_FLAG_CHECK1("CWI_PUT_NUM_ELEM", (RTX), CONST_WIDE_INT)->u2.num_elem = (NUM)) +/* The maximum number of entries in the FLD array in rtx. */ +#define RTX_FLD_WIDTH 8 + +/* The maximum number of entries in the HWINT array in rtx. */ +#define RTX_HWINT_WIDTH (MAX (REAL_WIDTH, 3)) + /* RTL expression ("rtx"). */ struct GTY((chain_next ("RTX_NEXT (&%h)"), @@ -378,8 +384,8 @@ struct GTY((chain_next ("RTX_NEXT (&%h)"), The number of operands and their types are controlled by the `code' field, according to rtl.def. */ union u { - rtunion fld[1]; - HOST_WIDE_INT hwint[1]; + rtunion fld[RTX_FLD_WIDTH]; + HOST_WIDE_INT hwint[RTX_HWINT_WIDTH]; struct block_symbol block_sym; struct real_value rv; struct fixed_value fv;