From patchwork Sat Dec 3 18:27:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 29298 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1477402wrr; Sat, 3 Dec 2022 10:28:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf44e0ryw9dVPTojIfwO+K9Z7W53VV03nlf8KtYN9rsXKO2T6t+oja4/qzGcPewmn7srCarC X-Received: by 2002:a17:907:1185:b0:7c0:d543:7bd6 with SMTP id uz5-20020a170907118500b007c0d5437bd6mr3211609ejb.237.1670092112020; Sat, 03 Dec 2022 10:28:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670092112; cv=none; d=google.com; s=arc-20160816; b=d3tnsTJIxq2fSXUFf22TLGBfC4A2sDs9KM8isE2sc/zk2nVhOUE0wU1CUYsBtlO54D hn/WY0uU6nZhUdEjjbGdFHtcXnl0jy1pmswJmaGUl7F3BukycDuXUV8CrU3RuqUlmVf3 Xtmq2asT0kJ2pRwvYoh6iGikAAVa3pzao8leMX56Gz+dorEwavlNKnRM/0vkTEnIGMS0 8MGqbK9KZld1MV/EL5b4UA/pAxD+PZKU/GI5ZOXgqNs0IGxYz5vM9Td03GVvhOiMm2XX nnxNk4zIbVtV98Yib8xxPabTtYw3RSWZWBeU7MDjhyE9A09Vx8Veldjlw3dLY6pRh9Qj o2xg== 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=7BurY4a0HAKmNMoja366/xemlua7Fo0fB4zcqWdv3Xw=; b=pPyQhHw0r4gjZcmkLai59YfQ8PU1CjiXAmoLzIbsRdZfbqGHZjJcYzTGRfZg19xp0E glGdMBeoT35/ipbkuVENulygQ8xabqrKExW73EmwVPa1DZVXZ4KqSVirb1MYLbHvaiof xoF0XoDsESxGMHWTL/OItdR6kyC7QgFL4f7LjvbixzKc4/me9CRkJp0+bpTPvfl4puYA liXm7AYNeMWfI63Hvo8O7vlQ09YCzDRgLhKY7uuWYuBGRjENIzyxKqURO7EckgaShgW/ EgXgt5Rwf4VxGlHpWgCZL4HVT/A+9ulSa2JNOlZWVaT0Na6z7R1QRYLq8G+9g56dX0Wh 8gjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aGEOgBRO; 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 g22-20020a056402321600b0045d4b7ad162si8232167eda.546.2022.12.03.10.28.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Dec 2022 10:28:32 -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=aGEOgBRO; 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 D1C693858D39 for ; Sat, 3 Dec 2022 18:28:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1C693858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670092110; bh=7BurY4a0HAKmNMoja366/xemlua7Fo0fB4zcqWdv3Xw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=aGEOgBROOoOTwSk3+wGx6C5wErvV6jIzaRb0iD62thw1xsKjE/zowUMoHZ/RnQK1v g5HG1W5qebPDnxn/RCU843xQ453QaY+vKzwSD9q7wjyAGDQlfJNG1ScI/2UQSs5qhT 1A5onoU0Er4zvw5tUlByk+wsrqmVB5QPH2nO1CMQ= 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.15.19]) by sourceware.org (Postfix) with ESMTPS id 378D83858D20; Sat, 3 Dec 2022 18:27:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 378D83858D20 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.85.95] ([93.207.85.95]) by web-mail.gmx.net (3c-app-gmx-bs55.server.lan [172.19.170.139]) (via HTTP); Sat, 3 Dec 2022 19:27:46 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: error recovery handling invalid CLASS variable [PR107899] Date: Sat, 3 Dec 2022 19:27:46 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:GokTIJhLu0YYj1ht2WMaDuXkPuIIMTEpw/iuA5Zsc1yxNMUSWYnZmBq2mSRTmkwxOKQou cV9ASVRO6VaTgcDi+57/3NqvX+/t4Gzh8cS94exH6EvO8IfZpmmOkzwiA6LJvU7iCxMfo6PPnrsI gOGo7eTeINJ/XvkuJlmXEzn/uDEN313l2x0n/rmir0GQbfXLCwQ946QCpB7sqZjXMktzJOYJ7z8R N/KCdkkIRODV//XAWm5tTydr7ZGuyS/c6/HNaeB2lZySUKOTVvnKZzLkUtmUJ6Anblt1sfXe++rL Cc= UI-OutboundReport: notjunk:1;M01:P0:mPwOlv4BJZc=;qD2MQF19afi4Z0NjvdjAMw/ijgk N6hJzImjl8ZrUbWEltiuNy3Du4iSTGyYW+tTHU4nGlYp17UNbDmRMperJkEf0eNOjLRl4mg0X 4Wp9vbbQawxKPxayg0FepomORaivsjWo4PsSu2fzHeP53kLT6vvf1+3qdHf4OHQhAc2Us6APr BnuGHOgyKlDCqxre7jyFfhaQOPYxBIq/FnIiUPHDWLIGONGe8pNX8uy9U2xasSyiU7pYbSTwh rsWzQRWpI7GufAhcYmlRk/U89f39t9mnVeN4rmcvuE6svHBHrntOXXnmQ42huMrffqtU5xc9M xQYoNXyg1WveQBEp7rAGcm/XZyKEAMmCH7zM1m3ts4qRNcIt0AgHNWHmQv5gKciQiV358RBwW gug27oR+mhygNAfMRbm84lGTCqeAEGJILF10A6ZwBLoCtM9W77wSc2vdU0nWNmF1OLCxjTa0L FrrxrdjcdXhWKmf0UpV5t5C0soBjIO9iS55f3h30k4E0Wyfo100r09JX7SVEwhh81brDTr8w/ MZgM3uV+11hi/XgAIKq9Zq+1h0so1fOOWUxHJbRDg9nlJwrrH3okULa+U2qWCAILVCyoranrn ZwG47UmCxOe+p9nAuoXwTcL33wC2ZwR0Al5UayyFSigAWNfBOIa+i5e71o9fYi1GucmB0Iswr l25l/fqkdD11MUwWPiqdJJvxVjwvJkHuGZ6p6ARVB07+DpI+qUry605RJO5grmAyZO2gYg1ip fLFS4SP/YAfhVIxaJePfgt8+jXya73uyOnJrWlEYn9K1v+4UJ/a7EryFgJcyY6YF14uaVCL8F QTNVrHtHHIR5wBkjp0KW1CzQ== X-Spam-Status: No, score=-13.5 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, 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?1751218506512951471?= X-GMAIL-MSGID: =?utf-8?q?1751218506512951471?= Dear all, the attached obvious patch fixes a NULL pointer dereference that occurs with an invalid CLASS argument to DEALLOCATE. Regtested on x86_64-pc-linux-gnu. Will commit soon unless there are comments. Thanks, Harald From dfe7f1a06d78f6319ad81f5774dc43fe52e37f45 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sat, 3 Dec 2022 19:21:07 +0100 Subject: [PATCH] Fortran: error recovery handling invalid CLASS variable [PR107899] gcc/fortran/ChangeLog: PR fortran/107899 * resolve.cc (resolve_deallocate_expr): Avoid NULL pointer dereference on invalid CLASS variable. gcc/testsuite/ChangeLog: PR fortran/107899 * gfortran.dg/pr107899.f90: New test. --- gcc/fortran/resolve.cc | 2 +- gcc/testsuite/gfortran.dg/pr107899.f90 | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr107899.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 3396c6ce4a7..75dc4b59105 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -7570,7 +7570,7 @@ resolve_deallocate_expr (gfc_expr *e) sym = e->symtree->n.sym; unlimited = UNLIMITED_POLY(sym); - if (sym->ts.type == BT_CLASS) + if (sym->ts.type == BT_CLASS && sym->attr.class_ok && CLASS_DATA (sym)) { allocatable = CLASS_DATA (sym)->attr.allocatable; pointer = CLASS_DATA (sym)->attr.class_pointer; diff --git a/gcc/testsuite/gfortran.dg/pr107899.f90 b/gcc/testsuite/gfortran.dg/pr107899.f90 new file mode 100644 index 00000000000..e47b57b7b91 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr107899.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +! PR fortran/107899 - ICE in resolve_deallocate_expr +! Contributed by G.Steinmetz + +program p + type t + end type + class(t), target :: x[:] ! { dg-error "deferred shape" } + if (allocated (x)) then ! { dg-error "must be ALLOCATABLE" } + deallocate (x) ! { dg-error "must be ALLOCATABLE or a POINTER" } + end if +end -- 2.35.3