From patchwork Sat Nov 12 20:13:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 694061 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 3tGSfV6BMhz9sxS for ; Sun, 13 Nov 2016 07:13:54 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="k+/xhIRj"; 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:from:date:message-id:subject:to:content-type; q= dns; s=default; b=XuppFj1AdYODZrgADLslwcZZ4LS4Se1lOi7scrSMcJCTEm zoX+oUOD1bKLREonaH4I4NgeBflY762abMag7RbLlUOdcAdUKRvkBWkxwm5tEK4y R1QH7A1Y/B9c66O6UD60zTvH+NxVU4+FoFqRNCut+auBwfeulL3ESR+JXFpbQ= 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:from:date:message-id:subject:to:content-type; s= default; bh=+F1RuqoKR5mcXDbPJzoAvuFteCI=; b=k+/xhIRjkZO2g2A8d/75 QjsSYD7bm8tSyOfBX+2KwghRUmmwYxcAI8uGm1eIdL/7smsykeaXbCjjlpSnaFFb 8ufHS5jXONd7J5i+nwmbMKFJPXPAVHSEzM/+ho+1GLfGXZ5ZWecFy0yIYqjwEjYP XKNeVNbuxmDRHgPOeJKnrDs= Received: (qmail 108057 invoked by alias); 12 Nov 2016 20:13: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 108032 invoked by uid 89); 12 Nov 2016 20:13:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=no version=3.3.2 spammy=benson, Benson, transfer, association X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-yw0-f177.google.com Received: from mail-yw0-f177.google.com (HELO mail-yw0-f177.google.com) (209.85.161.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 12 Nov 2016 20:13:28 +0000 Received: by mail-yw0-f177.google.com with SMTP id a10so36532481ywa.3; Sat, 12 Nov 2016 12:13:28 -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:from:date:message-id:subject :to; bh=fwGCnOKf2hlB1B+eByykdDi/GHLCv/uWG4z/w3x8yDA=; b=X+pEs/U9Y8tY/XIekrqbGebZY+6M7u/5OkXKbbxVAxcH4h7xb6OZLSYQPemLQGdYzX /QuaVUQcN60CvQ07liRMH5nXjPfcG/RaWuD/bVS3eZdhki/EIBEE2BajW96/2MukjG3i bILEwIeyen3TPjWiEV7Lxq8PtsPOoMJkvzAoieWke8xVUQXAa/uJyR7WN3FJktM912qS kL+DVZg7xOYdtZBvIcYfBjS03otJDkfHHRaXLaa6P16xbjvlMNGWJugxvz8j0GtPsXul t7jJ5+MP8KKtyHEVddkiMDyUw+gGf4f7ZJ1kH51/lRDZ3wct8YmbyGK8mkubWRDs4aQw dJwQ== X-Gm-Message-State: ABUngvdKP4PLSfCgbNfkjxSmxNEEDOKhCJUbzJi0FWQVBzj5KMTedy4UPhhsWwd0lcM+17anSis5GGXuQZNUhQ== X-Received: by 10.129.132.77 with SMTP id u74mr8406583ywf.177.1478981606570; Sat, 12 Nov 2016 12:13:26 -0800 (PST) MIME-Version: 1.0 Received: by 10.129.52.2 with HTTP; Sat, 12 Nov 2016 12:13:26 -0800 (PST) From: Janus Weil Date: Sat, 12 Nov 2016 21:13:26 +0100 Message-ID: Subject: [Patch, Fortran, OOP] PR 66366: ICE on invalid with non-allocatable CLASS variable To: gfortran , gcc-patches Hi all, this patch fixes an ICE on invalid code involving class component declarations. The ICE is avoided by moving forward the error check from resolution to parsing stage. For class components this is possible, because the attributes have to be specified in the same line (in contrast to class variables, where the attributes can be specified in multiple statements, so that checking can only be done during resolution). Note that this fixes only the original example, but not comment 2 (which is a different issue). Regtests cleanly on x86_64-linux-gnu. Ok for trunk? Cheers, Janus 2016-11-12 Janus Weil PR fortran/66366 * resolve.c (resolve_component): Move check for C437 to ... * decl.c (build_struct): ... here. Fix indentation. 2016-11-12 Janus Weil PR fortran/66366 * gfortran.dg/class_60.f90: New test. Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (Revision 242339) +++ gcc/fortran/decl.c (Arbeitskopie) @@ -1866,10 +1866,19 @@ build_struct (const char *name, gfc_charlen *cl, g } else if (current_attr.allocatable == 0) { - gfc_error ("Component at %C must have the POINTER attribute"); + gfc_error ("Component at %C must have the POINTER attribute"); + return false; + } + } + + /* F03:C437. */ + if (current_ts.type == BT_CLASS + && !(current_attr.pointer || current_attr.allocatable)) + { + gfc_error ("Component %qs with CLASS at %C must be allocatable " + "or pointer", name); return false; } - } if (gfc_current_block ()->attr.pointer && (*as)->rank != 0) { Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (Revision 242339) +++ gcc/fortran/resolve.c (Arbeitskopie) @@ -13587,19 +13587,6 @@ resolve_component (gfc_component *c, gfc_symbol *s return false; } - /* C437. */ - if (c->ts.type == BT_CLASS && c->attr.flavor != FL_PROCEDURE - && (!c->attr.class_ok - || !(CLASS_DATA (c)->attr.class_pointer - || CLASS_DATA (c)->attr.allocatable))) - { - gfc_error ("Component %qs with CLASS at %L must be allocatable " - "or pointer", c->name, &c->loc); - /* Prevent a recurrence of the error. */ - c->ts.type = BT_UNKNOWN; - return false; - } - /* If an allocatable component derived type is of the same type as the enclosing derived type, we need a vtable generating so that the __deallocate procedure is created. */ Index: gcc/testsuite/gfortran.dg/class_57.f90 =================================================================== --- gcc/testsuite/gfortran.dg/class_57.f90 (Revision 242339) +++ gcc/testsuite/gfortran.dg/class_57.f90 (Arbeitskopie) @@ -18,7 +18,7 @@ contains function pc(pd) type(p) :: pc class(d), intent(in), target :: pd - pc%cc => pd ! { dg-error "Non-POINTER in pointer association context" } + pc%cc => pd ! { dg-error "is not a member of" } end function end