From patchwork Sat Apr 18 16:48:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 462378 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 92D3914030B for ; Sun, 19 Apr 2015 02:49:13 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Tfu5+/0F; dkim-adsp=none (unprotected policy); 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 :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=tTyZAjw6xtLtFLf0BtiEXNZkZhBKbLQDOw9h6bKhMPYvdG fUqAOaFpdbJjZl8+rsRcPz9UjydM4vwopaNS1IFOkhAUjw1qn+tMKa7Md/rayStR 0v4afsJdzm89w1Jb/OjjDB+k19PBAfQw4CsUFtpexIe/zTvxOgrpIG81RoKDA= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=zDiJv0pm3d4+8DwtCAS1W6RttMk=; b=Tfu5+/0FeGyXUVR93V1C L5Hd0Bl0oia61YdC8w0eDZNmHXpPvInOG4dH7gQuozwN7icefahVpvJ/Vrme1I1F YHMEKZk9AJXK/qMK3vMcbiUX6NZimN1l6Aea64zPaTer2xXc1XGCjyI/AQDpaxFR 8FJVD0XLHNRVqGjmxur+PKc= Received: (qmail 47672 invoked by alias); 18 Apr 2015 16:49:00 -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 47645 invoked by uid 89); 18 Apr 2015 16:49:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: smtp24.services.sfr.fr Received: from smtp24.services.sfr.fr (HELO smtp24.services.sfr.fr) (93.17.128.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Sat, 18 Apr 2015 16:48:58 +0000 Received: from filter.sfr.fr (localhost [86.72.15.122]) by msfrf2403.sfr.fr (SMTP Server) with ESMTP id 422C470000A8; Sat, 18 Apr 2015 18:48:55 +0200 (CEST) Authentication-Results: sfrmc.priv.atos.fr; dkim=none (no signature); dkim-adsp=none (no policy) header.from=mikael.morin@sfr.fr Received: from tolstoi.localhost (122.15.72.86.rev.sfr.net [86.72.15.122]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by msfrf2403.sfr.fr (SMTP Server) with ESMTP id 1C9E570000A2; Sat, 18 Apr 2015 18:48:52 +0200 (CEST) X-SFR-UUID: 20150418164853117.1C9E570000A2@msfrf2403.sfr.fr Message-ID: <55328ADC.4020102@sfr.fr> Date: Sat, 18 Apr 2015 18:48:28 +0200 From: Mikael Morin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: gfortran , gcc-patches Subject: [Patch, fortran] PR65792 unitialized structure constructor array subcomponent X-IsSubscribed: yes Hello, here is a fix for PR65792 where a structure constructor used as actual argument was not fully initialized. The test looks like the following... type :: string_t character(LEN=1), dimension(:), allocatable :: chars end type string_t type :: string_container_t type(string_t) :: comp end type string_container_t type(string_t) :: prt_in [...] tmpc = new_prt_spec2 (string_container_t(prt_in)) The problem is in gfc_trans_subcomponent_assign, when initialising the component comp with prt_in: if (cm->ts.u.derived->attr.alloc_comp && expr->expr_type == EXPR_VARIABLE) { tmp = gfc_copy_alloc_comp (cm->ts.u.derived, se.expr, dest, expr->rank); gfc_add_expr_to_block (&block, tmp); } else gfc_add_modify (&block, dest, fold_convert (TREE_TYPE (dest), se.expr)); The if branch deep copies allocatable components, but does nothing for other components, which is the case here (the array elements are copied, not the array bounds). The patch proposed here for backport, moves the existing shallow copy out of the else branch. For trunk, I wanted to reuse gfc_trans_scalar_assign which has all the logic for copying stuff around. And as gfc_trans_scalar_assign is used as fallback a few lines down, I have tried to use that fallback. This change of control flow makes the patch a bit more risky, so I prefer to use the other variant for the branches. Setting the deep_copy argument of gfc_trans_scalar_assign to true is necessary so that gfc_copy_alloc_comp is called as before. Because of the branch the patch removes, I think the fallback code was unreachable for non-derived types, and for those the deep_copy flag was irrelevant anyway, so that that change should be rather harmless. Both patches have been regression tested on trunk on x86_64-linux. OK for trunk [first patch]? OK for 4.9 and 5 (after the 5.1 release) [second patch]? Mikael PS: Dominiq reported that the variant of this patch posted on the PR was also fixing PR49324. I couldn't confirm as what seems to be the remaining testcase there (comment #6) doesn't fail with trunk here. 2015-04-18 Mikael Morin PR fortran/65792 * trans-expr.c (gfc_trans_subcomponent_assign): Always (shallow) copy the subcomponent. 2015-04-18 Mikael Morin PR fortran/65792 * gfortran.dg/derived_constructor_comps_5.f90: New. Index: trans-expr.c =================================================================== --- trans-expr.c (révision 221972) +++ trans-expr.c (copie de travail) @@ -6915,6 +6935,8 @@ gfc_trans_subcomponent_assign (tree dest, gfc_comp gfc_init_se (&se, NULL); gfc_conv_expr (&se, expr); gfc_add_block_to_block (&block, &se.pre); + gfc_add_modify (&block, dest, + fold_convert (TREE_TYPE (dest), se.expr)); if (cm->ts.u.derived->attr.alloc_comp && expr->expr_type == EXPR_VARIABLE) { @@ -6922,9 +6944,6 @@ gfc_trans_subcomponent_assign (tree dest, gfc_comp dest, expr->rank); gfc_add_expr_to_block (&block, tmp); } - else - gfc_add_modify (&block, dest, - fold_convert (TREE_TYPE (dest), se.expr)); gfc_add_block_to_block (&block, &se.post); } else