From patchwork Fri Feb 1 18:15:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Richard Thomas X-Patchwork-Id: 1035047 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-495096-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="O55heegf"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HGfz/C7P"; dkim-atps=neutral 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 43rldx1Dstz9s6w for ; Sat, 2 Feb 2019 05:15:48 +1100 (AEDT) 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:from:date:message-id:subject:to:content-type; q= dns; s=default; b=VPljlRfuhRNkzLNDbeDj2pInQYteLltXYP5jygHzrC6aWc ivG7r7FvxjEHDZEW4wr6oRrmHJh5IZtLsz3WPAn4Xda/EVhqyFuV2j7jp/dH5NXu r70KS3IxKBJ7OIxaR2TVi1JhBfWGMsrYuocpmOEFSbioAwFGZdt/TtwLrKca8= 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:from:date:message-id:subject:to:content-type; s= default; bh=t0vCVmCYJhW7pXCluQjs90JxKvU=; b=O55heegfVQrZ1nG1+RfO SJvC1LN0eJvBdE+7ujg+peP7GK695SndBpIBMccWqJ2h2/SQpXIHHEv2kGBRjyt+ HsYDclM5keKCgvhe9WACb6lhv8XC426HJIXX9FzQWYNS0Mv9k1m+GVnw6NiYvq4C IOwhsJ/1RLDFmOFDaLKri6A= Received: (qmail 37014 invoked by alias); 1 Feb 2019 18:15:37 -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 36994 invoked by uid 89); 1 Feb 2019 18:15:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=tomorrow X-HELO: mail-lf1-f49.google.com Received: from mail-lf1-f49.google.com (HELO mail-lf1-f49.google.com) (209.85.167.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 01 Feb 2019 18:15:35 +0000 Received: by mail-lf1-f49.google.com with SMTP id p6so5782233lfc.1; Fri, 01 Feb 2019 10:15:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=Wxx65DjUHTGU3g0EFizDoqwN4GZRvO1N7oS2thUtb/8=; b=HGfz/C7P4kZYK+AYNpauaTWosi/18OYb36m6o+3j+efq5hKVMFePDRkBSWstTcYhcs OCCRxM6yItYfpaA06Y3/bIsQ1yQxPlhiC2ol2j75ML5BrbiWln3Fb/PgFFzOFBkf2xRX QLCjMMjPUMjp1am/bFgYtNJq7HcKMWcMEllrvai4GsFuzGiFMNkurISEHmjHzRnLlS7M kEK2PmOAr01i9NU158nyOCfVDLGgD4Gfu7qPb+viSJZHUSk5DC/wBtG0pLOhjYsTzcWP Am/fZGVoQxfaBv4ftiCySb0c30sw4pRaV53GtdXZ1lKOgrtEWeeBayHMQoq/hGJ3Qqb2 zfhQ== MIME-Version: 1.0 From: Paul Richard Thomas Date: Fri, 1 Feb 2019 18:15:21 +0000 Message-ID: Subject: [Patch, fortran] PR88393 - [7/8/9 Regression] [OOP] Segfault with type-bound assignment To: "fortran@gcc.gnu.org" , gcc-patches I will commit this patch as 'obvious' tomorrow. Cheers Paul 2019-02-01 Paul Thomas PR fortran/88393 * trans-expr.c (gfc_conv_procedure_call): For derived entities, passed in parentheses to class formals, invert the order of copying allocatable components to taking taking the _data of the class expression. 2019-02-01 Paul Thomas PR fortran/88393 * gfortran.dg/alloc_comp_assign_16.f03 : New test. Index: gcc/fortran/trans-expr.c =================================================================== *** gcc/fortran/trans-expr.c (revision 268231) --- gcc/fortran/trans-expr.c (working copy) *************** gfc_conv_procedure_call (gfc_se * se, gf *** 6042,6047 **** --- 6042,6057 ---- break; } + if (e->ts.type == BT_DERIVED && fsym && fsym->ts.type == BT_CLASS) + { + /* The derived type is passed to gfc_deallocate_alloc_comp. + Therefore, class actuals can handled correctly but derived + types passed to class formals need the _data component. */ + tmp = gfc_class_data_get (tmp); + if (!CLASS_DATA (fsym)->attr.dimension) + tmp = build_fold_indirect_ref_loc (input_location, tmp); + } + if (e->expr_type == EXPR_OP && e->value.op.op == INTRINSIC_PARENTHESES && e->value.op.op1->expr_type == EXPR_VARIABLE) *************** gfc_conv_procedure_call (gfc_se * se, gf *** 6053,6068 **** gfc_add_expr_to_block (&se->post, local_tmp); } - if (e->ts.type == BT_DERIVED && fsym && fsym->ts.type == BT_CLASS) - { - /* The derived type is passed to gfc_deallocate_alloc_comp. - Therefore, class actuals can handled correctly but derived - types passed to class formals need the _data component. */ - tmp = gfc_class_data_get (tmp); - if (!CLASS_DATA (fsym)->attr.dimension) - tmp = build_fold_indirect_ref_loc (input_location, tmp); - } - if (!finalized && !e->must_finalize) { if ((e->ts.type == BT_CLASS --- 6063,6068 ---- Index: gcc/testsuite/gfortran.dg/alloc_comp_assign_16.f03 =================================================================== *** gcc/testsuite/gfortran.dg/alloc_comp_assign_16.f03 (nonexistent) --- gcc/testsuite/gfortran.dg/alloc_comp_assign_16.f03 (working copy) *************** *** 0 **** --- 1,37 ---- + ! { dg-do run } + ! + ! Test the fix for PR88393 in which a segfault occurred as indicated. + ! + ! Contributed by Janus Weil + ! + module m + implicit none + type :: t + character(len=:), allocatable :: cs + contains + procedure :: ass + generic :: assignment(=) => ass + end type + contains + subroutine ass(a, b) + class(t), intent(inout) :: a + class(t), intent(in) :: b + a%cs = b%cs + print *, "ass" + end subroutine + end module + + program p + use m + implicit none + type :: t2 + type(t) :: c + end type + type(t2), dimension(1:2) :: arr + arr(1)%c%cs = "abcd" + arr(2)%c = arr(1)%c ! Segfault here. + print *, "done", arr(2)%c%cs, arr(2)%c%cs + ! Make sure with valgrind that there are no memory leaks. + deallocate (arr(1)%c%cs) + deallocate (arr(2)%c%cs) + end