From patchwork Thu Oct 21 11:37:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 68594 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 ABD35B6EE9 for ; Thu, 21 Oct 2010 22:37:46 +1100 (EST) Received: (qmail 13202 invoked by alias); 21 Oct 2010 11:37:42 -0000 Received: (qmail 13115 invoked by uid 22791); 21 Oct 2010 11:37:40 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp5.netcologne.de (HELO smtp5.netcologne.de) (194.8.194.25) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 21 Oct 2010 11:37:31 +0000 Received: from [192.168.0.197] (xdsl-78-34-108-159.netcologne.de [78.34.108.159]) by smtp5.netcologne.de (Postfix) with ESMTP id 7E17940CCBC; Thu, 21 Oct 2010 13:37:28 +0200 (CEST) Subject: [patch, fortran] Fix PR 46007, segfault with shape From: Thomas Koenig To: fortran@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org Date: Thu, 21 Oct 2010 13:37:27 +0200 Message-ID: <1287661047.3660.12.camel@linux-fd1f.site> Mime-Version: 1.0 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, this rather straightforward patch fixes PR 46007. Regression-tested on trunk. OK for trunk? Also OK for 4.5 after regression-testing there? Thomas 2010-10-21 Thomas Koenig PR fortran/46007 * m4/shape.m4 (shape_'rtype_kind`): Use variable for rank. Allocate return array if unallocated. * generated/shape_i4.c: Regenerated. * generated/shape_i8.c: Regenerated. * generated/shape_i16.c: Regenerated. 2010-10-21 Thomas Koenig PR fortran/46007 * gfortran.dg/shape_5.f90: New test case. Index: m4/shape.m4 =================================================================== --- m4/shape.m4 (Revision 165561) +++ m4/shape.m4 (Arbeitskopie) @@ -42,13 +42,23 @@ shape_'rtype_kind` ('rtype` * const restrict ret, int n; index_type stride; index_type extent; + int rank; + rank = GFC_DESCRIPTOR_RANK (array); + + if (ret->data == NULL) + { + GFC_DIMENSION_SET(ret->dim[0], 0, rank - 1, 1); + ret->offset = 0; + ret->data = internal_malloc_size (sizeof ('rtype_name`) * rank); + } + stride = GFC_DESCRIPTOR_STRIDE(ret,0); if (GFC_DESCRIPTOR_EXTENT(ret,0) < 1) return; - for (n = 0; n < GFC_DESCRIPTOR_RANK (array); n++) + for (n = 0; n < rank; n++) { extent = GFC_DESCRIPTOR_EXTENT(array,n); ret->data[n * stride] = extent > 0 ? extent : 0 ;