From patchwork Tue Apr 30 16:56:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 240669 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id C3A012C00CC for ; Wed, 1 May 2013 02:56:53 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=l8Wx4/QLMYkNwYoQJct3ZudAgy6BnFWadpgMYj8d5hLxTp WkCUWkdJGSIlVOJ8unZehb0jcIaSxOToukXeXsfG4gdgJajDJUz7ZrtTO94TlIZq g5ymtCgK0APsAemYyLuldB7GHz+jzmfDYHUciCkU7RD7q8IucgjdeAzoWRR6U= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=8QF1pBvukoSly58T/LpwlFvnAHE=; b=gRV2s7/Ume/ZoQUiHIbJ snoLPnNaszURq2wgHfu6s/cdlxonHKZXStP0N+10Mwx+vZtlxqZ0oY/YU0c/CYSV B0kaxKrYBegB5+0ozGJUUo1/YcTajBQbyV/RUwyMzbtIFyQQTLHlFgL98fr2wk3x QhZyPMEPqwkvsnxQQDcrRdk= Received: (qmail 21395 invoked by alias); 30 Apr 2013 16:56:47 -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 21376 invoked by uid 89); 30 Apr 2013 16:56:46 -0000 X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SEMBACKSCATTER autolearn=no version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 30 Apr 2013 16:56:45 +0000 Received: from archimedes.net-b.de (port-92-195-76-58.dynamic.qsc.de [92.195.76.58]) by mx01.qsc.de (Postfix) with ESMTP id 8579F939A; Tue, 30 Apr 2013 18:56:42 +0200 (CEST) Message-ID: <517FF7C9.4060306@net-b.de> Date: Tue, 30 Apr 2013 18:56:41 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] Avoid segfault in conformable_arrays X-Virus-Found: No The issue was found by Reinhold Bader when testing the Fortran-Dev branch (thanks!), but it also affects GCC 4.6 and later. The patch is rather obvious: The segfault occured as tail->u.ar.start[i] == NULL. An alternative is to could use "continue" instead of "break". Build and regtested on x86-64-gnu-linux. OK for the trunk? Tobias PS: The test case is invalid Fortran 2003 but valid Fortran 2008. As gfortran lacks that feature, it unconditionally rejects the test case. Work around is to add a "(1)" to the alloc-expr. 2013-04-30 Tobias Burnus * resolve.c (conformable_arrays): Avoid segfault when ar.start[i] == NULL. 2013-04-30 Tobias Burnus * gfortran.dg/allocate_with_source_3.f90: New. diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 6e1f56f..0f2fce0 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -6498,24 +6498,27 @@ conformable_arrays (gfc_expr *e1, gfc_expr *e2) return false; } if (e1->shape) { int i; mpz_t s; mpz_init (s); for (i = 0; i < e1->rank; i++) { + if (tail->u.ar.start[i] == NULL) + break; + if (tail->u.ar.end[i]) { mpz_set (s, tail->u.ar.end[i]->value.integer); mpz_sub (s, s, tail->u.ar.start[i]->value.integer); mpz_add_ui (s, s, 1); } else { mpz_set (s, tail->u.ar.start[i]->value.integer); } if (mpz_cmp (e1->shape[i], s) != 0) --- /dev/null 2013-04-30 09:21:48.687062896 +0200 +++ gcc/gcc/testsuite/gfortran.dg/allocate_with_source_3.f90 2013-04-30 18:13:52.884740171 +0200 @@ -0,0 +1,28 @@ +! { dg-do compile } +! +! Contributed by Reinhold Bader +! +program assumed_shape_01 + use, intrinsic :: iso_c_binding + implicit none + type, bind(c) :: cstruct + integer(c_int) :: i + real(c_float) :: r(2) + end type cstruct + interface + subroutine psub(this, that) bind(c, name='Psub') + import :: c_float, cstruct + real(c_float) :: this(:,:) + type(cstruct) :: that(:) + end subroutine psub + end interface + + real(c_float) :: t(3,7) + type(cstruct), pointer :: u(:) + +! The following is VALID Fortran 2008 but NOT YET supported + allocate(u, source=[cstruct( 4, [1.1,2.2] ) ]) ! { dg-error "Array specification required in ALLOCATE statement" } + call psub(t, u) + deallocate (u) + +end program assumed_shape_01