From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 75344 invoked by alias); 16 Sep 2015 14:23:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 75278 invoked by uid 89); 16 Sep 2015 14:23:46 -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,KAM_ASCII_DIVIDERS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Wed, 16 Sep 2015 14:23:44 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 91E89AC9A for ; Wed, 16 Sep 2015 14:23:40 +0000 (UTC) Date: Wed, 16 Sep 2015 14:24:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR67271 Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2015-09/txt/msg01184.txt.bz2 Bootstrapped / tested on x86_64-unknown-linux-gnu, applied. Richard. 2015-09-16 Richard Biener PR middle-end/67271 * fold-const.c (native_encode_expr): Bail out on bogus offsets. * gcc.dg/pr67271.c: New testcase. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 227779) +++ gcc/fold-const.c (working copy) @@ -7106,6 +7127,10 @@ native_encode_string (const_tree expr, u int native_encode_expr (const_tree expr, unsigned char *ptr, int len, int off) { + /* We don't support starting at negative offset and -1 is special. */ + if (off < -1) + return 0; + switch (TREE_CODE (expr)) { case INTEGER_CST: Index: gcc/testsuite/gcc.dg/pr67271.c =================================================================== --- gcc/testsuite/gcc.dg/pr67271.c (revision 0) +++ gcc/testsuite/gcc.dg/pr67271.c (working copy) @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O" } */ + +extern long int labs (long int j); +int +main () +{ + long *a = (long *)"empty"; + int i = 1441516387; + a[i] = labs (a[i]); + return 0; +}