From patchwork Mon Jan 23 21:23:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 47409 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1822460wrn; Mon, 23 Jan 2023 13:24:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXsazEQj1AK9xQI6DAf11rs6R+C5BLX/yGI+9zyA3TO9rTmbaLRFPL7gQCVmg9paKcq09XIv X-Received: by 2002:a17:906:154e:b0:7b9:62ab:dc3f with SMTP id c14-20020a170906154e00b007b962abdc3fmr32418138ejd.1.1674509079875; Mon, 23 Jan 2023 13:24:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674509079; cv=none; d=google.com; s=arc-20160816; b=PVwyicsRBExKefhsUwAJnaEzPP1Sy60v8z8g7rV7wOkoTM5/HaavNBWcyrpuppS5WR f0FjuiBsSJFFuu5mrgxEtyHM3S4O9/eA+dOgkMEdxVojfAGniXXNiInV8lbHniydsfgW dbVukEAsFPHUaAxU5RQQqA4J4ujKcMO7IkAgdsAlPcjRFSRMTwSClWCFZx+K8fOHt8bt QuvxFwLlcrpjRiSBcGKR+UmXMpdX3teghiof0FevnpJdByHExjtVMU1I6qvJoUp6cXOx QCPW4wEifrDtjswaAGZY1tuit1mLkbT8kZh/NoWH/6/UgjL4T8/oYID3t3T7M9QAjzP9 4JSw== 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=oDEdHNLzi4id/5KAzUo8IfWod24ZA4jdBQD6IS+fBT4=; b=gF0rLHGHCAeyWf9Yy87X9FCYBGvp18BT3oaMQq1b5CQtN1d1tPz8hjb643eUxC3fm1 KASjXfrvTwO9pZM0+n4ZRiDwG9vqzWN6uxF2KDEVw/9mbPaqIr5/us9S5SbxoQWKcphP 0oARnb8fu7/jH+t+c7ySc2vLsbO32/cz0Rt7zGhemweu1x3OebvGekDxh7PH82jUdPnn aaWgG6Bxy+Nyl7M1dZrUnavtYfgcLmCwnDe5idxVh2r2VC7i3oBBjS95swX8FpFlEZMW 4d3pBw50X/TgTPO0uo2NriMG6U7Iuksg1YQ2a6/PFyTlRvEzeIs/0G1QxuY1+qB0UPhM Z2Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aVGlFYL7; 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 ae10-20020a17090725ca00b007c1852c08f0si57724052ejc.658.2023.01.23.13.24.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 13:24:39 -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=aVGlFYL7; 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 A758A3858407 for ; Mon, 23 Jan 2023 21:24:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A758A3858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674509078; bh=oDEdHNLzi4id/5KAzUo8IfWod24ZA4jdBQD6IS+fBT4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=aVGlFYL7E3rPFpvwwpUeKAMWuuv477OhzfLZbko3K0V1Wp45ryiy409XZ7Yjn74R1 SfRum02r9SxgjwEIWAaV9ty5lcoi1ln10sCqtumxjGaeasNw4k1gKIEwM8kd0kmesx 6t0XNxyhB9/3vrL4t3tSH2kBv/gpcsGjPaUvRiOo= 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 0C9223858D33; Mon, 23 Jan 2023 21:23:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C9223858D33 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.90.148] ([93.207.90.148]) by web-mail.gmx.net (3c-app-gmx-bap50.server.lan [172.19.172.120]) (via HTTP); Mon, 23 Jan 2023 22:23:54 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: fix NULL pointer dereference in gfc_check_dependency [PR108502] Date: Mon, 23 Jan 2023 22:23:54 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:G3dDCyBrMcY9B9pRmxMjLRFpVWY1kVNGJiTT13AGS06EIEX01mhjbA4YsZQsC5KX+T5bF E1txwwFgljKdzwBpb4MIhGffp3rfoW5us0SwvaOPatGmzTX/m3NAU/wSFGM6F5YVOxtLLtJ0/c9H BBV9frOnXZczGymjku5eDgmZ682baqPuvZzP5Fby9oDJTjXywVRsGG3s43l0ZJccSsByLRxKZ8Z8 FAv772VQwFuTDc7SjvInmpwaQfQL6J8ASqrMzfuj1xXYWqdp0emt1xE1Ue8hjPz7rDqhxvLxk6zH 4A= UI-OutboundReport: notjunk:1;M01:P0:UI0lnDTvHck=;JL9MIcfdBUh99PtI5/H8Qj/+HDR lFXkmf6s4SHGbycqZDWTc/oxnxJe5fWT4dVgk8+YJG+KBpLmg1gGjfogdQwmhFps2EHxpPPCY 33SE3pRPqYLnFmjdrRkbiiDVHsHpDdGD8QnXpyWYI9wGZyKPSe95QunuuKNT+CsVBQjFfWgy2 0yo1sTZ2zQGC/S7+rur8Z5cdt5IAV4yoMhL8M/ml+jUZGJjgHNgrdVXsk31ldgcao5E57klId qWQyjETVqzB5t0B4Gfif4vkfcoXGCyHSuPUprKntXXbO5/RuTpCkuMZpWqfHOqTsu1/Orrj5S USdUg05toSaZl6zwMMO1GZK//oC1/40Vhzst1dLv82LhK1Mit0FN8gBthag/pik7CoXziClch btTTbjbZdXPglicyf58VzAL2/JlcXUb5q/mWxjrFZvnFYOgBI94DEve7Kcg2/tukpqKPtzWny 3bPRsXI3UF2AGV3EhUb90lv6uBo9PmXf/Ip9heC/kSLplOA44dRcygcYSnjIHamor362JI9nY zlLW+E5CbQTQsCViHCc6MjHOrJXsL0XBdArLhxDYLVjtRv3rUoySDthdj26o/g2sWKbo+tyRm TsDPBiczTtk9QDNO+lgQqUX4rdKnC0pE75+VXJdQrvNRLT6AQXytH9PdHRPLQQ5Y9vmUMvTzJ 82kR7QuL3J7UuA3EAFISDVj5LoxFt8qghBwmzeVha7CJvaSb0ZLJn0GEr0SGHzecwr4+ufiet iJTVcUxOsKt8qt1WzvqYDHeMATC5O1Uhg5AJphVz2N46dVqo6BwQfzAMXDJPpe9UrC6kp4+Ce LR+0OCkie6szQ1FPQ84VeTLvE0XHh6pzrhmprAkM9lgVU= X-Spam-Status: No, score=-13.1 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_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?1755850032946404224?= X-GMAIL-MSGID: =?utf-8?q?1755850032946404224?= Dear all, the code in the PR demonstrates that dependency checking in the frontend optimization was not recovering well from invalid code, leading to a NULL pointer dereference. An easy and really obvious fix. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From d27e1b13ba312411ce271f5122f694ffe6c051e6 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 23 Jan 2023 22:13:44 +0100 Subject: [PATCH] Fortran: fix NULL pointer dereference in gfc_check_dependency [PR108502] gcc/fortran/ChangeLog: PR fortran/108502 * dependency.cc (gfc_check_dependency): Prevent NULL pointer dereference while recursively checking expressions. gcc/testsuite/ChangeLog: PR fortran/108502 * gfortran.dg/pr108502.f90: New test. --- gcc/fortran/dependency.cc | 5 +++++ gcc/testsuite/gfortran.dg/pr108502.f90 | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr108502.f90 diff --git a/gcc/fortran/dependency.cc b/gcc/fortran/dependency.cc index 43417a6ec76..9117825ee6e 100644 --- a/gcc/fortran/dependency.cc +++ b/gcc/fortran/dependency.cc @@ -1292,6 +1292,11 @@ gfc_check_dependency (gfc_expr *expr1, gfc_expr *expr2, bool identical) if (expr1->expr_type != EXPR_VARIABLE) gfc_internal_error ("gfc_check_dependency: expecting an EXPR_VARIABLE"); + /* Prevent NULL pointer dereference while recursively analyzing invalid + expressions. */ + if (expr2 == NULL) + return 0; + switch (expr2->expr_type) { case EXPR_OP: diff --git a/gcc/testsuite/gfortran.dg/pr108502.f90 b/gcc/testsuite/gfortran.dg/pr108502.f90 new file mode 100644 index 00000000000..45f73849c57 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr108502.f90 @@ -0,0 +1,12 @@ +! { dg-do compile } +! { dg-options "-O2 -ffrontend-optimize" } +! PR fortran/108502 - ICE in gfc_check_dependency +! Contributed by G.Steinmetz + +integer function n() + integer :: a(1) + a = [1] / 0 +end +program p + integer :: b = n() ! { dg-error "must be an intrinsic function" } +end -- 2.35.3