From patchwork Mon Jun 27 22:18:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 102286 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 5FFEEB6F54 for ; Tue, 28 Jun 2011 08:18:37 +1000 (EST) Received: (qmail 9362 invoked by alias); 27 Jun 2011 22:18:36 -0000 Received: (qmail 9345 invoked by uid 22791); 27 Jun 2011 22:18:35 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, 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; Mon, 27 Jun 2011 22:18:20 +0000 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id 54BBA12564; Tue, 28 Jun 2011 00:18:17 +0200 (CEST) Received: from [192.168.0.199] (xdsl-84-44-178-63.netcologne.de [84.44.178.63]) by cc-smtpin1.netcologne.de (Postfix) with ESMTPSA id 1B22911E75; Tue, 28 Jun 2011 00:18:15 +0200 (CEST) Message-ID: <4E0901A7.90905@netcologne.de> Date: Tue, 28 Jun 2011 00:18:15 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.17) Gecko/20110414 SUSE/3.1.10 Thunderbird/3.1.10 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] Fix PR 49479, reshape with optional arg 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 PR 49479, a regression for 4.7 and 4.6. Test case was supplied by Joost, the approach to the patch was suggested by Tobias in comment#4 of the PR. The patch certainly looks safe enough. Regression-tested. OK for trunk and, after a couple of days, for 4.6? Thomas 2011-06-27 Thomas Koenig PR fortran/49479 * m4/reshape.m4: If source allocation is smaller than one, set it to one. * generated/reshape_r16.c: Regenerated. * generated/reshape_c4.c: Regenerated. * generated/reshape_c16.c: Regenerated. * generated/reshape_c8.c: Regenerated. * generated/reshape_r4.c: Regenerated. * generated/reshape_i4.c: Regenerated. * generated/reshape_r10.c: Regenerated. * generated/reshape_r8.c: Regenerated. * generated/reshape_c10.c: Regenerated. * generated/reshape_i8.c: Regenerated. * generated/reshape_i16.c: Regenerated. 2011-06-27 Thomas Koenig PR fortran/49479 * gfortran.dg/reshape_zerosize_3.f90: New test. ! { dg-do run } ! PR 49479 - this used not to print anything. ! Test case by Joost VandeVondele. MODULE M1 IMPLICIT NONE CONTAINS SUBROUTINE S1(data) INTEGER, DIMENSION(:), INTENT(IN), & OPTIONAL :: DATA character(20) :: line IF (.not. PRESENT(data)) call abort write (unit=line,fmt='(I5)') size(data) if (line /= ' 0 ') call abort END SUBROUTINE SUBROUTINE S2(N) INTEGER :: N INTEGER, ALLOCATABLE, DIMENSION(:, :) :: blki ALLOCATE(blki(3,N)) blki=0 CALL S1(RESHAPE(blki,(/3*N/))) END SUBROUTINE S2 END MODULE M1 USE M1 CALL S2(0) END ! { dg-final { cleanup-modules "m1" } } Index: m4/reshape.m4 =================================================================== --- m4/reshape.m4 (Revision 175543) +++ m4/reshape.m4 (Arbeitskopie) @@ -101,6 +101,8 @@ if (ret->data == NULL) { + index_type alloc_size; + rs = 1; for (n = 0; n < rdim; n++) { @@ -111,7 +113,13 @@ rs *= rex; } ret->offset = 0; - ret->data = internal_malloc_size ( rs * sizeof ('rtype_name`)); + + if (unlikely (rs < 1)) + alloc_size = 1; + else + alloc_size = rs * sizeof ('rtype_name`); + + ret->data = internal_malloc_size (alloc_size); ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim; }