From patchwork Thu Nov 17 20:48:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 21895 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp614858wrr; Thu, 17 Nov 2022 12:48:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf7zjIrJVH7OT6fht9rYZtzI4J2vbBo0vg7z11GWxMC4YJ0AsVpTJUzqc0AzkEAM3zIS8Ymt X-Received: by 2002:a17:907:a705:b0:78d:3e6b:d402 with SMTP id vw5-20020a170907a70500b0078d3e6bd402mr3469147ejc.563.1668718128052; Thu, 17 Nov 2022 12:48:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668718128; cv=none; d=google.com; s=arc-20160816; b=IA/c11v97rZarsLnNUWbJFYBngEZWRMATQSP1Lym/HlvGLp77nXsrpXxqV9p+OsRHq uQnt29kkyUvCojFw2G4X8AOf3o7kql5Ub5utdfQG7KOeXN2E+4kOYfgnkxSaj1OnWKwk YDUQyEAMFUVoybgCfTQUYwDIgv/jgjBxW8eH0bU4g1k7aQnbEOEoTJo0983q/eh+Dv0u nyOQhCVPZGl0M44SzTm44oBMkdI3CdebC1VXAZdJso6VYJwAUWP5sgVgGARkQrkpvT70 q+5cUNErdc2WdPqmFzqIWvOhJgmqCC0U8PE4WQQ2WGXOBs9A9zFTGemtsO27MpRK4GMa /YIw== 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=LJ6NQsSlDBmSD1rX8peoVJiWLIuMmJGt79EbemRDViM=; b=vcvGKZVNXY8l5yhUNyKshzhGh0J9fDal3z03cCxB+fopqRbujCv0BZk2Jh3rh7I0yb a//GU2HsVw7S8qM6kou2XTr5rw6/UfwQ7OVffo/o+ZlCOeD2+gIfXz/smeXEaWxtbF75 rlewLDweqDVMPPrfFIoGHzuM7zDBWm1Hgagq7bp8Tx6AMrH8xJ3SM50tbyCQ1ddGYF7L 11qWzZRelrAzOYSKPrKiwnvK5IiURQfzJJNoKSUkBwrJ2scMOFSoww6t5oMWkrz449Fj 3zpLoTcbgWX9FDOUiGX4w6D7V9fe9JbPcsqle/ZXl8CWlaPhWr3OddrDAMYB8TasGZSA ewGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jd5VrPX4; 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 hy22-20020a1709068a7600b0078d1e08f1e5si1160632ejc.919.2022.11.17.12.48.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 12:48:48 -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=jd5VrPX4; 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 D90A73852226 for ; Thu, 17 Nov 2022 20:48:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D90A73852226 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668718126; bh=LJ6NQsSlDBmSD1rX8peoVJiWLIuMmJGt79EbemRDViM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jd5VrPX4Nk+YHS1bJpGE+NyI4MMQYwdogncWZcg2H31hVpNQtkBt278z/6FE0cJ1I Y5swZ0x8zZbbm/2/IxJhFeTIwVtxO/CbgyMzJFCuMY2bpdggpNAIZo2shT7Km4TjSQ u2NvOzvRbmmeTAq1+PU6GryGkhdHDYynOuS13s64= 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 E7BF73852200; Thu, 17 Nov 2022 20:48:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E7BF73852200 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.84.59] ([93.207.84.59]) by web-mail.gmx.net (3c-app-gmx-bap50.server.lan [172.19.172.120]) (via HTTP); Thu, 17 Nov 2022 21:48:01 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: reject NULL actual argument without explicit interface [PR107576] Date: Thu, 17 Nov 2022 21:48:01 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:/8Cdj2MFC0EohNF+my6gVV/Tjzqqa7P28j8BOYpirLXl6WJ6PeBsQXNSxet36jPhJQiEP O1ajl1dsLVkeIHHX0M8r6PMXwcaq2mUsQJ3YdiPSVhbN42dg4h8diAvM741KnS23MBV2eYhb7wGb 2JA1G/JJthGT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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, 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?1749777779386726221?= X-GMAIL-MSGID: =?utf-8?q?1749777779386726221?= Dear all, one cannot pass a NULL actual argument to a procedure without an explicit interface. This is detected and reported by NAG and Intel. (Cray accepts this silently, and some other brands ICE.) The testcase by Gerhard even tricked gfortran into inconsistent behavior which could lead to an ICE with -fallow-argument-mismatch, or silently accepting invalid code. The solution is to reject such code, see attached patch. Regtested on x86_64-pc-linux-gnu. OK for mainline? As this is marked as a regression which started at v7, OK for backports to open branches? Thanks, Harald From c6b19d662f51b1e2d2691e81cfeb68ad953a4c09 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 17 Nov 2022 21:36:49 +0100 Subject: [PATCH] Fortran: reject NULL actual argument without explicit interface [PR107576] gcc/fortran/ChangeLog: PR fortran/107576 * interface.cc (gfc_procedure_use): Reject NULL as actual argument when there is no explicit procedure interface. gcc/testsuite/ChangeLog: PR fortran/107576 * gfortran.dg/null_actual_3.f90: New test. --- gcc/fortran/interface.cc | 8 ++++++++ gcc/testsuite/gfortran.dg/null_actual_3.f90 | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/null_actual_3.f90 diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index 616ae2b1197..73799c175b7 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -4162,6 +4162,14 @@ gfc_procedure_use (gfc_symbol *sym, gfc_actual_arglist **ap, locus *where) return false; } + if (a->expr && a->expr->expr_type == EXPR_NULL) + { + gfc_error ("Passing intrinsic NULL as actual argument at %L " + "requires an explicit interface", &a->expr->where); + a->expr->error = 1; + return false; + } + /* TS 29113, C407b. */ if (a->expr && a->expr->expr_type == EXPR_VARIABLE && symbol_rank (a->expr->symtree->n.sym) == -1) diff --git a/gcc/testsuite/gfortran.dg/null_actual_3.f90 b/gcc/testsuite/gfortran.dg/null_actual_3.f90 new file mode 100644 index 00000000000..ea49f9630c9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/null_actual_3.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } +! { dg-options "-fallow-argument-mismatch -w" } +! PR fortran/107576 +! Contributed by G.Steinmetz + +program p + implicit none + interface + subroutine r(y) + integer, pointer :: y(:) + end subroutine r + end interface + integer, pointer :: z(:) => null() + call r(z) + call s(z) + call r(null(z)) + call s(null(z)) ! { dg-error "requires an explicit interface" } +end -- 2.35.3