From patchwork Wed Mar 27 21:35:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 1067455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-498520-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="AUFvt/nU"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44V1Zg6c1kz9sPZ for ; Thu, 28 Mar 2019 08:38:16 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=cyqYTtIYIFSC/2uGnaDj3fO00lX49J0dO995vJyzl12ljD i2X46rjWTr4pEUzHEJ2ZMj/zJ2UDHaZCROPX/uG55AgwvmNxOhbb1UDaSse/+3A+ WvlL6IsZ68fkdCcePRrKZDJoQTmphkz4jTJ8VK/Hskp4hu7A/NHbb/OXMElkk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=ay+diVuwLzvDLt6LL0h0CYo8hMs=; b=AUFvt/nUdu2tYiHOfZGD tL9D+D+TgPRkodNIdPX8gK5PrtIl3U5wc6e6FuK493uY2iuXsvtRLrNqpTuoQtKA u8zpDg/rPPi+PnIDlQ/OOU8TPZZKKVgHsqRdlAVC+f6ARQe8DAruxuQ6zT6fT8sy hnDCMVVHjiJhtGnM72rUD3w= Received: (qmail 108772 invoked by alias); 27 Mar 2019 21:36:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 105131 invoked by uid 89); 27 Mar 2019 21:35:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=concerning, gfc_expr, HX-HELO:sk:mail-oi, HX-Spam-Relays-External:sk:mail-oi X-HELO: mail-oi1-f179.google.com Received: from mail-oi1-f179.google.com (HELO mail-oi1-f179.google.com) (209.85.167.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 27 Mar 2019 21:35:46 +0000 Received: by mail-oi1-f179.google.com with SMTP id y84so14102708oia.12; Wed, 27 Mar 2019 14:35:46 -0700 (PDT) MIME-Version: 1.0 From: Janus Weil Date: Wed, 27 Mar 2019 22:35:33 +0100 Message-ID: Subject: [Patch, Fortran, F08] PR 85537: Invalid memory reference at runtime when calling subroutine through procedure pointer To: gfortran , gcc-patches Hi all, the attached patch implements some missing constraints from Fortran 2008 concerning procedure pointer initialization (cf. the standard quote in comment #18), thus fixing two accepts-invalid and ICE-on-invalid problems. It regtests cleanly on x86_64-linux-gnu. Ok for trunk? Cheers, Janus diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e1fdb93f3d0..372c517487f 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-03-27 Janus Weil + + PR fortran/85537 + * expr.c (gfc_check_assign_symbol): Reject internal and dummy procedures + in procedure pointer initialization. + 2019-03-27 Paul Thomas PR fortran/88247 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index f54affae18d..478a5557723 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -4407,6 +4407,20 @@ gfc_check_assign_symbol (gfc_symbol *sym, gfc_component *comp, gfc_expr *rvalue) "may not be a procedure pointer", &rvalue->where); return false; } + if (attr.proc == PROC_INTERNAL) + { + gfc_error ("Internal procedure %qs is invalid in " + "procedure pointer initialization at %L", + rvalue->symtree->name, &rvalue->where); + return false; + } + if (attr.dummy) + { + gfc_error ("Dummy procedure %qs is invalid in " + "procedure pointer initialization at %L", + rvalue->symtree->name, &rvalue->where); + return false; + } } return true; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0679cb72e52..f6df0b1281c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-03-27 Janus Weil + + PR fortran/85537 + * gfortran.dg/dummy_procedure_11.f90: Fix test case. + * gfortran.dg/pointer_init_11.f90: New test case. + 2019-03-27 Richard Biener * gcc.dg/torture/20190327-1.c: New testcase. diff --git a/gcc/testsuite/gfortran.dg/dummy_procedure_11.f90 b/gcc/testsuite/gfortran.dg/dummy_procedure_11.f90 index f51c5455c05..3e4b2b1d6f0 100644 --- a/gcc/testsuite/gfortran.dg/dummy_procedure_11.f90 +++ b/gcc/testsuite/gfortran.dg/dummy_procedure_11.f90 @@ -5,16 +5,18 @@ ! Contributed by Vladimir Fuka type :: t - procedure(g), pointer, nopass :: ppc => g + procedure(g), pointer, nopass :: ppc end type -procedure(g), pointer :: pp => g +procedure(g), pointer :: pp type(t)::x print *, f(g) print *, f(g()) ! { dg-error "Expected a procedure for argument" } +pp => g print *, f(pp) print *, f(pp()) ! { dg-error "Expected a procedure for argument" } +x%ppc => g print *, f(x%ppc) print *, f(x%ppc()) ! { dg-error "Expected a procedure for argument" } diff --git a/gcc/testsuite/gfortran.dg/pointer_init_11.f90 b/gcc/testsuite/gfortran.dg/pointer_init_11.f90 new file mode 100644 index 00000000000..3113e157687 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pointer_init_11.f90 @@ -0,0 +1,44 @@ +! { dg-do compile } +! +! PR 85537: [F08] Invalid memory reference at runtime when calling subroutine through procedure pointer +! +! Contributed by Tiziano Müller + +module m1 + implicit none +contains + subroutine foo() + integer :: a + + abstract interface + subroutine ibar() + end subroutine + end interface + + procedure(ibar), pointer :: bar_ptr => bar_impl ! { dg-error "invalid in procedure pointer initialization" } + + contains + subroutine bar_impl() + write (*,*) "foo" + a = a + 1 + end subroutine + + end subroutine +end module + + +module m2 + implicit none +contains + subroutine foo(dbar) + interface + subroutine dbar() + end subroutine + end interface + + procedure(dbar), pointer :: bar_ptr => dbar ! { dg-error "invalid in procedure pointer initialization" } + + call bar_ptr() + + end subroutine +end module