From patchwork Fri Dec 19 17:24:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 422959 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 C93D21400D2 for ; Sat, 20 Dec 2014 04:49:12 +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:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=YvYGZn/MV2nNSBjbej OQzpZssBAz1xTEYUDtLnp7vn3TsMyx9/avTStIfTUNxaxMCHyb9KgWcw+wETiBeh GZNJp0qU69yALxS3NraEzV+OWH/74H7selbJkNuqN19LnsH/CfFb2W3cV7IHI+FU fSwj+lG2wAQFyIGY3UGXXvhgw= 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:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=c4vCgR6MiKQIJaR2lWx//u57 NdY=; b=I15GmbcmiuI0XEVV00CwhNiPxAQp+kSD9nNeySllEkrA0Qz++76pkS6S SOOMLXWfEgKYCUgyZQvRHquV0y6sYnYuv0Qm2gyBwDtM0/OV1UOv9MLQM/NYMAHr J2Gz2wDsuYuuvBQR8+QRR1gri348FS+qHDs7w+JtOHGxRX1F4jE= Received: (qmail 2983 invoked by alias); 19 Dec 2014 17:24:58 -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 2953 invoked by uid 89); 19 Dec 2014 17:24:57 -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-qg0-f53.google.com Received: from mail-qg0-f53.google.com (HELO mail-qg0-f53.google.com) (209.85.192.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 19 Dec 2014 17:24:56 +0000 Received: by mail-qg0-f53.google.com with SMTP id l89so927977qgf.26; Fri, 19 Dec 2014 09:24:54 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.140.30.244 with SMTP id d107mr14670899qgd.70.1419009894548; Fri, 19 Dec 2014 09:24:54 -0800 (PST) Received: by 10.96.211.7 with HTTP; Fri, 19 Dec 2014 09:24:54 -0800 (PST) In-Reply-To: <20141219134850.GA19182@physik.fu-berlin.de> References: <20141219134850.GA19182@physik.fu-berlin.de> Date: Fri, 19 Dec 2014 18:24:54 +0100 Message-ID: Subject: Re: [Patch, Fortran, OOP] PR 64209: runtime segfault with CLASS(*), INTENT(OUT) dummy argument From: Janus Weil To: Tobias Burnus Cc: gcc-patches , gfortran 2014-12-19 14:48 GMT+01:00 Tobias Burnus : > As you write yourself, the issue can only occur for CLASS(*). Hence, > please apply this only for UNLIMITED_POLY() to avoid unneccessary code side > increase and performance decrease. Good point, thanks for reviewing. An updated patch is attached. Will commit after regtesting. Cheers, Janus Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (Revision 218957) +++ gcc/fortran/trans-expr.c (Arbeitskopie) @@ -932,6 +932,21 @@ 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); + + if (UNLIMITED_POLY(obj)) + { + /* Check if rhs is non-NULL. */ + gfc_se src; + gfc_init_se (&src, NULL); + gfc_conv_expr (&src, rhs); + src.expr = gfc_build_addr_expr (NULL_TREE, src.expr); + tree 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; } @@ -980,6 +995,17 @@ 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); + + if (UNLIMITED_POLY(code->expr1)) + { + /* Check if _def_init is non-NULL. */ + tree 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