From patchwork Thu Apr 28 12:10:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 616168 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 3qwbJf00J6z9t74 for ; Thu, 28 Apr 2016 22:10:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=wYDcD+K1; 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:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=tW48gssNS/q5sKoH zyd0p9cY/Tcr8RSzaVG4dy2FXZDWFpWn2GjFzyM71DgHvQ8T8DtjIQ023PkqlvOd mo6/R7whGWH45MwSzWpVarVga6icBHgGstaengXXnoBivk9yiq05m4Sm942SiGk5 5+1PHdoUi5Dl+J0wlhoY9xAN7II= 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:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=hA23i4ZPK42WGe4dWk7zOE jiZKM=; b=wYDcD+K1D7bfBo0dkyiWBEeikMWyrIqZQRbQYhp1TEFeBjPZrvg6eq fznhtId685GnavrkEwwVb7OCvhlezO7BYhrFkD30hgsuLTevnXbekfkSdx/Zrqk+ SjYrYAxbBjHfKzKDtb3Q2akHC9CnAzIeQ2A0gA7J+kwlQUCT6H4pE= Received: (qmail 49815 invoked by alias); 28 Apr 2016 12:10:46 -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 49503 invoked by uid 89); 28 Apr 2016 12:10:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=Fill, dtype, late X-Spam-User: qpsmtpd, 2 recipients 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; Thu, 28 Apr 2016 12:10:36 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BACC0ABDD; Thu, 28 Apr 2016 12:10:30 +0000 (UTC) Date: Thu, 28 Apr 2016 14:10:32 +0200 (CEST) From: Richard Biener To: Eric Botcazou cc: gcc-patches@gcc.gnu.org, jason@redhat.com, fortran@gcc.gnu.org Subject: Re: [PATCH] Fix type field walking in gimplifier unsharing In-Reply-To: Message-ID: References: <1563866.3PAXIoXYk7@polaris> <3302327.fD05QFZoa0@polaris> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 On Thu, 28 Apr 2016, Richard Biener wrote: > On Thu, 28 Apr 2016, Eric Botcazou wrote: > > > > Aww, I was hoping for sth that would not require me to fix all > > > frontends ... > > > > I don't really see how this can work without DECL_EXPR though. You need to > > define when the variable-sized expressions are evaluated to lay out the type, > > otherwise it will be laid out on the first use, which may see a different > > value of the expressions than the definition point. The only way to do that > > for a locally-defined type is to add a DECL_EXPR in GENERIC, so that the > > gimplifier evaluates the expressions at the right spot. > > Ah, so the C++ FE does this correctly but in addition to that it has > > /* When the pointed-to type involves components of variable > size, > care must be taken to ensure that the size evaluation code is > emitted early enough to dominate all the possible later uses > and late enough for the variables on which it depends to have > been assigned. > > This is expected to happen automatically when the pointed-to > type has a name/declaration of it's own, but special > attention > is required if the type is anonymous. > ... > if (!TYPE_NAME (type) > && (decl_context == NORMAL || decl_context == FIELD) > && at_function_scope_p () > && variably_modified_type_p (type, NULL_TREE)) > /* Force evaluation of the SAVE_EXPR. */ > finish_expr_stmt (TYPE_SIZE (type)); > > so in this case the type doesn't have an associated TYPE_DECL and thus > we can't build a DECL_EXPR. To me the correct fix is then to > always force a TYPE_DECL for variable-modified types. > > Jason? The following works (for the testcase): I wonder if we can avoid allocating the TYPE_DECL by simply also allowing TREE_TYPE as operand of a DECL_EXPR (to avoid adding a 'TYPE_EXPR'). Richard. Index: gcc/cp/decl.c =================================================================== --- gcc/cp/decl.c (revision 235547) +++ gcc/cp/decl.c (working copy) @@ -10393,8 +10393,11 @@ grokdeclarator (const cp_declarator *dec && (decl_context == NORMAL || decl_context == FIELD) && at_function_scope_p () && variably_modified_type_p (type, NULL_TREE)) - /* Force evaluation of the SAVE_EXPR. */ - finish_expr_stmt (TYPE_SIZE (type)); + { + TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, + NULL_TREE, type); + add_decl_expr (TYPE_NAME (type)); + } if (declarator->kind == cdk_reference) { and I have a similar fix for the Fortran FE for one testcase I reduced to character(10), dimension (2) :: implicit_result character(10), dimension (2) :: source implicit_result = reallocate_hnv (LEN (source)) contains FUNCTION reallocate_hnv(LEN) CHARACTER(LEN=LEN), DIMENSION(:), POINTER :: reallocate_hnv END FUNCTION reallocate_hnv end Index: fortran/trans-array.c =================================================================== --- fortran/trans-array.c (revision 235547) +++ fortran/trans-array.c (working copy) @@ -1094,6 +1094,16 @@ gfc_trans_create_temp_array (stmtblock_t info->descriptor = desc; size = gfc_index_one_node; + /* Emit a DECL_EXPR for the variable sized array type in + GFC_TYPE_ARRAY_DATAPTR_TYPE so the gimplification of its type + sizes works correctly. */ + tree arraytype = TREE_TYPE (GFC_TYPE_ARRAY_DATAPTR_TYPE (type)); + if (! TYPE_NAME (arraytype)) + TYPE_NAME (arraytype) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, + NULL_TREE, arraytype); + gfc_add_expr_to_block (pre, build1 (DECL_EXPR, + arraytype, TYPE_NAME (arraytype))); + /* Fill in the array dtype. */ tmp = gfc_conv_descriptor_dtype (desc); gfc_add_modify (pre, tmp, gfc_get_dtype (TREE_TYPE (desc)));