diff options
author | Thomas Koenig <Thomas.Koenig@online.de> | 2006-03-03 16:18:46 +0000 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2006-03-03 16:18:46 +0000 |
commit | 5b725b8d04fff8583103bbea88f3d42f5443367d (patch) | |
tree | 2053327438b596f44709a80d2095a44b82bdb8f7 /libgfortran | |
parent | 9a75ede07ca08c69fd38acafea04cc2e1a7bfd10 (diff) | |
download | gcc-5b725b8d04fff8583103bbea88f3d42f5443367d.zip gcc-5b725b8d04fff8583103bbea88f3d42f5443367d.tar.gz gcc-5b725b8d04fff8583103bbea88f3d42f5443367d.tar.bz2 |
re PR fortran/25031 ([4.1 only] Allocatable array can be reallocated.)
2006-03-03 Thomas Koenig <Thomas.Koenig@online.de>
PR fortran/25031
* trans-array.h: Adjust gfc_array_allocate prototype.
* trans-array.c (gfc_array_allocate): Change type of
gfc_array_allocatate to bool. Function returns true if
it operates on an array. Change second argument to gfc_expr.
Find last reference in chain.
If the function operates on an allocatable array, emit call to
allocate_array() or allocate64_array().
* trans-stmt.c (gfc_trans_allocate): Code to follow to last
reference has been moved to gfc_array_allocate.
* trans.h: Add declaration for gfor_fndecl_allocate_array and
gfor_fndecl_allocate64_array.
(gfc_build_builtin_function_decls): Add gfor_fndecl_allocate_array
and gfor_fndecl_allocate64_array.
2006-03-03 Thomas Koenig <Thomas.Koenig@online.de>
PR fortran/25031
* runtime/memory.c: Adjust copyright years.
(allocate_array): New function.
(allocate64_array): New function.
* libgfortran.h (error_codes): Add ERROR_ALLOCATION.
2006-03-03 Thomas Koenig <Thomas.Koenig@online.de>
PR fortran/25031
* multiple_allocation_1.f90: New test.
From-SVN: r111677
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 8 | ||||
-rw-r--r-- | libgfortran/libgfortran.h | 1 | ||||
-rw-r--r-- | libgfortran/runtime/memory.c | 47 |
3 files changed, 55 insertions, 1 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 39039a6..ff9e599 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,11 @@ +2006-03-03 Thomas Koenig <Thomas.Koenig@online.de> + + PR fortran/25031 + * runtime/memory.c: Adjust copyright years. + (allocate_array): New function. + (allocate64_array): New function. + * libgfortran.h (error_codes): Add ERROR_ALLOCATION. + 2006-02-28 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libgfortran/26136 diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h index 524c57e..5efc8ae 100644 --- a/libgfortran/libgfortran.h +++ b/libgfortran/libgfortran.h @@ -379,6 +379,7 @@ typedef enum ERROR_READ_OVERFLOW, ERROR_INTERNAL, ERROR_INTERNAL_UNIT, + ERROR_ALLOCATION, ERROR_LAST /* Not a real error, the last error # + 1. */ } error_codes; diff --git a/libgfortran/runtime/memory.c b/libgfortran/runtime/memory.c index d52319f..34d70f2 100644 --- a/libgfortran/runtime/memory.c +++ b/libgfortran/runtime/memory.c @@ -1,5 +1,5 @@ /* Memory mamagement routines. - Copyright 2002, 2005 Free Software Foundation, Inc. + Copyright 2002, 2005, 2006 Free Software Foundation, Inc. Contributed by Paul Brook <paul@nowt.org> This file is part of the GNU Fortran 95 runtime library (libgfortran). @@ -233,6 +233,51 @@ allocate64 (void **mem, GFC_INTEGER_8 size, GFC_INTEGER_4 * stat) allocate_size (mem, (size_t) size, stat); } +/* Function to call in an ALLOCATE statement when the argument is an + allocatable array. If the array is currently allocated, it is + an error to allocate it again. 32-bit version. */ + +extern void allocate_array (void **, GFC_INTEGER_4, GFC_INTEGER_4 *); +export_proto(allocate_array); + +void +allocate_array (void **mem, GFC_INTEGER_4 size, GFC_INTEGER_4 * stat) +{ + if (*mem == NULL) + { + allocate (mem, size, stat); + return; + } + if (stat) + *stat = ERROR_ALLOCATION; + else + runtime_error ("Attempting to allocate already allocated array."); + + return; +} + +/* Function to call in an ALLOCATE statement when the argument is an + allocatable array. If the array is currently allocated, it is + an error to allocate it again. 64-bit version. */ + +extern void allocate64_array (void **, GFC_INTEGER_8, GFC_INTEGER_4 *); +export_proto(allocate64_array); + +void +allocate64_array (void **mem, GFC_INTEGER_8 size, GFC_INTEGER_4 * stat) +{ + if (*mem == NULL) + { + allocate64 (mem, size, stat); + return; + } + if (stat) + *stat = ERROR_ALLOCATION; + else + runtime_error ("Attempting to allocate already allocated array."); + + return; +} /* User-deallocate; pointer is NULLified. */ |