From patchwork Mon Dec 26 22:26:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 36709 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1113276wrt; Mon, 26 Dec 2022 14:27:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXt7j/oOw1Lndo4nqn7xd2OZdblrCpvjrU/vI4joAuqZl/J0tFN6wIXvxQyI6TU5v0GZHxoX X-Received: by 2002:a50:fe0c:0:b0:45c:834b:f2ad with SMTP id f12-20020a50fe0c000000b0045c834bf2admr15712405edt.42.1672093640957; Mon, 26 Dec 2022 14:27:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672093640; cv=none; d=google.com; s=arc-20160816; b=ey2ajdnWH6SlVu9cbA+w8cbo+Svt0ROWEDHCRK5MhMFOy5hB5oAapgTLUIxc2Tkd4P UO6lwR2GCbCR/wrlew+Ch0GSB0jXRiyz5QEtNz3+mQ89hL1sxKGx5yENl/45AsW7jD9t pbw8wbTCCAgqePoLieACqHMI0B/MC4rDhlvLMP5fhetf5BCw3Hf0AmDdWB0sskMOvt7R jDUUlI+oXH1nnDjRhEsQGAK62p8uZMCv8J/gE7gLBfqBRtB9jYzi+qpOUWFc37KBeKkV upoHS0plUV9XrntoWyJfBXxzc/X90LKonP06jodBuuXzyBRKUlo3MldajzIZahh1f67d VjAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :feedback-id:message-id:subject:cc:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=anvBVXGPb4MzY3jmokaoVRklvByYq/hSGxEM1r+SnSo=; b=AGLv6iwIJZS2YBoTowVwiRufZ6EfICAcXnTYkv2Yr9vg1yr4c8kwfK7bdQWXgGDYv4 ULvCq+e0AB68e58g6287m7fL2nAxfRyfu+QP0Kv4cdm5G45D2gxFwNTHhxz+3JP6rxIX pVIJtJZQWhYlSE708PUWf7JaRnwbcw5pKKQ5k3vx9qRxaVQRAxq7ja0LVWavDEQL144h MEI9rNY7T3SU5u4/Ylce2vDpPgfJ+zSW9P3PyWslHTFffOr77a8XAGLK0+FwtdC65SF0 j8wtH3aJ+6G8XOsvowBmOh7/9orEKjT0QvVMrtzdBXXp35CQDmOeHkJ/7qkeY5Tl3lBF WSwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UpfDloAG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r16-20020a50d690000000b0047ed1256ff6si9707085edi.443.2022.12.26.14.27.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Dec 2022 14:27:20 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UpfDloAG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D0F6F3858D32 for ; Mon, 26 Dec 2022 22:27:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0F6F3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672093639; bh=anvBVXGPb4MzY3jmokaoVRklvByYq/hSGxEM1r+SnSo=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=UpfDloAG2IdD1X/6slBllgtNmU/5lxn+BleUc2Dc++kO/uER4j3jS5wxKx/N8aEn4 3HyMz4ZF2lGZAzYR8Fj+mTgQP9Ajy48WzHBWaWYGXbmlzS7tVBCgUAQIAVJDWxbcP0 RzCvcDk3fqQycNRzl7az44JMk2q5tZDxipvsDFPs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by sourceware.org (Postfix) with ESMTPS id 337C93858D38; Mon, 26 Dec 2022 22:26:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 337C93858D38 Date: Mon, 26 Dec 2022 22:26:29 +0000 To: gfortran Cc: gcc-patches Subject: [patch, fortran] ICE in attr_decl1, at fortran/decl.c:8691 Message-ID: <7802b3ba-cf1d-84eb-6e64-e470ef8e911a@protonmail.com> Feedback-ID: 34907122:user:proton MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jerry DeLisle via Gcc-patches From: Jerry DeLisle Reply-To: Jerry DeLisle Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753317261558069374?= X-GMAIL-MSGID: =?utf-8?q?1753317261558069374?= The attached patch was provided by Steve Kargl. After exploring for possible other checks I settled on leaving the patch intact. Two existing test cases updated as different but sensible error messages resulted. Regression tested on main line. OK to commit? Regards, Jerry Author: Steve Kargl Date: Mon Dec 26 14:07:04 2022 -0800 Modify checks to avoid referencing NULL pointer. Update test cases with error messages that changed as a result. gcc/fortran/ChangeLog: * decl.cc (attr_decl1): Guard against NULL pointer. * parse.cc (match_deferred_characteristics): Include BT_CLASS in check for derived being undefined. gcc/testsuite/ChangeLog: * gfortran.dg/class_result_4.f90: Update error message check. * gfortran.dg/pr85779_3.f90: Update error message check. diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index e593518a77e..bac7b6568b0 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -8743,7 +8743,9 @@ attr_decl1 (void) /* Update symbol table. DIMENSION attribute is set in gfc_set_array_spec(). For CLASS variables, this must be applied to the first component, or '_data' field. */ - if (sym->ts.type == BT_CLASS && sym->ts.u.derived->attr.is_class) + if (sym->ts.type == BT_CLASS + && sym->ts.u.derived + && sym->ts.u.derived->attr.is_class) { /* gfc_set_array_spec sets sym->attr not CLASS_DATA(sym)->attr. Check for duplicate attribute here. */ diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index bc2b2188eea..6186c48aee2 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -3934,7 +3934,7 @@ match_deferred_characteristics (gfc_typespec * ts) m = gfc_match_prefix (ts); gfc_buffer_error (false); - if (ts->type == BT_DERIVED) + if (ts->type == BT_DERIVED || ts->type == BT_CLASS) { ts->kind = 0; @@ -4215,7 +4215,7 @@ declSt: if (bad_characteristic) { ts = &gfc_current_block ()->result->ts; - if (ts->type != BT_DERIVED) + if (ts->type != BT_DERIVED && ts->type != BT_CLASS) gfc_error ("Bad kind expression for function %qs at %L", gfc_current_block ()->name, &gfc_current_block ()->declared_at); diff --git a/gcc/testsuite/gfortran.dg/class_result_4.f90 b/gcc/testsuite/gfortran.dg/class_result_4.f90 index 4b22a3c30ee..5497ac652ec 100644 --- a/gcc/testsuite/gfortran.dg/class_result_4.f90 +++ b/gcc/testsuite/gfortran.dg/class_result_4.f90 @@ -1,6 +1,6 @@ ! { dg-do compile } ! PR fortran/78500 -class(t) function f() ! { dg-error "must be dummy, allocatable or pointer" } +class(t) function f() ! { dg-error "is not accessible" } f = 1 ! { dg-error "variable must not be polymorphic" } end diff --git a/gcc/testsuite/gfortran.dg/pr85779_3.f90 b/gcc/testsuite/gfortran.dg/pr85779_3.f90 index fba1133b3ea..a81a9faf88e 100644 --- a/gcc/testsuite/gfortran.dg/pr85779_3.f90 +++ b/gcc/testsuite/gfortran.dg/pr85779_3.f90 @@ -1,6 +1,6 @@ ! { dg-do compile } ! PR fortran/85779 -class(t) function f() ! { dg-error "must be dummy, allocatable or pointer" } +class(t) function f() ! { dg-error "is not accessible" } type f ! { dg-error "already has a basic type" } end type ! { dg-error "END FUNCTION statement" } end