From patchwork Fri Jul 22 18:54:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Carrera X-Patchwork-Id: 106378 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 2007BB6F64 for ; Sat, 23 Jul 2011 04:55:01 +1000 (EST) Received: (qmail 23572 invoked by alias); 22 Jul 2011 18:54:59 -0000 Received: (qmail 23554 invoked by uid 22791); 22 Jul 2011 18:54:57 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, TW_TM X-Spam-Check-By: sourceware.org Received: from mail-fx0-f49.google.com (HELO mail-fx0-f49.google.com) (209.85.161.49) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 22 Jul 2011 18:54:40 +0000 Received: by fxd20 with SMTP id 20so4351506fxd.22 for ; Fri, 22 Jul 2011 11:54:39 -0700 (PDT) Received: by 10.223.155.141 with SMTP id s13mr761263faw.109.1311360878811; Fri, 22 Jul 2011 11:54:38 -0700 (PDT) Received: from [192.168.10.107] (h-187-67.a189.priv.bahnhof.se [85.24.187.67]) by mx.google.com with ESMTPS id j19sm2212370faa.17.2011.07.22.11.54.37 (version=SSLv3 cipher=OTHER); Fri, 22 Jul 2011 11:54:38 -0700 (PDT) Message-ID: <4E29C76C.1070409@gmail.com> Date: Fri, 22 Jul 2011 20:54:36 +0200 From: Daniel Carrera User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 To: gfortran , gcc patches Subject: [Patch, Fotran] Fix PR 4755 - Do not free + reallocate a variable that is already allocated. 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, This is a simple patch that fixes PR 4755. Currently the ALLOCATE statement will free and re-allocate an already allocated scalar. The Fortran standard says that this is an error. The attached patch fixes the problem. I am also attaching two tree dumps of the same program, compiled before and after the application of this patch. The test program is this: program test integer, allocatable :: A(:), B[:] integer :: stat character(len=33) :: str allocate(A(1), B[*], stat=stat) end program If you compare the "before" and "after" files you'll see that with this patch GCC no longer tries to free and reallocate A(1). You will also notice that the block for B[*] didn't change. The block for B[*] is already correct in trunk and doesn't need changing. Here is my ChangeLog: 2011-07-22 Daniel Carrera * trans.c (gfc__allocate_allocatable): [PR 4755] Do not fix and the reallocate a variable that is already allocated. diff -r c8b6eb02738a gcc/fortran/trans.c --- a/gcc/fortran/trans.c Fri Jul 22 09:21:49 2011 +0000 +++ b/gcc/fortran/trans.c Fri Jul 22 20:36:23 2011 +0200 @@ -775,13 +775,8 @@ gfc_allocate_allocatable (stmtblock_t * stmtblock_t set_status_block; gfc_start_block (&set_status_block); - tmp = build_call_expr_loc (input_location, - built_in_decls[BUILT_IN_FREE], 1, - fold_convert (pvoid_type_node, mem)); - gfc_add_expr_to_block (&set_status_block, tmp); - tmp = gfc_allocate_using_malloc (&set_status_block, size, status); - gfc_add_modify (&set_status_block, res, fold_convert (type, tmp)); + gfc_add_modify (&set_status_block, res, fold_convert (type, mem)); gfc_add_modify (&set_status_block, status, build_int_cst (status_type, LIBERROR_ALLOCATION));