From patchwork Sun Jan 30 12:40:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 81024 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 80F731007D1 for ; Sun, 30 Jan 2011 23:40:14 +1100 (EST) Received: (qmail 2750 invoked by alias); 30 Jan 2011 12:40:12 -0000 Received: (qmail 2737 invoked by uid 22791); 30 Jan 2011 12:40:11 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 30 Jan 2011 12:40:05 +0000 Received: from [192.168.178.22] (port-92-204-33-159.dynamic.qsc.de [92.204.33.159]) by mx01.qsc.de (Postfix) with ESMTP id 60BA83CAE5; Sun, 30 Jan 2011 13:40:03 +0100 (CET) Message-ID: <4D455C23.2030904@net-b.de> Date: Sun, 30 Jan 2011 13:40:03 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.13) Gecko/20101206 SUSE/3.1.7 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR 47042: ICE on invalid code: Missing interface check 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 Build and regtested on x86-64-linux. OK for the trunk? (At least part of the ICE is in a way a regression: with proc-pointers, external + pointer became valid - thus some other checks disappeared.) Tobias 2011-01-31 Tobias Burnus PR fortran/47042 * interface.c (gfc_procedure_use): Add explicit interface check for pointer/allocatable functions. 2011-01-31 Tobias Burnus PR fortran/47042 * gfortran.dg/interface_34.f90: New. diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c index 1cbba24..1e5df61 100644 --- a/gcc/fortran/interface.c +++ b/gcc/fortran/interface.c @@ -2686,6 +2686,30 @@ gfc_procedure_use (gfc_symbol *sym, gfc_actual_arglist **ap, locus *where) if (sym->attr.if_source == IFSRC_UNKNOWN) { gfc_actual_arglist *a; + + if (sym->attr.pointer) + { + gfc_error("The pointer object '%s' at %L must have an explicit " + "function interface or be declared as array", + sym->name, where); + return; + } + + if (sym->attr.allocatable && !sym->attr.external) + { + gfc_error("The allocatable object '%s' at %L must have an explicit " + "function interface or be declared as array", + sym->name, where); + return; + } + + if (sym->attr.allocatable) + { + gfc_error("Allocatable function '%s' at %L must have an explicit " + "function interface", sym->name, where); + return; + } + for (a = *ap; a; a = a->next) { /* Skip g77 keyword extensions like %VAL, %REF, %LOC. */ --- /dev/null 2011-01-30 09:39:30.783999991 +0100 +++ gcc/gcc/testsuite/gfortran.dg/interface_34.f90 2011-01-30 11:35:02.000000000 +0100 @@ -0,0 +1,33 @@ +! { dg-compile } +! +! PR fortran/47042 +! +! Contribued by Jerry DeLisle +! + +program bug + +contains +function get_cstring () + character :: get_cstring + character, pointer :: ptmp + character, allocatable :: atmp + + get_cstring = ptmp(i) ! { dg-error "must have an explicit function interface" } + get_cstring = atmp(i) ! { dg-error "must have an explicit function interface" } +end function + +function get_cstring2 () + EXTERNAL :: ptmp, atmp + character :: get_cstring2 + character, pointer :: ptmp + character, allocatable :: atmp + + get_cstring2 = atmp(i) ! { dg-error "must have an explicit function interface" } + + ! The following is regarded as call to a procedure pointer, + ! which is in principle valid: + get_cstring2 = ptmp(i) +end function + +end program