From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 72659 invoked by alias); 14 Aug 2017 08:22:20 -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 61677 invoked by uid 89); 14 Aug 2017 08:22:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-spam-relays-external:74.125.82.68, H*RU:74.125.82.68, SIGNED X-HELO: mail-wm0-f68.google.com Received: from mail-wm0-f68.google.com (HELO mail-wm0-f68.google.com) (74.125.82.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 Aug 2017 08:22:12 +0000 Received: by mail-wm0-f68.google.com with SMTP id d40so13562509wma.3 for ; Mon, 14 Aug 2017 01:22:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=z3C3i/29SIf0rNNiGPg2nqsiqUCyNfO3IrP1PEcPIa8=; b=FYo1HMTWZj/lDZxbR5LjfaBJJhdl/vtkIRq9wJXniTWjwTTedt+B7lpndkDDN+JBOL 486w94JTkW7l2avN64dw34ZgMmp9REkKUC3Xo2jqpFDtUDcpmA4dAnHfyN9wv44Ov3uu zOjoSfTj5wnWrWEi00lzV1Fq4BAbV5lULMVRjz5JLUSJ9jAYNd3R2KniaERsoZh4AjQ2 EKG5raMnbJEMk990Cd0CX+rwi03zOmya0mNa5aVuF61Mw7U/0xRllc0sGAP+LQ9DSgce MWMWWL1hfGOB9udZB9ud9ZTdJxBCyyfPU6CswfDv43lVoEE1Lk48/iNV2TZZQyBansSm lJFA== X-Gm-Message-State: AHYfb5gNRYuW3izmBk13R27bBs1uWGb9T/FZcrA3RWvoAEyni4UOaLpy Qp3T25jzONpeKmmBMnPib3jbrRhWWg== X-Received: by 10.80.209.195 with SMTP id i3mr23895544edg.70.1502698930003; Mon, 14 Aug 2017 01:22:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.80.180.249 with HTTP; Mon, 14 Aug 2017 01:22:09 -0700 (PDT) In-Reply-To: <20170808172345.GK17069@redhat.com> References: <20170807084751.GC17069@redhat.com> <20170807085809.GJ2123@tucnak> <20170807090959.GD17069@redhat.com> <20170808172345.GK17069@redhat.com> From: Richard Biener Date: Mon, 14 Aug 2017 08:32:00 -0000 Message-ID: Subject: Re: [PATCH] Fix middle-end/81737 To: Marek Polacek Cc: GCC Patches , Jakub Jelinek Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00850.txt.bz2 On Tue, Aug 8, 2017 at 7:23 PM, Marek Polacek wrote: > On Mon, Aug 07, 2017 at 04:07:49PM +0200, Richard Biener wrote: >> On August 7, 2017 11:09:59 AM GMT+02:00, Marek Polacek wrote: >> >On Mon, Aug 07, 2017 at 10:58:09AM +0200, Jakub Jelinek wrote: >> >> On Mon, Aug 07, 2017 at 10:47:51AM +0200, Marek Polacek wrote: >> >> > In my recent change I failed to check whether the type domain >> >> > of a type is non-NULL and this goof causes crashing on this >> >> > testcase. >> >> > >> >> > Bootstrapped/regtested on x86_64-linux, ok for trunk? >> >> > >> >> > 2017-08-07 Marek Polacek >> >> > >> >> > PR middle-end/81737 >> >> > * fold-const.c (fold_indirect_ref_1): Check type_domain. >> >> > >> >> > * gcc.dg/pr81737.c: New test. >> >> >> >> The old code was assuming size_zero_node if type_domain is NULL >> >> or TYPE_MIN_VALUE is NULL, which is reasonable for C/C++, but indeed >> >might >> >> be wrong perhaps for Fortran or Ada. >> >> It's how the middle-end defines it, so please restore this behavior (sorry for missing this in the review). IIRC there are at least one other 'copy' of the folding somewhere. > > Sure, this patch should do it: > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > 2017-08-08 Marek Polacek > > PR middle/81695 > * fold-const.c (fold_indirect_ref_1): Restore original behavior > regarding size_zero_node. > > diff --git gcc/fold-const.c gcc/fold-const.c > index 5a118ca50a1..2c47d1d16a4 100644 > --- gcc/fold-const.c > +++ gcc/fold-const.c > @@ -14109,22 +14109,21 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0) > && type == TREE_TYPE (op00type)) > { > tree type_domain = TYPE_DOMAIN (op00type); > - tree min; > + tree min = size_zero_node; > if (type_domain != NULL_TREE > - && (min = TYPE_MIN_VALUE (type_domain)) > + && TYPE_MIN_VALUE (type_domain) > && TREE_CODE (min) == INTEGER_CST) > + min = TYPE_MIN_VALUE (type_domain); I think this is wrong for non-INTEGER_CST TYPE_MIN_VALUE. Richard. > + offset_int off = wi::to_offset (op01); > + offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type)); > + offset_int remainder; > + off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder); > + if (remainder == 0) > { > - offset_int off = wi::to_offset (op01); > - offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type)); > - offset_int remainder; > - off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder); > - if (remainder == 0) > - { > - off = off + wi::to_offset (min); > - op01 = wide_int_to_tree (sizetype, off); > - return build4_loc (loc, ARRAY_REF, type, op00, op01, > - NULL_TREE, NULL_TREE); > - } > + off = off + wi::to_offset (min); > + op01 = wide_int_to_tree (sizetype, off); > + return build4_loc (loc, ARRAY_REF, type, op00, op01, > + NULL_TREE, NULL_TREE); > } > } > } > > Marek