From patchwork Mon Aug 29 20:28:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 112127 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]) by ozlabs.org (Postfix) with SMTP id 8764AB6F92 for ; Tue, 30 Aug 2011 06:28:21 +1000 (EST) Received: (qmail 22969 invoked by alias); 29 Aug 2011 20:28:18 -0000 Received: (qmail 22953 invoked by uid 22791); 29 Aug 2011 20:28:17 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-yw0-f47.google.com (HELO mail-yw0-f47.google.com) (209.85.213.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 29 Aug 2011 20:28:03 +0000 Received: by ywa12 with SMTP id 12so5162924ywa.20 for ; Mon, 29 Aug 2011 13:28:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.91.3 with SMTP id o3mr2492479ybb.349.1314649682669; Mon, 29 Aug 2011 13:28:02 -0700 (PDT) Received: by 10.146.82.19 with HTTP; Mon, 29 Aug 2011 13:28:02 -0700 (PDT) Date: Mon, 29 Aug 2011 22:28:02 +0200 Message-ID: Subject: [Patch, Fortran, OOP] PR 50225: The allocation status for polymorphic allocatable function results is not set properly From: Janus Weil To: gfortran , gcc-patches 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 Hi all, here is a relatively simple patch which fixes the PR in the subject line. The problem was: For functions with polymorphic allocatable result, the result variable was not nullified at the start. The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk? Cheers, Janus 2011-08-29 Janus Weil PR fortran/50225 * trans-decl.c (gfc_generate_function_code): Nullify polymorphic allocatable function results. 2011-08-29 Janus Weil PR fortran/50225 * gfortran.dg/class_result_1.f03: New. Index: gcc/fortran/trans-decl.c =================================================================== --- gcc/fortran/trans-decl.c (revision 178253) +++ gcc/fortran/trans-decl.c (working copy) @@ -5215,17 +5215,25 @@ gfc_generate_function_code (gfc_namespace * ns) { tree result = get_proc_result (sym); - if (result != NULL_TREE - && sym->attr.function - && !sym->attr.pointer) + if (result != NULL_TREE && sym->attr.function && !sym->attr.pointer) { if (sym->attr.allocatable && sym->attr.dimension == 0 && sym->result == sym) gfc_add_modify (&init, result, fold_convert (TREE_TYPE (result), null_pointer_node)); + else if (sym->ts.type == BT_CLASS + && CLASS_DATA (sym)->attr.allocatable + && sym->attr.dimension == 0 && sym->result == sym) + { + tmp = CLASS_DATA (sym)->backend_decl; + tmp = fold_build3_loc (input_location, COMPONENT_REF, + TREE_TYPE (tmp), result, tmp, NULL_TREE); + gfc_add_modify (&init, tmp, fold_convert (TREE_TYPE (tmp), + null_pointer_node)); + } else if (sym->ts.type == BT_DERIVED - && sym->ts.u.derived->attr.alloc_comp - && !sym->attr.allocatable) + && sym->ts.u.derived->attr.alloc_comp + && !sym->attr.allocatable) { rank = sym->as ? sym->as->rank : 0; tmp = gfc_nullify_alloc_comp (sym->ts.u.derived, result, rank);