From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15295 invoked by alias); 26 Nov 2015 16:19:06 -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 15274 invoked by uid 89); 26 Nov 2015 16:19:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS 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; Thu, 26 Nov 2015 16:19:05 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id DCCB3C0B7ABC; Thu, 26 Nov 2015 16:19:03 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAQGJ2kQ023681 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 26 Nov 2015 11:19:03 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id tAQGJ0v1006465; Thu, 26 Nov 2015 17:19:00 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id tAQGIv5t006429; Thu, 26 Nov 2015 17:18:57 +0100 Date: Thu, 26 Nov 2015 16:20:00 -0000 From: Jakub Jelinek To: Marek Polacek Cc: Joseph Myers , GCC Patches , Richard Biener Subject: Re: [PATCH] Fix pattern causing C_MAYBE_CONST_EXPRs leak into gimplifier (PR c/68513) Message-ID: <20151126161857.GG5675@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20151125143509.GU21807@redhat.com> <20151125144620.GY5675@tucnak.redhat.com> <20151126111547.GX21807@redhat.com> <20151126161026.GY21807@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151126161026.GY21807@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg03267.txt.bz2 On Thu, Nov 26, 2015 at 05:10:26PM +0100, Marek Polacek wrote: > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > 2015-11-26 Marek Polacek > > PR c/68513 > * c-gimplify.c (strip_c_maybe_const_expr_r): New. > (c_gimplify_expr): Call it. > > * gcc.dg/torture/pr68513.c: New test. > > diff --git gcc/c-family/c-gimplify.c gcc/c-family/c-gimplify.c > index fc4a44a..c096575 100644 > --- gcc/c-family/c-gimplify.c > +++ gcc/c-family/c-gimplify.c > @@ -212,6 +212,21 @@ c_build_bind_expr (location_t loc, tree block, tree body) > > /* Gimplification of expression trees. */ > > +/* Callback for c_gimplify_expr. Strip C_MAYBE_CONST_EXPRs in TP so that > + they don't leak into the middle end. */ > + > +static tree > +strip_c_maybe_const_expr_r (tree *tp, int *walk_subtrees, void *) > +{ > + if (TREE_CODE (*tp) == C_MAYBE_CONST_EXPR) > + { > + gcc_assert (C_MAYBE_CONST_EXPR_PRE (*tp) == NULL_TREE); > + *tp = C_MAYBE_CONST_EXPR_EXPR (*tp); > + *walk_subtrees = 0; > + } > + return NULL_TREE; > +} > + > /* Do C-specific gimplification on *EXPR_P. PRE_P and POST_P are as in > gimplify_expr. */ > > @@ -296,6 +311,10 @@ c_gimplify_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED, > return (enum gimplify_status) gimplify_cilk_spawn (expr_p); > } > > + case SAVE_EXPR: > + walk_tree_without_duplicates (expr_p, strip_c_maybe_const_expr_r, NULL); Shouldn't this be done only if (!SAVE_EXPR_RESOLVED_P (*expr_p))? Otherwise I fear bad compile time complexity, consider huge tree containing lots of nested SAVE_EXPRs and every SAVE_EXPR appearing twice or more times somewhere in the tree. Perhaps the walk should also *walk_subtrees = 0; for SAVE_EXPRs and start walking &TREE_OPERAND (*expr_p, 0) instead of expr_p. The nested SAVE_EXPRs would be handled when those are gimplified. Jakub