From patchwork Fri May 13 00:13:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fritz Reese X-Patchwork-Id: 621776 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 3r5Vhs16s8z9vKT for ; Fri, 13 May 2016 10:14:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=i2coPudg; 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 :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=Kttc0Vr808Vdb17d0n7TwGj7MoGxmk2037UUCN140621+i Ppygz9x3kZMPZokMa4LBRsG6HxEcVDTLIxWPyGWbpLhubqRfdFCuTiJBRoNQ92io Ffc0DSMa1BAo2i6db2euygf1QouPjEHOxsFcNuY54bBaL7g9wCuIhCH0ZcEoQ= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=Z6v4pE5FN/A1d0hLPL5xphTvR4Y=; b=i2coPudgCQnp41usKaHz 8nDO98Vga8IJXAf+az8RHV43Ar8q2j9WGg/0R0WRKiJoKklP1Z12fYKZyTyG3rvW SYEwm1hLN3GTDp3sQNAQaf+S2LeXXMxRE8v/EIi2FFgwD5RH8LXfbHQWLi7bKbJw r24abtdrvzT++9qPl+F1hKM= Received: (qmail 6420 invoked by alias); 13 May 2016 00:14:01 -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 6390 invoked by uid 89); 13 May 2016 00:14:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=extraneous, U*fritzoreese, sk:fritzor, yx X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-oi0-f68.google.com Received: from mail-oi0-f68.google.com (HELO mail-oi0-f68.google.com) (209.85.218.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 13 May 2016 00:13:50 +0000 Received: by mail-oi0-f68.google.com with SMTP id t140so1529714oie.0; Thu, 12 May 2016 17:13:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=qFFz72htHpubUwIkgZzkoKm75GMSellsOJIrtb9g5f4=; b=ITCUwjjReMxEwtbsQiIxwcDgFTJ2igRaCS1OwrIDYZT6mwqI+wy1XFtweoTF899jVS lge36LX2VoFirSkI4sfQcmGb4GzoMucVkiw+sPoEsrZfgD/DWMmB+BOsoeHVrdlZA9Q+ 4UpA+AY95riAmMsg3wTR3GmP2p8vo3jASJkRA0oSswfr48GZuqYbhChSWj1PvP7fNBfg HTSsER6ub17MT6ecpSvqqHvTfcWyutUDoKGvAj2aH5b7T9zgk2XjwGhGxGj0o+xO1nmP ssyOYVNzI3PKhb5KQcwb7v+x1cqp9ktfiCMd4RBpopn52yO0CQUtan8VheysLvokJZ63 S+YQ== X-Gm-Message-State: AOPr4FVEqN/dQT5a3lImDiwmAwYMlFXFt+RjD2Ti2yIApFN9nB06wsmVwG4xkFYMyCUKEi3ihu5PcOYB/7MUVA== MIME-Version: 1.0 X-Received: by 10.157.24.41 with SMTP id b38mr6703815ote.190.1463098428631; Thu, 12 May 2016 17:13:48 -0700 (PDT) Received: by 10.182.39.161 with HTTP; Thu, 12 May 2016 17:13:48 -0700 (PDT) Date: Thu, 12 May 2016 20:13:48 -0400 Message-ID: Subject: [Patch, Fortran] Fix PR 71047 From: Fritz Reese To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Here's the fix and a test case for the regression PR 71047 introduced by the DEC STRUCTURE/UNION patch (commit 235999). Turns out I was a bit greedy about adding component refs to structure constructors in gfc_default_initializer. Fixed to only add them to FL_STRUCTURE and FL_UNION symbols, which expect them during translation. The component ref was being added to constructors for the hidden _data and _vptr members of CLASS components, causing the code for their real initialization to be skipped by the middle-end. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71047 --- Fritz Reese From f1ee9fb07728f69631f9795ba01b590d2277b6f3 Mon Sep 17 00:00:00 2001 From: Fritz O. Reese Date: Thu, 12 May 2016 18:04:15 -0400 Subject: [PATCH] Remove extraneous component refs from derived type constructors. gcc/fortran/ PR fortran/71047 * expr.c (gfc_default_initializer): Avoid extra component refs in constructors for derived types and classes. gcc/testsuite/gfortran.dg/ PR fortran/71047 * pr71047.f08: New test. --- gcc/fortran/expr.c | 5 +++- gcc/testsuite/gfortran.dg/pr71047.f08 | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr71047.f08 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 6ebe08b..816ef01 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -3975,7 +3975,10 @@ gfc_default_initializer (gfc_typespec *ts) if (comp->initializer) { - ctor->n.component = comp; + // Save the component ref for STRUCTUREs and UNIONs. + if (ts->u.derived->attr.flavor == FL_STRUCT + || ts->u.derived->attr.flavor == FL_UNION) + ctor->n.component = comp; ctor->expr = gfc_copy_expr (comp->initializer); if ((comp->ts.type != comp->initializer->ts.type || comp->ts.kind != comp->initializer->ts.kind) diff --git a/gcc/testsuite/gfortran.dg/pr71047.f08 b/gcc/testsuite/gfortran.dg/pr71047.f08 new file mode 100644 index 0000000..61a0ad4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr71047.f08 @@ -0,0 +1,48 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original" } +! +! Fortran/PR71047 +! + +module m + implicit none + + type, abstract :: c_abstr + integer :: i = 0 + end type c_abstr + + type, extends(c_abstr) :: t_a + class(c_abstr), allocatable :: f + end type t_a + + type, extends(c_abstr) :: t_b + end type t_b + +contains + + subroutine set(y,x) + class(c_abstr), intent(in) :: x + type(t_a), intent(out) :: y + allocate( y%f , source=x ) + end subroutine set + +end module m + + +program p + use m + implicit none + + type(t_a) :: res + type(t_b) :: var + + call set( res , var ) + write(*,*) res%i + +end program p + +! +! Check to ensure the vtable is actually initialized. +! +! { dg-final { scan-tree-dump "t_a\\.\\d+\\.f\\._vptr =" "original" } } +! -- 1.7.1