From patchwork Fri Sep 22 19:16:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 143605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5812760vqi; Fri, 22 Sep 2023 12:17:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDusznJG8tF3d2DG/ZiTeYNDDzv9izlOITnRXiENNbrj3nMFPS3GJm6wNpQ92LcchUv7gK X-Received: by 2002:a2e:a418:0:b0:2c0:bc5:5ff1 with SMTP id p24-20020a2ea418000000b002c00bc55ff1mr170329ljn.22.1695410244856; Fri, 22 Sep 2023 12:17:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695410244; cv=none; d=google.com; s=arc-20160816; b=a72owNVc8f2Y/WKxjuEAF2/H0iCmh1OHB94yFR1lhC/vVwAumCPiB9qPxAuXRdRX3t Ff2v/XMr2VWqslzlhdZvCApIaYvqlN6du/LB1wL2YW4BiB33uoe+HHCENE2/aFABhUFs ywDYe9RZF/tcXlAJJQ8tpsOew2D991PW7KsuLPRB1nKZbhXDxTKXZC8IS7dN7YsKMS+8 85fFjnFKp2AUroMLdysYcUUXgG6P+UdXqJFhKiFxG3qoCXDtXAasci3lfYNOBv85mU6R aQzZo/ByawYdjrEanHfg/Wl7czLZOsjtI1TeLzGxfm9orAV38iNVnqdX7QVxlyuuyaD4 VGYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:ui-outboundreport:sensitivity :importance:date:subject:to:from:message-id:mime-version :dkim-signature:dmarc-filter:delivered-to; bh=0D2adyMxUdkgpS+d985GT/g71Z5EoBkWHHOZ6VHPbn4=; fh=+IEfvAe+9BRgPHWhQEl2uIBTtAiiGDh1ExRZeB5JJoc=; b=kk2N0QGUsP97DZLDEM/N/3fUME0Uues8/Q/JrbIHfwRbXY2+l3hUDu9ZOMBIO6vcUe OvlHRC3Okl4D6WQ/eeAoal4dbp1wdl3M+T9Oh6pfj/HQ+BJsUsupqvIvsi9Df61kUGCv mRJwXWvu5HX3NaQTc06KRe5vVQzsqZ6fuFEIIR9Alu9qArshNTG88RafaldN4l+PchV1 XNaI+Kh4gikQDBfqAXEbNNw7eQMmGL0MQNaCfzNyla6I+U2c+7OZdFWlFJ2g93hsBcqm GBYFbYa1NE8ydepyVQDOu7yiav2sgBhKSsQdRv4lyQBF3tIwv/uC06v8iY4sVp3jWwkq GqSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=XR9Lg9rP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b20-20020a170906491400b009ae0b41c0bbsi4115680ejq.49.2023.09.22.12.17.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:17:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=XR9Lg9rP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AFE383858005 for ; Fri, 22 Sep 2023 19:17:17 +0000 (GMT) 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.21]) by sourceware.org (Postfix) with ESMTPS id 29FF83858D28; Fri, 22 Sep 2023 19:16:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29FF83858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695410195; x=1696014995; i=anlauf@gmx.de; bh=jBAPduteDYSPp0eLcLwbHrSSq7gcsEiHi/Jq4vngIiU=; h=X-UI-Sender-Class:From:To:Subject:Date; b=XR9Lg9rPQO4Ad3PI0wC+3O/rZOrKgweNYp1kXjfUg0UZ+tkytBohlyZ0spTDEA4JIE4ET2P/+S8 2yA8P9TY4L+QqgMnF87q/U3q4ua5uEI8PNeDo+loO8l2m8GaKuE8Kq90oev+PekhRQU+J+rE9KwTE nypxKwHPOHvjZzHA4xzyZrpntTl9onGh98JrBIHbStitQ6M9RbFx+glYqavRdTAl1rQFvu5RSwXgX FV9saAgZOdtDO+PdqhInJ2zsr14FSfzTxZaCpAMMag90bvkL9QS+MRb1sIrz6QEo/Kt9yZK12lBEd 6WqK5Dara+2UU2OI5ANR+w7xRc5gdUvOtzkA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.232.154.30] ([79.232.154.30]) by web-mail.gmx.net (3c-app-gmx-bap04.server.lan [172.19.172.74]) (via HTTP); Fri, 22 Sep 2023 21:16:35 +0200 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] fortran: error recovery on duplicate declaration of class variable [PR95710] Date: Fri, 22 Sep 2023 21:16:35 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:LBjFRnEKshD4X0+hxKUqvrdKUCjb2ZbPo2Ko76TGS52FhSS01JnRm/tNv0XVqA/AB6RRe +/mLLybl/JwM4Ja9eBCs8f2Zm67RfGYNZ6EweKFqXfCbPRF88e1yRPD20dEmSKMaA6yG5Gufb1Kd 6AtP2KgHE0kW5hKjbjuWlRaIZ616cP/T2pev5HYVP1DHfEH+3UJFJWoywnGdJJSCaDVCumSqVOPz Be7MPzf+nsjwNR16dlxYMmOZ43gegd0ib1zE+HiQtdL3kwMpdDdVaprco2OEfK8TXV5eaLZeUuLx N0= UI-OutboundReport: notjunk:1;M01:P0:NMA1eydau5s=;4i/KGyj8cK1J7ELA10eK1xsTPTb tJzf5N8GAA5+0SagvY3xshXqQkPiK4kAb+NLgvS7ACl49BITx7bcdUAFbdHHf+ZRo7HLOt1nX nJSBp4ZHoZsLs1E8R//IBGotIPQpr/sjb6djSbeEghcmUutFgKyJlggWFoaswOarVYxoTxEkC YKWjDC42N9uYEl2eCFIgpsp55PtZRYYDLaHc/GSs2MfhFw6uQvkXX6cs2Rw+gJylzQa0cyVQv Ypj8OJLb4qTh8cvvvPSuH2TakqsgPtzH6DnoXuWMehDLyq8n3OY2tdvCAnddm5CsskLs5MyTZ vkgYUCgm6FI5kX7k3pM1IbF/7fdV/Hqipz8nzV0OuQxJaNMZPLTSIa5/pLPzwRDfMAuMpAm2p k+vLmYSPvhg0IDosT9PcdCXOdmflsKJjY2aGC7gZtZWcrDTxHCOqcATBhElNmnc4ZJhFAm6qO nST4SvSTBZvMzA+UVvH27w1WHjSdceabTEG3MwB2hw/AoO40//ocKSYHERtudwFnH/nOxi8O8 UFu3QouImTrszqG+SwQUCVQquK24BEblpRSEEPPtBLgAWjdzgUZaUALdGdGofJ1EBOh7lSLHg ObLrApq2rYfDD18SNCQkpIlhowIPmi+1yAd8hoWllHT6nFbCQntpU3kNOpbc5MAbUzCt7BVPC UBSr87fjH0seHjSPN2fkvKv2rN9KPj/Gm4zPnmWP7CVLNiyg8sc8oKNk7wNdCyRGlpa0/oEVf F9yTPO0tFu5TYaOPzpbL4lmydo4sbjABaq9vqnSJXcl88T4FfO84dQhw5hPMaP8SvB3bhSZeD OQwl5xSpOaYNBtvj4YCzQ19A== X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777766492714418360 X-GMAIL-MSGID: 1777766492714418360 Dear all, the attached simple and obvious patch fixes several NULL pointer dereferences that are encountered for a duplicate declaration of a class variable. Another one from Gerhard's torture tests... Regtested on x86_64-pc-linux-gnu. I intend to commit within 24h unless there are comments. Thanks, Harald From 0027c58c172889bdb5c09ecea0faf3c48624dc21 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Fri, 22 Sep 2023 21:06:00 +0200 Subject: [PATCH] fortran: error recovery on duplicate declaration of class variable [PR95710] gcc/fortran/ChangeLog: PR fortran/95710 * class.cc (gfc_build_class_symbol): Do not try to build class container for invalid typespec. * resolve.cc (resolve_fl_var_and_proc): Prevent NULL pointer dereference. (resolve_symbol): Likewise. gcc/testsuite/ChangeLog: PR fortran/95710 * gfortran.dg/pr95710.f90: New test. --- gcc/fortran/class.cc | 4 ++++ gcc/fortran/resolve.cc | 4 +++- gcc/testsuite/gfortran.dg/pr95710.f90 | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr95710.f90 diff --git a/gcc/fortran/class.cc b/gcc/fortran/class.cc index 9d0c802b867..5c43b77dba3 100644 --- a/gcc/fortran/class.cc +++ b/gcc/fortran/class.cc @@ -647,6 +647,10 @@ gfc_build_class_symbol (gfc_typespec *ts, symbol_attribute *attr, gcc_assert (as); + /* We cannot build the class container now. */ + if (attr->class_ok && (!ts->u.derived || !ts->u.derived->components)) + return false; + /* Class container has already been built with same name. */ if (attr->class_ok && ts->u.derived->components->attr.dimension >= attr->dimension diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 1042b8c18e8..861f69ac20f 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -13326,6 +13326,7 @@ resolve_fl_var_and_proc (gfc_symbol *sym, int mp_flag) && sym->ts.u.derived && !sym->attr.select_type_temporary && !UNLIMITED_POLY (sym) + && CLASS_DATA (sym) && CLASS_DATA (sym)->ts.u.derived && !gfc_type_is_extensible (CLASS_DATA (sym)->ts.u.derived)) { @@ -16068,7 +16069,8 @@ resolve_symbol (gfc_symbol *sym) specification_expr = saved_specification_expr; } - if (sym->ts.type == BT_CLASS && sym->attr.class_ok && sym->ts.u.derived) + if (sym->ts.type == BT_CLASS && sym->attr.class_ok && sym->ts.u.derived + && CLASS_DATA (sym)) { as = CLASS_DATA (sym)->as; class_attr = CLASS_DATA (sym)->attr; diff --git a/gcc/testsuite/gfortran.dg/pr95710.f90 b/gcc/testsuite/gfortran.dg/pr95710.f90 new file mode 100644 index 00000000000..566c38d0a9d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr95710.f90 @@ -0,0 +1,17 @@ +! { dg-do compile } +! PR fortran/95710 - ICE on duplicate declaration of class variable +! Contributed by G.Steinmetz + +module m + interface + module function s() + end + end interface +end +submodule(m) m2 +contains + module function s() + class(*), allocatable :: x + class(*), allocatable :: x ! { dg-error "Unclassifiable statement" } + end +end -- 2.35.3