From patchwork Sat Jan 15 10:09:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 79043 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 7C143B6EF1 for ; Sat, 15 Jan 2011 21:09:31 +1100 (EST) Received: (qmail 6047 invoked by alias); 15 Jan 2011 10:09:27 -0000 Received: (qmail 6031 invoked by uid 22791); 15 Jan 2011 10:09:26 -0000 X-SWARE-Spam-Status: No, hits=1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_JMF_BL, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 15 Jan 2011 10:09:19 +0000 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id 24F7F1224E; Sat, 15 Jan 2011 11:09:15 +0100 (CET) Received: from [192.168.0.197] (xdsl-78-35-167-101.netcologne.de [78.35.167.101]) by cc-smtpin1.netcologne.de (Postfix) with ESMTP id 00FFA11E80; Sat, 15 Jan 2011 11:09:13 +0100 (CET) Message-ID: <4D317249.30509@netcologne.de> Date: Sat, 15 Jan 2011 11:09:13 +0100 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.1.16) Gecko/20101125 SUSE/3.0.11 Thunderbird/3.0.11 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] Fix PR 38536 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 Hello world, the attached patch fixes the PR by inserting additional checks in resolve.c to catch the invalid array sections. Regression-tested. OK for trunk? Thomas 2011-01-15 Thomas Koenig PR fortran/38536 * resolve.c (gfc_iso_c_func_interface): For C_LOC, check for array sections which are illegal. 2011-01-15 Thomas Koenig PR fortran/38536 * gfortran.dg/c_loc_tests_16.f90: New test. ! { dg-do compile } ! PR 38536 - array sections as arguments to c_loc are illegal. use iso_c_binding type, bind(c) :: t1 integer(c_int) :: i(5) end type t1 type, bind(c):: t2 type(t1) :: t(5) end type t2 type(t2), target :: tt integer(c_int), target :: n(3) type(C_PTR) :: p p = c_loc(tt%t%i(1)) ! { dg-error "Array section not permitted" } p = c_loc(n(1:2)) ! { dg-error "Array section not permitted" } end Index: resolve.c =================================================================== --- resolve.c (Revision 168614) +++ resolve.c (Arbeitskopie) @@ -2709,6 +2709,8 @@ gfc_iso_c_func_interface (gfc_symbol *sym, gfc_act } else if (sym->intmod_sym_id == ISOCBINDING_LOC) { + gfc_ref *ref; + /* Make sure we have either the target or pointer attribute. */ if (!arg_attr.target && !arg_attr.pointer) { @@ -2719,6 +2721,23 @@ gfc_iso_c_func_interface (gfc_symbol *sym, gfc_act retval = FAILURE; } + /* Follow references to make sure there are no array + slices. */ + for (ref=args->expr->ref; ref; ref = ref->next) + { + if (ref->type == REF_ARRAY) + { + if (ref->u.ar.type == AR_SECTION + || (ref->u.ar.type != AR_ELEMENT && + ref->next && ref->next->type == REF_COMPONENT)) + { + gfc_error_now ("Array section not permitted in '%s'" + " call at %L", name, &(args->expr->where)); + retval = FAILURE; + } + } + } + /* See if we have interoperable type and type param. */ if (verify_c_interop (arg_ts) == SUCCESS || gfc_check_any_c_kind (arg_ts) == SUCCESS)