From patchwork Mon Dec 12 23:30:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 705210 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 3tczbs6jgTz9t10 for ; Tue, 13 Dec 2016 10:30:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="t/O5B/CT"; 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:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=x2rSW55v2KneiQJ mX/CwbJ9oNRgsikumuvTR7c4kY15ZuE72Re+Q/RBJmDyxg+6c7wm7LHiVT2Uilu+ L6qJli9hSh15fHkuHMb/DmRcJsSdyLtV4ncCv5KloYBn8zzwqiE2CYbB74qV6xvN yy/5BQ/sE9jwtgcem8IW1QVk+nTo= 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:from:date:message-id :subject:to:cc:content-type; s=default; bh=OJfiW7BQ7goPfEPhhQX16 rwSxpE=; b=t/O5B/CTPc3rYAYMlvu0WSRanAMMTuvV/n9hbZyxmydyfj4AkymV2 Lu14BBOtHTBaMLMVuMo2GbR44OeSgksYIegyg/xSs+k4OkhbkxC+IpB4Pi4j4Kz3 qebapq8YKYi77TVkO/e1Sih21oorNytaSwibUWSlPEqasYX0YLBMsk= Received: (qmail 56872 invoked by alias); 12 Dec 2016 23:30:39 -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 56711 invoked by uid 89); 12 Dec 2016 23:30:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.6 required=5.0 tests=AWL, BAYES_50, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=no version=3.3.2 spammy=PR78737, H*f:sk:CAGkQGi, interfacec, UD:interface.c X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-yb0-f196.google.com Received: from mail-yb0-f196.google.com (HELO mail-yb0-f196.google.com) (209.85.213.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Dec 2016 23:30:18 +0000 Received: by mail-yb0-f196.google.com with SMTP id d128so763392ybh.3; Mon, 12 Dec 2016 15:30:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=xTBaPabQN5DIT9sWm0Ymakv0tOEpFqkCjyvLp+bnIps=; b=Hgpqm+xyDws9OayMQw5HKKfbLZVtlQK5mP8guV+/Mc+LpBkzTqg0t3pnyuySI++/yq lR4Ls5C0AXOHuy9Cpq1cwo4UxVnxEePmzmuyprJurAjyyrmQdyIB2y7gm90oB/rgGqFt APglXh4cPr0MRkcWvXNmmxBidwu/aKeitWpmH4bRDXM8z8v1V/Uw6pbqsrWhI8hclS1x IYDrfPJcY2IR/GTem/BcCQAl06MjzUPPGjuY8qK9GmoRSWYNJxreJTheueo+qbcQGAvR nEYdLLwK3FWBTaEQy5zpTUeSn4rZ/TiLAkXOauwzoFnBqjmxv9LFEZMonmo/rOOfMQ8B pE+g== X-Gm-Message-State: AKaTC03l3z0QJiyUaMsilTBqTA6NYG8DmIOVhWDTyhCTgbOzellnUaP178bI6nTqsU57Tq9b6CNm9kZ3IjPK0A== X-Received: by 10.37.211.2 with SMTP id e2mr12332276ybf.149.1481585414849; Mon, 12 Dec 2016 15:30:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.129.51.145 with HTTP; Mon, 12 Dec 2016 15:30:14 -0800 (PST) In-Reply-To: References: From: Janus Weil Date: Tue, 13 Dec 2016 00:30:14 +0100 Message-ID: Subject: Re: [Patch, fortran] PR78737 - [OOP] linking error with deferred, undefined user-defined derived-type I/O To: Paul Richard Thomas Cc: "fortran@gcc.gnu.org" , gcc-patches , Damian Rouson Hi Paul, hi all, 2016-12-12 21:04 GMT+01:00 Janus Weil : > As commented several times in bugzilla, my feeling is that the > solution for this PR would be to utilize the vtable machinery, in > order to generate a truly polymorphic call to the DTIO procedure. in order to elaborate what I have in mind, I'm attaching a draft patch which implements polymorphic DTIO in the most straightforward manner I could come up with. I have not regtested it yet, but at least it removes the link failure on comment 0 and 6 in the PR and most importantly it generates the correct output for comment 18, which none of the previous attempts have accomplished. I'd be grateful for any comments, in particular whether I'm on the right track here or whether I'm misinterpreting the F03 standard in any way ... (Btw, it seems that Paul's dtio_20.f90 works already on current trunk, so it's not very well suited to test for the problem at hand.) Cheers, Janus PS: A quick check of the dtio_* tests shows ICEs on dtio_7.f90 and dtio_13.f90. I'll look into those tomorrow. Index: gcc/fortran/gfortran.h =================================================================== --- gcc/fortran/gfortran.h (revision 243580) +++ gcc/fortran/gfortran.h (working copy) @@ -3252,6 +3252,7 @@ int gfc_has_vector_subscript (gfc_expr*); gfc_intrinsic_op gfc_equivalent_op (gfc_intrinsic_op); bool gfc_check_typebound_override (gfc_symtree*, gfc_symtree*); void gfc_check_dtio_interfaces (gfc_symbol*); +gfc_symtree* gfc_find_typebound_dtio_proc (gfc_symbol *, bool, bool); gfc_symbol* gfc_find_specific_dtio_proc (gfc_symbol*, bool, bool); Index: gcc/fortran/interface.c =================================================================== --- gcc/fortran/interface.c (revision 243580) +++ gcc/fortran/interface.c (working copy) @@ -4826,13 +4826,10 @@ gfc_check_dtio_interfaces (gfc_symbol *derived) } -gfc_symbol * -gfc_find_specific_dtio_proc (gfc_symbol *derived, bool write, bool formatted) +gfc_symtree* +gfc_find_typebound_dtio_proc (gfc_symbol *derived, bool write, bool formatted) { gfc_symtree *tb_io_st = NULL; - gfc_symbol *dtio_sub = NULL; - gfc_symbol *extended; - gfc_typebound_proc *tb_io_proc, *specific_proc; bool t = false; if (!derived || derived->attr.flavor != FL_DERIVED) @@ -4869,7 +4866,20 @@ gfc_check_dtio_interfaces (gfc_symbol *derived) true, &derived->declared_at); } + return tb_io_st; +} + +gfc_symbol * +gfc_find_specific_dtio_proc (gfc_symbol *derived, bool write, bool formatted) +{ + gfc_symtree *tb_io_st = NULL; + gfc_symbol *dtio_sub = NULL; + gfc_symbol *extended; + gfc_typebound_proc *tb_io_proc, *specific_proc; + + tb_io_st = gfc_find_typebound_dtio_proc (derived, write, formatted); + if (tb_io_st != NULL) { const char *genname; Index: gcc/fortran/trans-io.c =================================================================== --- gcc/fortran/trans-io.c (revision 243580) +++ gcc/fortran/trans-io.c (working copy) @@ -2181,16 +2181,36 @@ get_dtio_proc (gfc_typespec * ts, gfc_code * code, } if (ts->type == BT_DERIVED) - derived = ts->u.derived; - else - derived = ts->u.derived->components->ts.u.derived; + { + derived = ts->u.derived; + *dtio_sub = gfc_find_specific_dtio_proc (derived, last_dt == WRITE, + formatted); - *dtio_sub = gfc_find_specific_dtio_proc (derived, last_dt == WRITE, - formatted); + if (*dtio_sub) + return gfc_build_addr_expr (NULL, gfc_get_symbol_decl (*dtio_sub)); + } + else if (ts->type == BT_CLASS) + { + gfc_expr *expr = gfc_copy_expr(code->expr1); + gfc_add_vptr_component (expr); - if (*dtio_sub) - return gfc_build_addr_expr (NULL, gfc_get_symbol_decl (*dtio_sub)); + derived = ts->u.derived->components->ts.u.derived; + gfc_symtree *tb_io_st = gfc_find_typebound_dtio_proc (derived, + last_dt == WRITE, formatted); + if (tb_io_st) + { + gfc_se se; + gfc_init_se (&se, NULL); + se.want_pointer = 1; + gfc_add_component_ref (expr, + tb_io_st->n.tb->u.generic->specific_st->name); + *dtio_sub = tb_io_st->n.tb->u.generic->specific->u.specific->n.sym; + gfc_conv_expr (&se, expr); + return se.expr; + } + } + return NULL_TREE; }