From patchwork Fri Dec 19 12:39:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 422869 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 7578E140079 for ; Fri, 19 Dec 2014 23:39:58 +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:date:message-id:subject:from:to:content-type; q= dns; s=default; b=j8SIHgLCY6lDGf/smrV+/N7GddB11/JGetY/5XoUe7O10A H+PhbH6RE7tQw8NSjikspixuFA1fjBDb3n6Rh2QtDLPzPkGovhz/yN47assR8KcY Vz8WZ0jGMFoIJ5gErJojwqRD9Fhm33zcxrY5PrHIqTls68WR04nfkHN1Xfkx0= 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=YUrKcTbnV4D0inlav5wKRHvAO+Q=; b=Q/gXtdMwDg+xqyUHpBUl jlnHFc8ZjZWuHj7gAnSsXh/+9ISRToSFL6iAASHSersn3S7CGc2fvmrUN4u2ADqY Av8zYFD3vKoJkcDJZZ/otrjh+zWZQAATW33Y+/2hM6UlIKc5ON38RGafAv5yphD1 9GFpM2rDcM++l9QrU42u5eI= Received: (qmail 16957 invoked by alias); 19 Dec 2014 12:39:50 -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 16939 invoked by uid 89); 19 Dec 2014 12:39:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-qa0-f44.google.com Received: from mail-qa0-f44.google.com (HELO mail-qa0-f44.google.com) (209.85.216.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 19 Dec 2014 12:39:48 +0000 Received: by mail-qa0-f44.google.com with SMTP id bm13so538694qab.17; Fri, 19 Dec 2014 04:39:46 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.224.65.134 with SMTP id j6mr13114007qai.90.1418992786266; Fri, 19 Dec 2014 04:39:46 -0800 (PST) Received: by 10.96.211.7 with HTTP; Fri, 19 Dec 2014 04:39:46 -0800 (PST) Date: Fri, 19 Dec 2014 13:39:46 +0100 Message-ID: Subject: [Patch, Fortran, OOP] PR 64209: runtime segfault with CLASS(*), INTENT(OUT) dummy argument From: Janus Weil To: gfortran , gcc-patches Hi all, the attached patch fixes a wrong-code issue with unlimited poylmorphic INTENT(OUT) arguments. We default-initialize all polymorphic INTENT(OUT) arguments via the _def_init component of the vtable. The problem is that the intrinsic types don't have a default initialization. Therefore their _def_init is NULL and we simply failed to check for that condition. That's what the patch does. It regtests cleanly on x86_64-unknown-linux-gnu. Ok for trunk? Cheers, Janus 2014-12-19 Janus Weil PR fortran/64209 * trans-expr.c (gfc_trans_class_array_init_assign): Check if _def_init component is non-NULL. (gfc_trans_class_init_assign): Ditto. 2014-12-19 Janus Weil PR fortran/64209 * gfortran.dg/unlimited_polymorphic_19.f90: New. Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (Revision 218896) +++ gcc/fortran/trans-expr.c (Arbeitskopie) @@ -912,7 +912,8 @@ gfc_trans_class_array_init_assign (gfc_expr *rhs, gfc_actual_arglist *actual; gfc_expr *ppc; gfc_code *ppc_code; - tree res; + tree res, cond; + gfc_se src; actual = gfc_get_actual_arglist (); actual->expr = gfc_copy_expr (rhs); @@ -932,6 +933,16 @@ gfc_trans_class_array_init_assign (gfc_expr *rhs, of arrays in gfc_trans_call. */ res = gfc_trans_call (ppc_code, false, NULL, NULL, false); gfc_free_statements (ppc_code); + + gfc_init_se (&src, NULL); + gfc_conv_expr (&src, rhs); + src.expr = gfc_build_addr_expr (NULL_TREE, src.expr); + cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node, + src.expr, fold_convert (TREE_TYPE (src.expr), + null_pointer_node)); + res = build3_loc (input_location, COND_EXPR, TREE_TYPE (res), cond, res, + build_empty_stmt (input_location)); + return res; } @@ -943,7 +954,7 @@ tree gfc_trans_class_init_assign (gfc_code *code) { stmtblock_t block; - tree tmp; + tree tmp, cond; gfc_se dst,src,memsz; gfc_expr *lhs, *rhs, *sz; @@ -980,6 +991,12 @@ gfc_trans_class_init_assign (gfc_code *code) src.expr = gfc_build_addr_expr (NULL_TREE, src.expr); tmp = gfc_build_memcpy_call (dst.expr, src.expr, memsz.expr); + + cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node, + src.expr, fold_convert (TREE_TYPE (src.expr), + null_pointer_node)); + tmp = build3_loc (input_location, COND_EXPR, TREE_TYPE (tmp), cond, tmp, + build_empty_stmt (input_location)); } if (code->expr1->symtree->n.sym->attr.optional