From patchwork Mon Feb 13 21:13:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 56552 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2579253wrn; Mon, 13 Feb 2023 13:15:28 -0800 (PST) X-Google-Smtp-Source: AK7set/fChc4C04q08DLO+BhHuYwQMDJlmjGaEpT0QRw8LX2uP+vFWCfa07NqiZ5PHz2sfxFLKGO X-Received: by 2002:a17:906:a2d6:b0:8aa:c038:974c with SMTP id by22-20020a170906a2d600b008aac038974cmr370023ejb.54.1676322927765; Mon, 13 Feb 2023 13:15:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676322927; cv=none; d=google.com; s=arc-20160816; b=WbBVnkWbZ/U237X8elJCDgzIjZAxHgTacwvS/w5a5Tl4ssjUgzyCojBnz7rRGdShAd 4LbPFd/5Xt1drvu2u9s1uPVG3QmyQXzgb97qIt2QgvT/nJ8eSbT2zJf0BzCfgEF/5CIs 9Hkvh55R9RwYy4AfPYZH6oQ9KdUKZG0L+IirxHwiNTFABOeZ/pvjU/69W+uyPXzp0jvc YVi1KDl6+SwsvRa+IIyX8MAuxcQ4UhkoX30W9iqUcCgEPvU6Zz19v+VHJiYxz4n6D8u2 lbVPXMGr5bdSnc1x8RmE293PGxC5OjjrkZrDC4EaQpjb+YfcPflPw//jEH1dYnJckKwm 4Kgg== 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:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Nt4nSJjJ4pba56Rb5Diy1EdIjlz+5oCwiVqAE+J5bJI=; b=KPzcIrE5qNAK3Zf/bFcJd4So3CfChfZ2YSl+DaRDLY6jpojA2yAMsYvkTbXHNAEBUi HIg6LykXtStfCGSpuEKrBYGJJX6vCY8rL/yS5ZUO6jIB9cgfpe+moLglV3hAgZio8dCM z/gZmKZPpme6Kl/V9C9SIYZ747lsPRx1DsJoOrXNXBUMBmfguLVBrQi7aQHyGdCum1MA m2BmgoLIhDlfAvFvjtfl+NwPWq5SkipwNgsXwX75SrSKMeF2ISWZyeIF4RcA96d6ujo8 6h+WhMZ6clUpFx92bTBM6/luivTbX3Y3sh7mzeoIUYueZkKbAMMAy2Z17+YpbJ4HNnyO c7ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Afpr79RF; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 12-20020a170906018c00b0088acf6e8c97si21756689ejb.531.2023.02.13.13.15.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 13:15:27 -0800 (PST) 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=@gcc.gnu.org header.s=default header.b=Afpr79RF; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7FF9E385B511 for ; Mon, 13 Feb 2023 21:14:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FF9E385B511 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676322896; bh=Nt4nSJjJ4pba56Rb5Diy1EdIjlz+5oCwiVqAE+J5bJI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Afpr79RFFTuNCXkm05yHJHo/6DJmXyk5K3FtWZFJOrr3UrjUzD/bGdWC/L5NB2W4C zkr0rQVqmsJZqTC6VSIv3Col4zFOyYbsVD2tRzOuoaDCgNJY+t6608Lv5L3K8wfg1c 2oWw5IJqaiBVyB9Bf6IUf7mlXXKDUe1Rk8gNtv8M= 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.20]) by sourceware.org (Postfix) with ESMTPS id 387993858433; Mon, 13 Feb 2023 21:13:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 387993858433 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.80.251] ([93.207.80.251]) by web-mail.gmx.net (3c-app-gmx-bap61.server.lan [172.19.172.131]) (via HTTP); Mon, 13 Feb 2023 22:13:18 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH, committed] Fortran: error recovery after invalid use of CLASS variable [PR103475] Date: Mon, 13 Feb 2023 22:13:18 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:1LX1I0TPjnR31JhsMzoSEgq1jztaIzOVWeoh73MWWBDI35w+4zeygnN4TKdqKNTARKY2E q23XiZ381do0PIuJNN55iLZoi1Sokp7m2VH85jJWqMxa3MR2CiUEyHxxgbJza8I5GaQOB3EvLX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rlE= X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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.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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757751990648555144?= X-GMAIL-MSGID: =?utf-8?q?1757751990648555144?= Dear all, the attached simple and obvious patch fixes a NULL pointer dereference on an invalid use of a CLASS variable. Committed to mainline after regtesting on x86_64-pc-linux-gnu as https://gcc.gnu.org/g:2ce7e2a83e18a27fe9c659f8667fc24f0df4ea9a Thanks, Harald From 2ce7e2a83e18a27fe9c659f8667fc24f0df4ea9a Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 13 Feb 2023 22:02:44 +0100 Subject: [PATCH] Fortran: error recovery after invalid use of CLASS variable [PR103475] gcc/fortran/ChangeLog: PR fortran/103475 * primary.cc (gfc_expr_attr): Avoid NULL pointer dereference for invalid use of CLASS variable. gcc/testsuite/ChangeLog: PR fortran/103475 * gfortran.dg/pr103475.f90: New test. --- gcc/fortran/primary.cc | 2 +- gcc/testsuite/gfortran.dg/pr103475.f90 | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr103475.f90 diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc index 28ce5fea865..1bea17d44fe 100644 --- a/gcc/fortran/primary.cc +++ b/gcc/fortran/primary.cc @@ -2770,7 +2770,7 @@ gfc_expr_attr (gfc_expr *e) { gfc_symbol *sym = e->value.function.esym->result; attr = sym->attr; - if (sym->ts.type == BT_CLASS) + if (sym->ts.type == BT_CLASS && sym->attr.class_ok) { attr.dimension = CLASS_DATA (sym)->attr.dimension; attr.pointer = CLASS_DATA (sym)->attr.class_pointer; diff --git a/gcc/testsuite/gfortran.dg/pr103475.f90 b/gcc/testsuite/gfortran.dg/pr103475.f90 new file mode 100644 index 00000000000..6cce5e8ebf7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103475.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! { dg-options "-O2 -Wall" } +! PR fortran/103475 - ICE in gfc_expr_attr +! Contributed by G.Steinmetz + +program p + type t + end type + class(t) :: x ! { dg-error "must be dummy, allocatable or pointer" } + y = x() ! { dg-error "Cannot convert invalid class" } +end -- 2.35.3