From patchwork Tue Nov 8 10:51:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 124320 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 7FF521007D6 for ; Tue, 8 Nov 2011 21:51:30 +1100 (EST) Received: (qmail 32700 invoked by alias); 8 Nov 2011 10:51:22 -0000 Received: (qmail 32682 invoked by uid 22791); 8 Nov 2011 10:51:21 -0000 X-SWARE-Spam-Status: No, hits=0.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, KAM_STOCKTIP, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-gy0-f175.google.com (HELO mail-gy0-f175.google.com) (209.85.160.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Nov 2011 10:51:05 +0000 Received: by gyh4 with SMTP id 4so423964gyh.20 for ; Tue, 08 Nov 2011 02:51:04 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.174.105 with SMTP id w69mr41486780yhl.32.1320749464829; Tue, 08 Nov 2011 02:51:04 -0800 (PST) Received: by 10.147.137.17 with HTTP; Tue, 8 Nov 2011 02:51:04 -0800 (PST) Date: Tue, 8 Nov 2011 11:51:04 +0100 Message-ID: Subject: [Patch, Fortran, OOP] PR 50960: vtables not marked as constant 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, the attached patch marks the 'vtab' symbols as constant (FL_PARAMETER). They are fixed objects which are initialized once and never change. Regtested on x86_64-unknown-linux-gnu. Ok for trunk? Is it ok to commit without a test case? If not, any suggestions how a good test case could look like? Cheers, Janus 2011-11-08 Janus Weil PR fortran/50960 * class.c (gfc_find_derived_vtab): Make the vtab symbols FL_PARAMETER. * expr.c (gfc_simplify_expr): Prevent vtabs from being replaced with their value. * resolve.c (resolve_values): Use-associated symbols do not need to be resolved again. (resolve_fl_parameter): Make sure the symbol has a value. Index: gcc/fortran/class.c =================================================================== --- gcc/fortran/class.c (revision 181107) +++ gcc/fortran/class.c (working copy) @@ -428,7 +428,7 @@ gfc_find_derived_vtab (gfc_symbol *derived) { gfc_get_symbol (name, ns, &vtab); vtab->ts.type = BT_DERIVED; - if (gfc_add_flavor (&vtab->attr, FL_VARIABLE, NULL, + if (gfc_add_flavor (&vtab->attr, FL_PARAMETER, NULL, &gfc_current_locus) == FAILURE) goto cleanup; vtab->attr.target = 1; Index: gcc/fortran/expr.c =================================================================== --- gcc/fortran/expr.c (revision 181106) +++ gcc/fortran/expr.c (working copy) @@ -1883,7 +1883,8 @@ gfc_simplify_expr (gfc_expr *p, int type) initialization expression, or we want a subsection. */ if (p->symtree->n.sym->attr.flavor == FL_PARAMETER && (gfc_init_expr_flag || p->ref - || p->symtree->n.sym->value->expr_type != EXPR_ARRAY)) + || p->symtree->n.sym->value->expr_type != EXPR_ARRAY) + && !p->symtree->n.sym->attr.vtab) { if (simplify_parameter_variable (p, type) == FAILURE) return FAILURE; Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 181107) +++ gcc/fortran/resolve.c (working copy) @@ -9514,7 +9514,7 @@ resolve_values (gfc_symbol *sym) { gfc_try t; - if (sym->value == NULL) + if (sym->value == NULL || sym->attr.use_assoc) return; if (sym->value->expr_type == EXPR_STRUCTURE) @@ -11982,7 +11982,7 @@ resolve_fl_parameter (gfc_symbol *sym) /* Make sure the types of derived parameters are consistent. This type checking is deferred until resolution because the type may refer to a derived type from the host. */ - if (sym->ts.type == BT_DERIVED + if (sym->ts.type == BT_DERIVED && sym->value && !gfc_compare_types (&sym->ts, &sym->value->ts)) { gfc_error ("Incompatible derived type in PARAMETER at %L",