From patchwork Fri Dec 10 21:49:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1566666 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=hr0HB8hu; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J9l2n5DhCz9ssD for ; Sat, 11 Dec 2021 08:50:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 25E613857C7A for ; Fri, 10 Dec 2021 21:50:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25E613857C7A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1639173053; bh=Z+KU4hCab2X4zhdnD5MJrBSzV4I2dbs4JiH3QfCY7gw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=hr0HB8huSK48ScXNWOszFWKM9/zq4AaATjg8rynEAeafNtd8FmI7AdfnymOwnNaLz 3G5gUwR2wYAZaSfsekwN4dNSBYY5MQyu5I4B8YBu5QqOaNOnuWC+6EelqaR0+Ddi9S aTHBQpVI4QC2fyW/YPx3HY6Eqkz/n0IX0Mvdvyoc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by sourceware.org (Postfix) with ESMTPS id 039933857C7A; Fri, 10 Dec 2021 21:49:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 039933857C7A X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.251.8.54] ([79.251.8.54]) by web-mail.gmx.net (3c-app-gmx-bap48.server.lan [172.19.172.118]) (via HTTP); Fri, 10 Dec 2021 22:49:51 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] PR fortran/103606 - [9/10/11/12 Regression] ICE in resolve_fl_procedure, at fortran/resolve.c:13297 Date: Fri, 10 Dec 2021 22:49:51 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:zW3fjnPr4izEh6YvgDj/6cpRoTvHeyKQNmL63c3sN1CD0A4K9429NaTqfWCV5QzgM14mY 1iJhrF3gNb0/m9d7Pto1xur4UfTKcPhnUnMzcZmiqs0C2ejpSs7/sN1u0nAcchCj+B9wv33jKkpZ jr8NHJb/7dWJMDlYpz8E5/wt1aRnV/rwi0eo/nVydGk5p9cSkewx0P2mxGQXM479029EtyxBfECH O2qYPKR1TM04PAdOIgXQ9MPrQvWUD9SZFt9YpfrWJA0BZ5fDpX5qRQhSlTcz4RCPHcv1xQ7J825y 60= X-UI-Out-Filterresults: notjunk:1;V03:K0:P4EjkBdq1xY=:KsQd078sh7NbqZIbkzFupu GWY0tqO2DJxKLdU0u5HO89AyGrdponQ1VI5Il7204ZsimKlTCJHZCSL9+iOZ+SBOvwee9Tu/c hyynVfmr4R2qiedKKpKbvlBmhngZ6ra0epSfGe4auRnL2beVIAA/6FCxx/IAm/KN7uK9hyUAm rDbeu0drIwNqz+PX1+B77L6KoA0PkagmtBM8ufLG9D3Fgzrm2bcw1dECIefBOL0pQrXKdbYe5 9pMhp7Ts8mklw0PTwER8ccHbxfnotTSJNG7tev39yfIsZ6PH9NIvKlIZRQi9E7c2Z1BkqP6B9 8YdsT3cwDqk7hOR+C5c1XB+slvRn5LnUoR8tXW6HjFQmUYluckpU1xr3EwUwrdcXQ4J9khY38 k+8y/5LQOSZT9gy7XOpSyBsvHkUew34gOCHHQOO3LeK/H8bDSLDEKCh5soxHwalw29jb/UkW1 m1m0k1LP2QJ3t6Xb0QgYHtoMPXItGM1wtXev0Plj0nUWaoaR+ZUCgt5caWgyglw6yNTG8JLQs 0JNA/z1p+ZCc6CNzSRPC2Jt93DS7rJWDVfSX53YwN34kQv7i6dh7R34838pyq+QG/cPNyeTra 7FArvIJ9ggOOd5lSb6zlGHHkQm9PPqFCERqT7TxHZA+z27S6xJx1qfnAH5tOmtUr20m7ya5VY TYB9NMWmGW7YjFt8ituyBHqI8r0BeoCND2nzgW7KWbvDVkr5bg1IppXG44ARM1ipLV5z5CW4I 7+7cKxV8ZbGvK9/NRVP1TIEAJWOA3mXNYlxqRrCMwq38RjTSwHBrGsSSAhI= X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Dear all, when accessing CLASS components we need to ensure that the corresponding class container has already been built. Invalid code, e.g. the testcase in PR103606, may otherwise generate segfaults due to invalid reads. Regtested on x86_64-pc-linux-gnu. OK for mainline / branches? Thanks, Harald From 6e41e4391a54337bd32560be2b72e11ceba37b3a Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Fri, 10 Dec 2021 22:41:24 +0100 Subject: [PATCH] Fortran: fix checking of elemental functions of type CLASS gcc/fortran/ChangeLog: PR fortran/103606 * resolve.c (resolve_fl_procedure): Do not access CLASS components before class container has been built. gcc/testsuite/ChangeLog: PR fortran/103606 * gfortran.dg/pr103606.f90: New test. --- gcc/fortran/resolve.c | 3 ++- gcc/testsuite/gfortran.dg/pr103606.f90 | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr103606.f90 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 0ed31970f8b..bff1b35446f 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -13294,7 +13294,8 @@ resolve_fl_procedure (gfc_symbol *sym, int mp_flag) /* An elemental function is required to return a scalar 12.7.1 */ if (sym->attr.elemental && sym->attr.function - && (sym->as || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)->as))) + && (sym->as || (sym->ts.type == BT_CLASS && sym->attr.class_ok + && CLASS_DATA (sym)->as))) { gfc_error ("ELEMENTAL function %qs at %L must have a scalar " "result", sym->name, &sym->declared_at); diff --git a/gcc/testsuite/gfortran.dg/pr103606.f90 b/gcc/testsuite/gfortran.dg/pr103606.f90 new file mode 100644 index 00000000000..43283184e89 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103606.f90 @@ -0,0 +1,12 @@ +! { dg-do compile } +! PR fortran/103606 - ICE in resolve_fl_procedure +! Contributed by G.Steinmetz + +program p + type t + end type +contains + elemental function f() result(z) ! { dg-error "CLASS variable" } + class(t) :: z + end +end -- 2.26.2