Patchwork [libfortran] Combine get_mem and internal_malloc_size

login
register
mail settings
Submitter Janne Blomqvist
Date March 26, 2012, 3:17 p.m.
Message ID <CAO9iq9GMqaXb-87sMkCGki-5MoGf_D505QvwG9WoRFRhAXkMJA@mail.gmail.com>
Download mbox | patch
Permalink /patch/148766/
State New
Headers show

Comments

Janne Blomqvist - March 26, 2012, 3:17 p.m.
Hi,

currently in libgfortran we have two malloc() wrappers, get_mem and
internal_malloc_size, which abort the program if malloc fails.
internal_malloc_size does

if (size == 0)
    size = 1;

and then calls get_mem, which doesn't have such a zero-size check.
This is, however, a bug in get_mem, as malloc(0) is allowed to return
NULL, and in that case get_mem would incorrectly abort the program.
Thus having both these functions is unnecessary. The attached patch
combines these two functions into one.  As I couldn't decide between
get_mem and internal_malloc_size and didn't particularly like either
of the names, I named the combined function "xmalloc", as is common
for such functions to be called.

When developing the patch, I noticed that the implementations of the
intrinsics IALL, IANY, IPARITY, NORM2, and PARITY weren't being
regenerated from the m4 sources. The reason, it turned out, was that
the dependencies were specified incorrectly in Makefile.am. The patch
also fixes this.

Regtested on x86_64-unknown-linux-gnu. While the patch is large, it's
also mechanical, hence committed as obvious.


2012-03-26  Janne Blomqvist  <jb@gcc.gnu.org>

	* runtime/memory.c (get_mem): Rename to xmalloc, check for zero
	size.
	(internal_malloc_size): Remove.
	* libgfortran.h (get_mem): Rename to xmalloc.
	(internal_malloc_size): Remove prototype.
	* Makefile.am (i_iall_c): Fix dependency.
	(i_iany_c): Likewise.
	(i_iparity_c): Likewise.
	(i_norm2_c): Likewise.
	(i_parity_c): Likewise.
	* Makefile.in: Regenerated.
	* m4/parity.m4: Fix typo in comment.
	* generated/all_l1.c: Regenerated.
	* generated/all_l16.c: Regenerated.
	* generated/all_l2.c: Regenerated.
	* generated/all_l4.c: Regenerated.
	* generated/all_l8.c: Regenerated.
	* generated/any_l1.c: Regenerated.
	* generated/any_l16.c: Regenerated.
	* generated/any_l2.c: Regenerated.
	* generated/any_l4.c: Regenerated.
	* generated/any_l8.c: Regenerated.
	* generated/bessel_r10.c: Regenerated.
	* generated/bessel_r16.c: Regenerated.
	* generated/bessel_r4.c: Regenerated.
	* generated/bessel_r8.c: Regenerated.
	* generated/count_16_l.c: Regenerated.
	* generated/count_1_l.c: Regenerated.
	* generated/count_2_l.c: Regenerated.
	* generated/count_4_l.c: Regenerated.
	* generated/count_8_l.c: Regenerated.
	* generated/cshift1_16.c: Regenerated.
	* generated/cshift1_4.c: Regenerated.
	* generated/cshift1_8.c: Regenerated.
	* generated/eoshift1_16.c: Regenerated.
	* generated/eoshift1_4.c: Regenerated.
	* generated/eoshift1_8.c: Regenerated.
	* generated/eoshift3_16.c: Regenerated.
	* generated/eoshift3_4.c: Regenerated.
	* generated/eoshift3_8.c: Regenerated.
	* generated/iall_i1.c: Regenerated.
	* generated/iall_i16.c: Regenerated.
	* generated/iall_i2.c: Regenerated.
	* generated/iall_i4.c: Regenerated.
	* generated/iall_i8.c: Regenerated.
	* generated/iany_i1.c: Regenerated.
	* generated/iany_i16.c: Regenerated.
	* generated/iany_i2.c: Regenerated.
	* generated/iany_i4.c: Regenerated.
	* generated/iany_i8.c: Regenerated.
	* generated/in_pack_c10.c: Regenerated.
	* generated/in_pack_c16.c: Regenerated.
	* generated/in_pack_c4.c: Regenerated.
	* generated/in_pack_c8.c: Regenerated.
	* generated/in_pack_i1.c: Regenerated.
	* generated/in_pack_i16.c: Regenerated.
	* generated/in_pack_i2.c: Regenerated.
	* generated/in_pack_i4.c: Regenerated.
	* generated/in_pack_i8.c: Regenerated.
	* generated/in_pack_r10.c: Regenerated.
	* generated/in_pack_r16.c: Regenerated.
	* generated/in_pack_r4.c: Regenerated.
	* generated/in_pack_r8.c: Regenerated.
	* generated/iparity_i1.c: Regenerated.
	* generated/iparity_i16.c: Regenerated.
	* generated/iparity_i2.c: Regenerated.
	* generated/iparity_i4.c: Regenerated.
	* generated/iparity_i8.c: Regenerated.
	* generated/matmul_c10.c: Regenerated.
	* generated/matmul_c16.c: Regenerated.
	* generated/matmul_c4.c: Regenerated.
	* generated/matmul_c8.c: Regenerated.
	* generated/matmul_i1.c: Regenerated.
	* generated/matmul_i16.c: Regenerated.
	* generated/matmul_i2.c: Regenerated.
	* generated/matmul_i4.c: Regenerated.
	* generated/matmul_i8.c: Regenerated.
	* generated/matmul_l16.c: Regenerated.
	* generated/matmul_l4.c: Regenerated.
	* generated/matmul_l8.c: Regenerated.
	* generated/matmul_r10.c: Regenerated.
	* generated/matmul_r16.c: Regenerated.
	* generated/matmul_r4.c: Regenerated.
	* generated/matmul_r8.c: Regenerated.
	* generated/maxloc0_16_i1.c: Regenerated.
	* generated/maxloc0_16_i16.c: Regenerated.
	* generated/maxloc0_16_i2.c: Regenerated.
	* generated/maxloc0_16_i4.c: Regenerated.
	* generated/maxloc0_16_i8.c: Regenerated.
	* generated/maxloc0_16_r10.c: Regenerated.
	* generated/maxloc0_16_r16.c: Regenerated.
	* generated/maxloc0_16_r4.c: Regenerated.
	* generated/maxloc0_16_r8.c: Regenerated.
	* generated/maxloc0_4_i1.c: Regenerated.
	* generated/maxloc0_4_i16.c: Regenerated.
	* generated/maxloc0_4_i2.c: Regenerated.
	* generated/maxloc0_4_i4.c: Regenerated.
	* generated/maxloc0_4_i8.c: Regenerated.
	* generated/maxloc0_4_r10.c: Regenerated.
	* generated/maxloc0_4_r16.c: Regenerated.
	* generated/maxloc0_4_r4.c: Regenerated.
	* generated/maxloc0_4_r8.c: Regenerated.
	* generated/maxloc0_8_i1.c: Regenerated.
	* generated/maxloc0_8_i16.c: Regenerated.
	* generated/maxloc0_8_i2.c: Regenerated.
	* generated/maxloc0_8_i4.c: Regenerated.
	* generated/maxloc0_8_i8.c: Regenerated.
	* generated/maxloc0_8_r10.c: Regenerated.
	* generated/maxloc0_8_r16.c: Regenerated.
	* generated/maxloc0_8_r4.c: Regenerated.
	* generated/maxloc0_8_r8.c: Regenerated.
	* generated/maxloc1_16_i1.c: Regenerated.
	* generated/maxloc1_16_i16.c: Regenerated.
	* generated/maxloc1_16_i2.c: Regenerated.
	* generated/maxloc1_16_i4.c: Regenerated.
	* generated/maxloc1_16_i8.c: Regenerated.
	* generated/maxloc1_16_r10.c: Regenerated.
	* generated/maxloc1_16_r16.c: Regenerated.
	* generated/maxloc1_16_r4.c: Regenerated.
	* generated/maxloc1_16_r8.c: Regenerated.
	* generated/maxloc1_4_i1.c: Regenerated.
	* generated/maxloc1_4_i16.c: Regenerated.
	* generated/maxloc1_4_i2.c: Regenerated.
	* generated/maxloc1_4_i4.c: Regenerated.
	* generated/maxloc1_4_i8.c: Regenerated.
	* generated/maxloc1_4_r10.c: Regenerated.
	* generated/maxloc1_4_r16.c: Regenerated.
	* generated/maxloc1_4_r4.c: Regenerated.
	* generated/maxloc1_4_r8.c: Regenerated.
	* generated/maxloc1_8_i1.c: Regenerated.
	* generated/maxloc1_8_i16.c: Regenerated.
	* generated/maxloc1_8_i2.c: Regenerated.
	* generated/maxloc1_8_i4.c: Regenerated.
	* generated/maxloc1_8_i8.c: Regenerated.
	* generated/maxloc1_8_r10.c: Regenerated.
	* generated/maxloc1_8_r16.c: Regenerated.
	* generated/maxloc1_8_r4.c: Regenerated.
	* generated/maxloc1_8_r8.c: Regenerated.
	* generated/maxval_i1.c: Regenerated.
	* generated/maxval_i16.c: Regenerated.
	* generated/maxval_i2.c: Regenerated.
	* generated/maxval_i4.c: Regenerated.
	* generated/maxval_i8.c: Regenerated.
	* generated/maxval_r10.c: Regenerated.
	* generated/maxval_r16.c: Regenerated.
	* generated/maxval_r4.c: Regenerated.
	* generated/maxval_r8.c: Regenerated.
	* generated/minloc0_16_i1.c: Regenerated.
	* generated/minloc0_16_i16.c: Regenerated.
	* generated/minloc0_16_i2.c: Regenerated.
	* generated/minloc0_16_i4.c: Regenerated.
	* generated/minloc0_16_i8.c: Regenerated.
	* generated/minloc0_16_r10.c: Regenerated.
	* generated/minloc0_16_r16.c: Regenerated.
	* generated/minloc0_16_r4.c: Regenerated.
	* generated/minloc0_16_r8.c: Regenerated.
	* generated/minloc0_4_i1.c: Regenerated.
	* generated/minloc0_4_i16.c: Regenerated.
	* generated/minloc0_4_i2.c: Regenerated.
	* generated/minloc0_4_i4.c: Regenerated.
	* generated/minloc0_4_i8.c: Regenerated.
	* generated/minloc0_4_r10.c: Regenerated.
	* generated/minloc0_4_r16.c: Regenerated.
	* generated/minloc0_4_r4.c: Regenerated.
	* generated/minloc0_4_r8.c: Regenerated.
	* generated/minloc0_8_i1.c: Regenerated.
	* generated/minloc0_8_i16.c: Regenerated.
	* generated/minloc0_8_i2.c: Regenerated.
	* generated/minloc0_8_i4.c: Regenerated.
	* generated/minloc0_8_i8.c: Regenerated.
	* generated/minloc0_8_r10.c: Regenerated.
	* generated/minloc0_8_r16.c: Regenerated.
	* generated/minloc0_8_r4.c: Regenerated.
	* generated/minloc0_8_r8.c: Regenerated.
	* generated/minloc1_16_i1.c: Regenerated.
	* generated/minloc1_16_i16.c: Regenerated.
	* generated/minloc1_16_i2.c: Regenerated.
	* generated/minloc1_16_i4.c: Regenerated.
	* generated/minloc1_16_i8.c: Regenerated.
	* generated/minloc1_16_r10.c: Regenerated.
	* generated/minloc1_16_r16.c: Regenerated.
	* generated/minloc1_16_r4.c: Regenerated.
	* generated/minloc1_16_r8.c: Regenerated.
	* generated/minloc1_4_i1.c: Regenerated.
	* generated/minloc1_4_i16.c: Regenerated.
	* generated/minloc1_4_i2.c: Regenerated.
	* generated/minloc1_4_i4.c: Regenerated.
	* generated/minloc1_4_i8.c: Regenerated.
	* generated/minloc1_4_r10.c: Regenerated.
	* generated/minloc1_4_r16.c: Regenerated.
	* generated/minloc1_4_r4.c: Regenerated.
	* generated/minloc1_4_r8.c: Regenerated.
	* generated/minloc1_8_i1.c: Regenerated.
	* generated/minloc1_8_i16.c: Regenerated.
	* generated/minloc1_8_i2.c: Regenerated.
	* generated/minloc1_8_i4.c: Regenerated.
	* generated/minloc1_8_i8.c: Regenerated.
	* generated/minloc1_8_r10.c: Regenerated.
	* generated/minloc1_8_r16.c: Regenerated.
	* generated/minloc1_8_r4.c: Regenerated.
	* generated/minloc1_8_r8.c: Regenerated.
	* generated/minval_i1.c: Regenerated.
	* generated/minval_i16.c: Regenerated.
	* generated/minval_i2.c: Regenerated.
	* generated/minval_i4.c: Regenerated.
	* generated/minval_i8.c: Regenerated.
	* generated/minval_r10.c: Regenerated.
	* generated/minval_r16.c: Regenerated.
	* generated/minval_r4.c: Regenerated.
	* generated/minval_r8.c: Regenerated.
	* generated/norm2_r10.c: Regenerated.
	* generated/norm2_r16.c: Regenerated.
	* generated/norm2_r4.c: Regenerated.
	* generated/norm2_r8.c: Regenerated.
	* generated/pack_c10.c: Regenerated.
	* generated/pack_c16.c: Regenerated.
	* generated/pack_c4.c: Regenerated.
	* generated/pack_c8.c: Regenerated.
	* generated/pack_i1.c: Regenerated.
	* generated/pack_i16.c: Regenerated.
	* generated/pack_i2.c: Regenerated.
	* generated/pack_i4.c: Regenerated.
	* generated/pack_i8.c: Regenerated.
	* generated/pack_r10.c: Regenerated.
	* generated/pack_r16.c: Regenerated.
	* generated/pack_r4.c: Regenerated.
	* generated/pack_r8.c: Regenerated.
	* generated/parity_l1.c: Regenerated.
	* generated/parity_l16.c: Regenerated.
	* generated/parity_l2.c: Regenerated.
	* generated/parity_l4.c: Regenerated.
	* generated/parity_l8.c: Regenerated.
	* generated/product_c10.c: Regenerated.
	* generated/product_c16.c: Regenerated.
	* generated/product_c4.c: Regenerated.
	* generated/product_c8.c: Regenerated.
	* generated/product_i1.c: Regenerated.
	* generated/product_i16.c: Regenerated.
	* generated/product_i2.c: Regenerated.
	* generated/product_i4.c: Regenerated.
	* generated/product_i8.c: Regenerated.
	* generated/product_r10.c: Regenerated.
	* generated/product_r16.c: Regenerated.
	* generated/product_r4.c: Regenerated.
	* generated/product_r8.c: Regenerated.
	* generated/reshape_c10.c: Regenerated.
	* generated/reshape_c16.c: Regenerated.
	* generated/reshape_c4.c: Regenerated.
	* generated/reshape_c8.c: Regenerated.
	* generated/reshape_i16.c: Regenerated.
	* generated/reshape_i4.c: Regenerated.
	* generated/reshape_i8.c: Regenerated.
	* generated/reshape_r10.c: Regenerated.
	* generated/reshape_r16.c: Regenerated.
	* generated/reshape_r4.c: Regenerated.
	* generated/reshape_r8.c: Regenerated.
	* generated/shape_i16.c: Regenerated.
	* generated/shape_i4.c: Regenerated.
	* generated/shape_i8.c: Regenerated.
	* generated/spread_c10.c: Regenerated.
	* generated/spread_c16.c: Regenerated.
	* generated/spread_c4.c: Regenerated.
	* generated/spread_c8.c: Regenerated.
	* generated/spread_i1.c: Regenerated.
	* generated/spread_i16.c: Regenerated.
	* generated/spread_i2.c: Regenerated.
	* generated/spread_i4.c: Regenerated.
	* generated/spread_i8.c: Regenerated.
	* generated/spread_r10.c: Regenerated.
	* generated/spread_r16.c: Regenerated.
	* generated/spread_r4.c: Regenerated.
	* generated/spread_r8.c: Regenerated.
	* generated/sum_c10.c: Regenerated.
	* generated/sum_c16.c: Regenerated.
	* generated/sum_c4.c: Regenerated.
	* generated/sum_c8.c: Regenerated.
	* generated/sum_i1.c: Regenerated.
	* generated/sum_i16.c: Regenerated.
	* generated/sum_i2.c: Regenerated.
	* generated/sum_i4.c: Regenerated.
	* generated/sum_i8.c: Regenerated.
	* generated/sum_r10.c: Regenerated.
	* generated/sum_r16.c: Regenerated.
	* generated/sum_r4.c: Regenerated.
	* generated/sum_r8.c: Regenerated.
	* generated/transpose_c10.c: Regenerated.
	* generated/transpose_c16.c: Regenerated.
	* generated/transpose_c4.c: Regenerated.
	* generated/transpose_c8.c: Regenerated.
	* generated/transpose_i16.c: Regenerated.
	* generated/transpose_i4.c: Regenerated.
	* generated/transpose_i8.c: Regenerated.
	* generated/transpose_r10.c: Regenerated.
	* generated/transpose_r16.c: Regenerated.
	* generated/transpose_r4.c: Regenerated.
	* generated/transpose_r8.c: Regenerated.
	* generated/unpack_c10.c: Regenerated.
	* generated/unpack_c16.c: Regenerated.
	* generated/unpack_c4.c: Regenerated.
	* generated/unpack_c8.c: Regenerated.
	* generated/unpack_i1.c: Regenerated.
	* generated/unpack_i16.c: Regenerated.
	* generated/unpack_i2.c: Regenerated.
	* generated/unpack_i4.c: Regenerated.
	* generated/unpack_i8.c: Regenerated.
	* generated/unpack_r10.c: Regenerated.
	* generated/unpack_r16.c: Regenerated.
	* generated/unpack_r4.c: Regenerated.
	* generated/unpack_r8.c: Regenerated.
	* intrinsics/cshift0.c: Use xmalloc.
	* intrinsics/ctime.c: Likewise.
	* intrinsics/date_and_time.c: Likewise.
	* intrinsics/eoshift0.c: Likewise.
	* intrinsics/eoshift2.c: Likewise.
	* intrinsics/getlog.c: Likewise.
	* intrinsics/pack_generic.c: Likewise.
	* intrinsics/reshape_generic.c: Likewise.
	* intrinsics/spread_generic.c: Likewise.
	* intrinsics/string_intrinsics_inc.c: Likewise.
	* intrinsics/transpose_generic.c: Likewise.
	* intrinsics/unpack_generic.c: Likewise.
	* io/fbuf.c: Likewise.
	* io/format.c: Likewise.
	* io/intrinsics.c: Likewise.
	* io/list_read.c: Likewise.
	* io/open.c: Likewise.
	* io/transfer.c: Likewise.
	* io/unit.c: Likewise.
	* io/unix.c: Likewise.
	* io/write.c: Likewise.
	* m4/bessel.m4: Likewise.
	* m4/cshift1.m4: Likewise.
	* m4/eoshift1.m4: Likewise.
	* m4/eoshift3.m4: Likewise.
	* m4/iforeach.m4: Likewise.
	* m4/ifunction.m4: Likewise.
	* m4/ifunction_logical.m4: Likewise.
	* m4/in_pack.m4: Likewise.
	* m4/matmul.m4: Likewise.
	* m4/matmull.m4: Likewise.
	* m4/pack.m4: Likewise.
	* m4/reshape.m4: Likewise.
	* m4/shape.m4: Likewise.
	* m4/spread.m4: Likewise.
	* m4/transpose.m4: Likewise.
	* m4/unpack.m4: Likewise.
	* runtime/convert_char.c: Likewise.
	* runtime/environ.c: Likewise.
	* runtime/in_pack_generic.c: Likewise.
Steve Kargl - March 26, 2012, 3:37 p.m.
On Mon, Mar 26, 2012 at 06:17:08PM +0300, Janne Blomqvist wrote:
> 
> currently in libgfortran we have two malloc() wrappers, get_mem and
> internal_malloc_size, which abort the program if malloc fails.
> internal_malloc_size does
> 
> if (size == 0)
>     size = 1;
> 
> and then calls get_mem, which doesn't have such a zero-size check.
> This is, however, a bug in get_mem, as malloc(0) is allowed to return
> NULL, and in that case get_mem would incorrectly abort the program.
> Thus having both these functions is unnecessary. The attached patch
> combines these two functions into one.  As I couldn't decide between
> get_mem and internal_malloc_size and didn't particularly like either
> of the names, I named the combined function "xmalloc", as is common
> for such functions to be called.
> 
> When developing the patch, I noticed that the implementations of the
> intrinsics IALL, IANY, IPARITY, NORM2, and PARITY weren't being
> regenerated from the m4 sources. The reason, it turned out, was that
> the dependencies were specified incorrectly in Makefile.am. The patch
> also fixes this.
> 
> Regtested on x86_64-unknown-linux-gnu. While the patch is large, it's
> also mechanical, hence committed as obvious.
> 

The patch looks ok to me, but I do have two questions.

1) xmalloc is used in other parts of gcc.  Is there a
   possibility of confusing the libgfortran version 
   with the other(s)?  Perhaps, a unique name is in 
   order, gfc_xmalloc().

2) Unless I've misread the patch (which is always a
   possibility), it seems that you've removed 
   GFC_CLEAR_MEMORY, which used calloc to zero the
   allocated memory.  Is there a situation where 
   libgfortran needs/assumes the memory is zeroed
   upon allocation?
Janne Blomqvist - March 26, 2012, 4 p.m.
On Mon, Mar 26, 2012 at 18:37, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
> On Mon, Mar 26, 2012 at 06:17:08PM +0300, Janne Blomqvist wrote:
>>
>> currently in libgfortran we have two malloc() wrappers, get_mem and
>> internal_malloc_size, which abort the program if malloc fails.
>> internal_malloc_size does
>>
>> if (size == 0)
>>     size = 1;
>>
>> and then calls get_mem, which doesn't have such a zero-size check.
>> This is, however, a bug in get_mem, as malloc(0) is allowed to return
>> NULL, and in that case get_mem would incorrectly abort the program.
>> Thus having both these functions is unnecessary. The attached patch
>> combines these two functions into one.  As I couldn't decide between
>> get_mem and internal_malloc_size and didn't particularly like either
>> of the names, I named the combined function "xmalloc", as is common
>> for such functions to be called.
>>
>> When developing the patch, I noticed that the implementations of the
>> intrinsics IALL, IANY, IPARITY, NORM2, and PARITY weren't being
>> regenerated from the m4 sources. The reason, it turned out, was that
>> the dependencies were specified incorrectly in Makefile.am. The patch
>> also fixes this.
>>
>> Regtested on x86_64-unknown-linux-gnu. While the patch is large, it's
>> also mechanical, hence committed as obvious.
>>
>
> The patch looks ok to me, but I do have two questions.
>
> 1) xmalloc is used in other parts of gcc.  Is there a
>   possibility of confusing the libgfortran version
>   with the other(s)?  Perhaps, a unique name is in
>   order, gfc_xmalloc().

I though about that, and ultimately decided against it, as the symbol
name is mangled anyway (__gfortrani_xmalloc IIRC), and so shouldn't
cause any linking problems. Also, I don't think it's worth worrying
about similar named source identifiers in other subdirectories in the
GCC tree; it's easy enough to find the implementation that is used in
libgfortran with (git) grep.

> 2) Unless I've misread the patch (which is always a
>   possibility), it seems that you've removed
>   GFC_CLEAR_MEMORY, which used calloc to zero the
>   allocated memory.  Is there a situation where
>   libgfortran needs/assumes the memory is zeroed
>   upon allocation?

GFC_CLEAR_MEMORY was a macro for debugging purposes. Today, with tools
like valgrind available, replacing malloc with calloc is quite a
inefficient debugging tool. And as it's only a one-line change to
replace the malloc call with calloc inside xmalloc, if somebody wants
to do that it's no more effort than uncommenting the GFC_CLEAR_MEMORY
macro definition was before.

And yes, we nowadays have a corresponding xcalloc for those cases
where the caller requires zeroed memory; before xcalloc the caller
used memset to explicitly zero the memory, so GFC_CLEAR_MEMORY was
never needed from a correctness standpoint.

Patch

diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am
index 2ff29a8..abc23cd 100644
--- a/libgfortran/Makefile.am
+++ b/libgfortran/Makefile.am
@@ -887,13 +887,13 @@  $(i_any_c): m4/any.m4 $(I_M4_DEPS2)
 $(i_count_c): m4/count.m4 $(I_M4_DEPS2)
 	$(M4) -Dfile=$@ -I$(srcdir)/m4 count.m4 > $@
 
-$(i_iall_c): m4/iall.m4 $(I_M4_DEPS)
+$(i_iall_c): m4/iall.m4 $(I_M4_DEPS1)
 	$(M4) -Dfile=$@ -I$(srcdir)/m4 iall.m4 > $@
 
-$(i_iany_c): m4/iany.m4 $(I_M4_DEPS)
+$(i_iany_c): m4/iany.m4 $(I_M4_DEPS1)
 	$(M4) -Dfile=$@ -I$(srcdir)/m4 iany.m4 > $@
 
-$(i_iparity_c): m4/iparity.m4 $(I_M4_DEPS)
+$(i_iparity_c): m4/iparity.m4 $(I_M4_DEPS1)
 	$(M4) -Dfile=$@ -I$(srcdir)/m4 iparity.m4 > $@
 
 $(i_maxloc0_c): m4/maxloc0.m4 $(I_M4_DEPS0)
@@ -926,10 +926,10 @@  $(i_matmul_c): m4/matmul.m4 $(I_M4_DEPS)
 $(i_matmull_c): m4/matmull.m4 $(I_M4_DEPS)
 	$(M4) -Dfile=$@ -I$(srcdir)/m4 matmull.m4 > $@
 
-$(i_norm2_c): m4/norm2.m4 $(I_M4_DEPS)
+$(i_norm2_c): m4/norm2.m4 $(I_M4_DEPS1)
 	$(M4) -Dfile=$@ -I$(srcdir)/m4 norm2.m4 > $@
 
-$(i_parity_c): m4/parity.m4 $(I_M4_DEPS)
+$(i_parity_c): m4/parity.m4 $(I_M4_DEPS1)
 	$(M4) -Dfile=$@ -I$(srcdir)/m4 parity.m4 > $@
 
 $(i_transpose_c): m4/transpose.m4 $(I_M4_DEPS)
diff --git a/libgfortran/intrinsics/cshift0.c b/libgfortran/intrinsics/cshift0.c
index 5da73d4..b330537 100644
--- a/libgfortran/intrinsics/cshift0.c
+++ b/libgfortran/intrinsics/cshift0.c
@@ -79,8 +79,8 @@  cshift0 (gfc_array_char * ret, const gfc_array_char * array,
 	  GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
         }
 
-      /* internal_malloc_size allocates a single byte for zero size.  */
-      ret->base_addr = internal_malloc_size (size * arraysize);
+      /* xmalloc allocates a single byte for zero size.  */
+      ret->base_addr = xmalloc (size * arraysize);
     }
   else if (unlikely (compile_options.bounds_check))
     {
diff --git a/libgfortran/intrinsics/ctime.c b/libgfortran/intrinsics/ctime.c
index 05bf31f..d22851c 100644
--- a/libgfortran/intrinsics/ctime.c
+++ b/libgfortran/intrinsics/ctime.c
@@ -1,5 +1,5 @@ 
 /* Implementation of the CTIME and FDATE g77 intrinsics.
-   Copyright (C) 2005, 2007, 2009, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2007, 2009, 2011, 2012 Free Software Foundation, Inc.
    Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -64,7 +64,7 @@  void
 fdate (char ** date, gfc_charlen_type * date_len)
 {
   time_t now = time(NULL);
-  *date = get_mem (CSZ);
+  *date = xmalloc (CSZ);
   *date_len = strctime (*date, CSZ, &now);
 }
 
@@ -76,7 +76,7 @@  void
 fdate_sub (char * date, gfc_charlen_type date_len)
 {
   time_t now = time(NULL);
-  char *s = get_mem (date_len + 1);
+  char *s = xmalloc (date_len + 1);
   size_t n = strctime (s, date_len + 1, &now);
   fstrcpy (date, date_len, s, n);
   free (s);
@@ -91,7 +91,7 @@  void
 PREFIX(ctime) (char ** date, gfc_charlen_type * date_len, GFC_INTEGER_8 t)
 {
   time_t now = t;
-  *date = get_mem (CSZ);
+  *date = xmalloc (CSZ);
   *date_len = strctime (*date, CSZ, &now);
 }
 
@@ -103,7 +103,7 @@  void
 ctime_sub (GFC_INTEGER_8 * t, char * date, gfc_charlen_type date_len)
 {
   time_t now = *t;
-  char *s = get_mem (date_len + 1);
+  char *s = xmalloc (date_len + 1);
   size_t n = strctime (s, date_len + 1, &now);
   fstrcpy (date, date_len, s, n);
   free (s);
diff --git a/libgfortran/intrinsics/date_and_time.c b/libgfortran/intrinsics/date_and_time.c
index c785f84..5d8973e 100644
--- a/libgfortran/intrinsics/date_and_time.c
+++ b/libgfortran/intrinsics/date_and_time.c
@@ -270,7 +270,7 @@  secnds (GFC_REAL_4 *x)
   GFC_REAL_4 temp1, temp2;
 
   /* Make the INTEGER*4 array for passing to date_and_time.  */
-  gfc_array_i4 *avalues = internal_malloc_size (sizeof (gfc_array_i4));
+  gfc_array_i4 *avalues = xmalloc (sizeof (gfc_array_i4));
   avalues->base_addr = &values[0];
   GFC_DESCRIPTOR_DTYPE (avalues) = ((BT_REAL << GFC_DTYPE_TYPE_SHIFT)
 				        & GFC_DTYPE_TYPE_MASK) +
diff --git a/libgfortran/intrinsics/eoshift0.c b/libgfortran/intrinsics/eoshift0.c
index 8b7dd0a..f4cd424 100644
--- a/libgfortran/intrinsics/eoshift0.c
+++ b/libgfortran/intrinsics/eoshift0.c
@@ -86,8 +86,8 @@  eoshift0 (gfc_array_char * ret, const gfc_array_char * array,
 
         }
 
-      /* internal_malloc_size allocates a single byte for zero size.  */
-      ret->base_addr = internal_malloc_size (size * arraysize);
+      /* xmalloc allocates a single byte for zero size.  */
+      ret->base_addr = xmalloc (size * arraysize);
     }
   else if (unlikely (compile_options.bounds_check))
     {
diff --git a/libgfortran/intrinsics/eoshift2.c b/libgfortran/intrinsics/eoshift2.c
index cd2a827..d0d0bf1 100644
--- a/libgfortran/intrinsics/eoshift2.c
+++ b/libgfortran/intrinsics/eoshift2.c
@@ -91,8 +91,8 @@  eoshift2 (gfc_array_char *ret, const gfc_array_char *array,
 
 	  GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
 
-          /* internal_malloc_size allocates a single byte for zero size.  */
-	  ret->base_addr = internal_malloc_size (size * arraysize);
+          /* xmalloc allocates a single byte for zero size.  */
+	  ret->base_addr = xmalloc (size * arraysize);
 
         }
     }
diff --git a/libgfortran/intrinsics/getlog.c b/libgfortran/intrinsics/getlog.c
index f4fc0f6..92338c1 100644
--- a/libgfortran/intrinsics/getlog.c
+++ b/libgfortran/intrinsics/getlog.c
@@ -1,5 +1,5 @@ 
 /* Implementation of the GETLOG g77 intrinsic.
-   Copyright (C) 2005, 2007, 2009, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2007, 2009, 2011, 2012 Free Software Foundation, Inc.
    Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -86,7 +86,7 @@  PREFIX(getlog) (char * login, gfc_charlen_type login_len)
      targets; we do something simple in case the target doesn't
      support sysconf.  */
   static const size_t buflen = 1024;
-  buf = get_mem (buflen);
+  buf = xmalloc (buflen);
   err = getpwuid_r (geteuid (), &pwd, buf, buflen, &result);
   if (err != 0 || result == NULL)
     goto cleanup;
diff --git a/libgfortran/intrinsics/pack_generic.c b/libgfortran/intrinsics/pack_generic.c
index 77d600a..4df3f93 100644
--- a/libgfortran/intrinsics/pack_generic.c
+++ b/libgfortran/intrinsics/pack_generic.c
@@ -153,8 +153,8 @@  pack_internal (gfc_array_char *ret, const gfc_array_char *array,
 	  GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1);
 
 	  ret->offset = 0;
-	  /* internal_malloc_size allocates a single byte for zero size.  */
-	  ret->base_addr = internal_malloc_size (size * total);
+	  /* xmalloc allocates a single byte for zero size.  */
+	  ret->base_addr = xmalloc (size * total);
 
 	  if (total == 0)
 	    return;      /* In this case, nothing remains to be done.  */
@@ -520,7 +520,7 @@  pack_s_internal (gfc_array_char *ret, const gfc_array_char *array,
 
       ret->offset = 0;
 
-      ret->base_addr = internal_malloc_size (size * total);
+      ret->base_addr = xmalloc (size * total);
 
       if (total == 0)
 	return;
diff --git a/libgfortran/intrinsics/reshape_generic.c b/libgfortran/intrinsics/reshape_generic.c
index b16690a..ec8ea23 100644
--- a/libgfortran/intrinsics/reshape_generic.c
+++ b/libgfortran/intrinsics/reshape_generic.c
@@ -103,7 +103,7 @@  reshape_internal (parray *ret, parray *source, shape_type *shape,
       else
 	alloc_size = rs * size;
 
-      ret->base_addr = internal_malloc_size (alloc_size);
+      ret->base_addr = xmalloc (alloc_size);
 
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
diff --git a/libgfortran/intrinsics/spread_generic.c b/libgfortran/intrinsics/spread_generic.c
index 2a478f1..40450bd 100644
--- a/libgfortran/intrinsics/spread_generic.c
+++ b/libgfortran/intrinsics/spread_generic.c
@@ -1,5 +1,6 @@ 
 /* Generic implementation of the SPREAD intrinsic
-   Copyright 2002, 2005, 2006, 2007, 2009, 2010, 2012 Free Software Foundation, Inc.
+   Copyright 2002, 2005, 2006, 2007, 2009, 2010, 2012 
+   Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -100,7 +101,7 @@  spread_internal (gfc_array_char *ret, const gfc_array_char *source,
 	  GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride);
 	}
       ret->offset = 0;
-      ret->base_addr = internal_malloc_size (rs * size);
+      ret->base_addr = xmalloc (rs * size);
 
       if (rs <= 0)
 	return;
@@ -245,7 +246,7 @@  spread_internal_scalar (gfc_array_char *ret, const char *source,
 
   if (ret->base_addr == NULL)
     {
-      ret->base_addr = internal_malloc_size (ncopies * size);
+      ret->base_addr = xmalloc (ncopies * size);
       ret->offset = 0;
       GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
     }
diff --git a/libgfortran/intrinsics/string_intrinsics_inc.c b/libgfortran/intrinsics/string_intrinsics_inc.c
index 8335a38..b20483d 100644
--- a/libgfortran/intrinsics/string_intrinsics_inc.c
+++ b/libgfortran/intrinsics/string_intrinsics_inc.c
@@ -1,5 +1,5 @@ 
 /* String intrinsics helper functions.
-   Copyright 2002, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
+   Copyright 2002, 2005, 2007, 2008, 2009, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU Fortran runtime library (libgfortran).
 
@@ -167,7 +167,7 @@  string_trim (gfc_charlen_type *len, CHARTYPE **dest, gfc_charlen_type slen,
   else
     {
       /* Allocate space for result string.  */
-      *dest = internal_malloc_size (*len * sizeof (CHARTYPE));
+      *dest = xmalloc (*len * sizeof (CHARTYPE));
 
       /* Copy string if necessary.  */
       memcpy (*dest, src, *len * sizeof (CHARTYPE));
@@ -445,7 +445,7 @@  string_minmax (gfc_charlen_type *rlen, CHARTYPE **dest, int op, int nargs, ...)
     *dest = &zero_length_string;
   else
     {
-      CHARTYPE *tmp = internal_malloc_size (*rlen * sizeof (CHARTYPE));
+      CHARTYPE *tmp = xmalloc (*rlen * sizeof (CHARTYPE));
       memcpy (tmp, res, reslen * sizeof (CHARTYPE));
       MEMSET (&tmp[reslen], ' ', *rlen - reslen);
       *dest = tmp;
diff --git a/libgfortran/intrinsics/transpose_generic.c b/libgfortran/intrinsics/transpose_generic.c
index 03fbbef..b5bae41 100644
--- a/libgfortran/intrinsics/transpose_generic.c
+++ b/libgfortran/intrinsics/transpose_generic.c
@@ -60,7 +60,7 @@  transpose_internal (gfc_array_char *ret, gfc_array_char *source)
       GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
 			GFC_DESCRIPTOR_EXTENT(source, 1));
 
-      ret->base_addr = internal_malloc_size (size * size0 ((array_t*)ret));
+      ret->base_addr = xmalloc (size * size0 ((array_t*)ret));
       ret->offset = 0;
     }
   else if (unlikely (compile_options.bounds_check))
diff --git a/libgfortran/intrinsics/unpack_generic.c b/libgfortran/intrinsics/unpack_generic.c
index 123f5e1..7f92cf5 100644
--- a/libgfortran/intrinsics/unpack_generic.c
+++ b/libgfortran/intrinsics/unpack_generic.c
@@ -126,7 +126,7 @@  unpack_internal (gfc_array_char *ret, const gfc_array_char *vector,
 	  rs *= extent[n];
 	}
       ret->offset = 0;
-      ret->base_addr = internal_malloc_size (rs * size);
+      ret->base_addr = xmalloc (rs * size);
     }
   else
     {
diff --git a/libgfortran/io/fbuf.c b/libgfortran/io/fbuf.c
index 353e5ae..6dacc54 100644
--- a/libgfortran/io/fbuf.c
+++ b/libgfortran/io/fbuf.c
@@ -1,4 +1,4 @@ 
-/* Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+/* Copyright (C) 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
    Contributed by Janne Blomqvist
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -39,8 +39,8 @@  fbuf_init (gfc_unit * u, int len)
   if (len == 0)
     len = 512;			/* Default size.  */
 
-  u->fbuf = get_mem (sizeof (struct fbuf));
-  u->fbuf->buf = get_mem (len);
+  u->fbuf = xmalloc (sizeof (struct fbuf));
+  u->fbuf->buf = xmalloc (len);
   u->fbuf->len = len;
   u->fbuf->act = u->fbuf->pos = 0;
 }
diff --git a/libgfortran/io/format.c b/libgfortran/io/format.c
index 1711a75..afa5f34 100644
--- a/libgfortran/io/format.c
+++ b/libgfortran/io/format.c
@@ -1,4 +1,5 @@ 
-/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 
+   2012
    Free Software Foundation, Inc.
    Contributed by Andy Vaught
    F2003 I/O support contributed by Jerry DeLisle
@@ -150,7 +151,7 @@  save_parsed_format (st_parameter_dt *dtp)
   u->format_hash_table[hash].hashed_fmt = NULL;
 
   free (u->format_hash_table[hash].key);
-  u->format_hash_table[hash].key = get_mem (dtp->format_len);
+  u->format_hash_table[hash].key = xmalloc (dtp->format_len);
   memcpy (u->format_hash_table[hash].key, dtp->format, dtp->format_len);
 
   u->format_hash_table[hash].key_len = dtp->format_len;
@@ -223,7 +224,7 @@  get_fnode (format_data *fmt, fnode **head, fnode **tail, format_token t)
 
   if (fmt->avail == &fmt->last->array[FARRAY_SIZE])
     {
-      fmt->last->next = get_mem (sizeof (fnode_array));
+      fmt->last->next = xmalloc (sizeof (fnode_array));
       fmt->last = fmt->last->next;
       fmt->last->next = NULL;
       fmt->avail = &fmt->last->array[0];
@@ -1225,7 +1226,7 @@  parse_format (st_parameter_dt *dtp)
 
   /* Not found so proceed as follows.  */
 
-  dtp->u.p.fmt = fmt = get_mem (sizeof (format_data));
+  dtp->u.p.fmt = fmt = xmalloc (sizeof (format_data));
   fmt->format_string = dtp->format;
   fmt->format_string_len = dtp->format_len;
 
diff --git a/libgfortran/io/intrinsics.c b/libgfortran/io/intrinsics.c
index 22150e7..576434a 100644
--- a/libgfortran/io/intrinsics.c
+++ b/libgfortran/io/intrinsics.c
@@ -1,6 +1,6 @@ 
 /* Implementation of the FGET, FGETC, FPUT, FPUTC, FLUSH 
    FTELL, TTYNAM and ISATTY intrinsics.
-   Copyright (C) 2005, 2007, 2009, 2010, 2011 Free Software
+   Copyright (C) 2005, 2007, 2009, 2010, 2011, 2012 Free Software
    Foundation, Inc.
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -380,7 +380,7 @@  ttynam (char ** name, gfc_charlen_type * name_len, int unit)
   u = find_unit (unit);
   if (u != NULL)
     {
-      *name = get_mem (TTY_NAME_MAX);
+      *name = xmalloc (TTY_NAME_MAX);
       int err = stream_ttyname (u->s, *name, TTY_NAME_MAX);
       if (err == 0)
 	{
diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index 91b345c..2024fcd 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -2282,7 +2282,7 @@  nml_touch_nodes (namelist_info * nl)
 {
   index_type len = strlen (nl->var_name) + 1;
   int dim;
-  char * ext_name = (char*)get_mem (len + 1);
+  char * ext_name = (char*)xmalloc (len + 1);
   memcpy (ext_name, nl->var_name, len-1);
   memcpy (ext_name + len - 1, "%", 2);
   for (nl = nl->next; nl; nl = nl->next)
@@ -2540,7 +2540,7 @@  nml_read_obj (st_parameter_dt *dtp, namelist_info * nl, index_type offset,
 
 	  case BT_DERIVED:
 	    obj_name_len = strlen (nl->var_name) + 1;
-	    obj_name = get_mem (obj_name_len+1);
+	    obj_name = xmalloc (obj_name_len+1);
 	    memcpy (obj_name, nl->var_name, obj_name_len-1);
 	    memcpy (obj_name + obj_name_len - 1, "%", 2);
 
diff --git a/libgfortran/io/open.c b/libgfortran/io/open.c
index 8f969ed..d086d2e 100644
--- a/libgfortran/io/open.c
+++ b/libgfortran/io/open.c
@@ -1,4 +1,4 @@ 
-/* Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
+/* Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Contributed by Andy Vaught
    F2003 I/O support contributed by Jerry DeLisle
@@ -538,7 +538,7 @@  new_unit (st_parameter_open *opp, gfc_unit *u, unit_flags * flags)
 
   /* Create the unit structure.  */
 
-  u->file = get_mem (opp->file_len);
+  u->file = xmalloc (opp->file_len);
   if (u->unit_number != opp->common.unit)
     internal_error (&opp->common, "Unit number changed");
   u->s = s;
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index f71e96f..6dda1df 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -3650,11 +3650,11 @@  st_set_nml_var (st_parameter_dt *dtp, void * var_addr, char * var_name,
   namelist_info *nml;
   size_t var_name_len = strlen (var_name);
 
-  nml = (namelist_info*) get_mem (sizeof (namelist_info));
+  nml = (namelist_info*) xmalloc (sizeof (namelist_info));
 
   nml->mem_pos = var_addr;
 
-  nml->var_name = (char*) get_mem (var_name_len + 1);
+  nml->var_name = (char*) xmalloc (var_name_len + 1);
   memcpy (nml->var_name, var_name, var_name_len);
   nml->var_name[var_name_len] = '\0';
 
@@ -3668,9 +3668,9 @@  st_set_nml_var (st_parameter_dt *dtp, void * var_addr, char * var_name,
   if (nml->var_rank > 0)
     {
       nml->dim = (descriptor_dimension*)
-		   get_mem (nml->var_rank * sizeof (descriptor_dimension));
+		   xmalloc (nml->var_rank * sizeof (descriptor_dimension));
       nml->ls = (array_loop_spec*)
-		  get_mem (nml->var_rank * sizeof (array_loop_spec));
+		  xmalloc (nml->var_rank * sizeof (array_loop_spec));
     }
   else
     {
diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c
index 5fe9eb2..d5029dc 100644
--- a/libgfortran/io/unit.c
+++ b/libgfortran/io/unit.c
@@ -409,7 +409,7 @@  get_internal_unit (st_parameter_dt *dtp)
     {
       iunit->rank = GFC_DESCRIPTOR_RANK (dtp->internal_unit_desc);
       iunit->ls = (array_loop_spec *)
-	get_mem (iunit->rank * sizeof (array_loop_spec));
+	xmalloc (iunit->rank * sizeof (array_loop_spec));
       dtp->internal_unit_len *=
 	init_loop_spec (dtp->internal_unit_desc, iunit->ls, &start_record);
 
@@ -542,7 +542,7 @@  init_units (void)
       u->endfile = NO_ENDFILE;
 
       u->file_len = strlen (stdin_name);
-      u->file = get_mem (u->file_len);
+      u->file = xmalloc (u->file_len);
       memmove (u->file, stdin_name, u->file_len);
 
       fbuf_init (u, 0);
@@ -572,7 +572,7 @@  init_units (void)
       u->endfile = AT_ENDFILE;
     
       u->file_len = strlen (stdout_name);
-      u->file = get_mem (u->file_len);
+      u->file = xmalloc (u->file_len);
       memmove (u->file, stdout_name, u->file_len);
       
       fbuf_init (u, 0);
@@ -602,7 +602,7 @@  init_units (void)
       u->endfile = AT_ENDFILE;
 
       u->file_len = strlen (stderr_name);
-      u->file = get_mem (u->file_len);
+      u->file = xmalloc (u->file_len);
       memmove (u->file, stderr_name, u->file_len);
       
       fbuf_init (u, 256);  /* 256 bytes should be enough, probably not doing
@@ -759,7 +759,7 @@  filename_from_unit (int n)
   /* Get the filename.  */
   if (u != NULL)
     {
-      filename = (char *) get_mem (u->file_len + 1);
+      filename = (char *) xmalloc (u->file_len + 1);
       unpack_filename (filename, u->file, u->file_len);
       return filename;
     }
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index 31fa005..278decd 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -639,7 +639,7 @@  buf_init (unix_stream * s)
 {
   s->st.vptr = &buf_vtable;
 
-  s->buffer = get_mem (BUFFER_SIZE);
+  s->buffer = xmalloc (BUFFER_SIZE);
   return 0;
 }
 
@@ -1082,7 +1082,7 @@  tempfile (st_parameter_open *opp)
     slash = "";
 
   // Take care that the template is longer in the mktemp() branch.
-  template = get_mem (tempdirlen + 23);
+  template = xmalloc (tempdirlen + 23);
 
 #ifdef HAVE_MKSTEMP
   snprintf (template, tempdirlen + 23, "%s%sgfortrantmpXXXXXX", 
diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c
index 8be3a5a..838bc0d 100644
--- a/libgfortran/io/write.c
+++ b/libgfortran/io/write.c
@@ -1,4 +1,5 @@ 
-/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 
+   2012
    Free Software Foundation, Inc.
    Contributed by Andy Vaught
    Namelist output contributed by Paul Thomas
@@ -1864,7 +1865,7 @@  nml_write_obj (st_parameter_dt *dtp, namelist_info * obj, index_type offset,
 	      base_var_name_len = base ? strlen (base->var_name) : 0;
 	      ext_name_len = base_name_len + base_var_name_len 
 		+ strlen (obj->var_name) + obj->var_rank * NML_DIGITS + 1;
-	      ext_name = (char*)get_mem (ext_name_len);
+	      ext_name = (char*)xmalloc (ext_name_len);
 
 	      memcpy (ext_name, base_name, base_name_len);
 	      clen = strlen (obj->var_name + base_var_name_len);
@@ -1893,7 +1894,7 @@  nml_write_obj (st_parameter_dt *dtp, namelist_info * obj, index_type offset,
 	      /* Now obj_name.  */
 
 	      obj_name_len = strlen (obj->var_name) + 1;
-	      obj_name = get_mem (obj_name_len+1);
+	      obj_name = xmalloc (obj_name_len+1);
 	      memcpy (obj_name, obj->var_name, obj_name_len-1);
 	      memcpy (obj_name + obj_name_len-1, "%", 2);
 
diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
index 186bfbe..be5f133 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -753,11 +753,8 @@  internal_proto(set_fpu);
 
 /* memory.c */
 
-extern void *get_mem (size_t) __attribute__ ((malloc));
-internal_proto(get_mem);
-
-extern void *internal_malloc_size (size_t) __attribute__ ((malloc));
-internal_proto(internal_malloc_size);
+extern void *xmalloc (size_t) __attribute__ ((malloc));
+internal_proto(xmalloc);
 
 extern void *xcalloc (size_t, size_t) __attribute__ ((malloc));
 internal_proto(xcalloc);
diff --git a/libgfortran/m4/bessel.m4 b/libgfortran/m4/bessel.m4
index d9e7f89..d5c602d 100644
--- a/libgfortran/m4/bessel.m4
+++ b/libgfortran/m4/bessel.m4
@@ -56,7 +56,7 @@  bessel_jn_r'rtype_kind` ('rtype` * const restrict ret, int n1, int n2, 'rtype_na
     {
       size_t size = n2 < n1 ? 0 : n2-n1+1; 
       GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
-      ret->base_addr = internal_malloc_size (sizeof ('rtype_name`) * size);
+      ret->base_addr = xmalloc (sizeof ('rtype_name`) * size);
       ret->offset = 0;
     }
 
@@ -123,7 +123,7 @@  bessel_yn_r'rtype_kind` ('rtype` * const restrict ret, int n1, int n2,
     {
       size_t size = n2 < n1 ? 0 : n2-n1+1; 
       GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
-      ret->base_addr = internal_malloc_size (sizeof ('rtype_name`) * size);
+      ret->base_addr = xmalloc (sizeof ('rtype_name`) * size);
       ret->offset = 0;
     }
 
diff --git a/libgfortran/m4/cshift1.m4 b/libgfortran/m4/cshift1.m4
index 88fce1a..40d34fb 100644
--- a/libgfortran/m4/cshift1.m4
+++ b/libgfortran/m4/cshift1.m4
@@ -81,7 +81,7 @@  cshift1 (gfc_array_char * const restrict ret,
     {
       int i;
 
-      ret->base_addr = internal_malloc_size (size * arraysize);
+      ret->base_addr = xmalloc (size * arraysize);
       ret->offset = 0;
       ret->dtype = array->dtype;
       for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
diff --git a/libgfortran/m4/eoshift1.m4 b/libgfortran/m4/eoshift1.m4
index 691edd1..637bdae 100644
--- a/libgfortran/m4/eoshift1.m4
+++ b/libgfortran/m4/eoshift1.m4
@@ -106,8 +106,8 @@  eoshift1 (gfc_array_char * const restrict ret,
 	  GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
 
         }
-      /* internal_malloc_size allocates a single byte for zero size.  */
-      ret->base_addr = internal_malloc_size (size * arraysize);
+      /* xmalloc allocates a single byte for zero size.  */
+      ret->base_addr = xmalloc (size * arraysize);
 
     }
   else if (unlikely (compile_options.bounds_check))
diff --git a/libgfortran/m4/eoshift3.m4 b/libgfortran/m4/eoshift3.m4
index b5c8bb4..e1d74fe 100644
--- a/libgfortran/m4/eoshift3.m4
+++ b/libgfortran/m4/eoshift3.m4
@@ -90,7 +90,7 @@  eoshift3 (gfc_array_char * const restrict ret,
     {
       int i;
 
-      ret->base_addr = internal_malloc_size (size * arraysize);
+      ret->base_addr = xmalloc (size * arraysize);
       ret->offset = 0;
       ret->dtype = array->dtype;
       for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
@@ -108,8 +108,8 @@  eoshift3 (gfc_array_char * const restrict ret,
 	  GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
 
         }
-      /* internal_malloc_size allocates a single byte for zero size.  */
-      ret->base_addr = internal_malloc_size (size * arraysize);
+      /* xmalloc allocates a single byte for zero size.  */
+      ret->base_addr = xmalloc (size * arraysize);
 
     }
   else if (unlikely (compile_options.bounds_check))
diff --git a/libgfortran/m4/iforeach.m4 b/libgfortran/m4/iforeach.m4
index 86d4350..a875a2a 100644
--- a/libgfortran/m4/iforeach.m4
+++ b/libgfortran/m4/iforeach.m4
@@ -30,7 +30,7 @@  name`'rtype_qual`_'atype_code (rtype * const restrict retarray,
       GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
       retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
       retarray->offset = 0;
-      retarray->base_addr = internal_malloc_size (sizeof (rtype_name) * rank);
+      retarray->base_addr = xmalloc (sizeof (rtype_name) * rank);
     }
   else
     {
@@ -133,7 +133,7 @@  void
       GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
       retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
       retarray->offset = 0;
-      retarray->base_addr = internal_malloc_size (sizeof (rtype_name) * rank);
+      retarray->base_addr = xmalloc (sizeof (rtype_name) * rank);
     }
   else
     {
@@ -264,7 +264,7 @@  void
       GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
       retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
       retarray->offset = 0;
-      retarray->base_addr = internal_malloc_size (sizeof (rtype_name) * rank);
+      retarray->base_addr = xmalloc (sizeof (rtype_name) * rank);
     }
   else if (unlikely (compile_options.bounds_check))
     {
diff --git a/libgfortran/m4/ifunction.m4 b/libgfortran/m4/ifunction.m4
index 1cd3073..613fbf5 100644
--- a/libgfortran/m4/ifunction.m4
+++ b/libgfortran/m4/ifunction.m4
@@ -88,7 +88,7 @@  name`'rtype_qual`_'atype_code (rtype * const restrict retarray,
       alloc_size = sizeof (rtype_name) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
     		   * extent[rank-1];
 
-      retarray->base_addr = internal_malloc_size (alloc_size);
+      retarray->base_addr = xmalloc (alloc_size);
       if (alloc_size == 0)
 	{
 	  /* Make sure we have a zero-sized array.  */
@@ -273,7 +273,7 @@  void
 	  return;
 	}
       else
-	retarray->base_addr = internal_malloc_size (alloc_size);
+	retarray->base_addr = xmalloc (alloc_size);
 
     }
   else
@@ -432,7 +432,7 @@  void
 	  return;
 	}
       else
-	retarray->base_addr = internal_malloc_size (alloc_size);
+	retarray->base_addr = xmalloc (alloc_size);
     }
   else
     {
diff --git a/libgfortran/m4/ifunction_logical.m4 b/libgfortran/m4/ifunction_logical.m4
index b36e8e0..13dd7a9 100644
--- a/libgfortran/m4/ifunction_logical.m4
+++ b/libgfortran/m4/ifunction_logical.m4
@@ -99,7 +99,7 @@  name`'rtype_qual`_'atype_code (rtype * const restrict retarray,
 	  return;
 	}
       else
-	retarray->base_addr = internal_malloc_size (alloc_size);
+	retarray->base_addr = xmalloc (alloc_size);
     }
   else
     {
diff --git a/libgfortran/m4/in_pack.m4 b/libgfortran/m4/in_pack.m4
index 7cee37b..aad3dab 100644
--- a/libgfortran/m4/in_pack.m4
+++ b/libgfortran/m4/in_pack.m4
@@ -79,7 +79,7 @@  internal_pack_'rtype_ccode` ('rtype` * source)
     return source->base_addr;
 
   /* Allocate storage for the destination.  */
-  destptr = ('rtype_name` *)internal_malloc_size (ssize * sizeof ('rtype_name`));
+  destptr = ('rtype_name` *)xmalloc (ssize * sizeof ('rtype_name`));
   dest = destptr;
   src = source->base_addr;
   stride0 = stride[0];
diff --git a/libgfortran/m4/matmul.m4 b/libgfortran/m4/matmul.m4
index 6a7ce5c..6a58cd9 100644
--- a/libgfortran/m4/matmul.m4
+++ b/libgfortran/m4/matmul.m4
@@ -125,7 +125,7 @@  matmul_'rtype_code` ('rtype` * const restrict retarray,
         }
 
       retarray->base_addr
-	= internal_malloc_size (sizeof ('rtype_name`) * size0 ((array_t *) retarray));
+	= xmalloc (sizeof ('rtype_name`) * size0 ((array_t *) retarray));
       retarray->offset = 0;
     }
     else if (unlikely (compile_options.bounds_check))
diff --git a/libgfortran/m4/matmull.m4 b/libgfortran/m4/matmull.m4
index 87245ae..73c5088 100644
--- a/libgfortran/m4/matmull.m4
+++ b/libgfortran/m4/matmull.m4
@@ -89,7 +89,7 @@  matmul_'rtype_code` ('rtype` * const restrict retarray,
         }
           
       retarray->base_addr
-	= internal_malloc_size (sizeof ('rtype_name`) * size0 ((array_t *) retarray));
+	= xmalloc (sizeof ('rtype_name`) * size0 ((array_t *) retarray));
       retarray->offset = 0;
     }
     else if (unlikely (compile_options.bounds_check))
diff --git a/libgfortran/m4/pack.m4 b/libgfortran/m4/pack.m4
index e88e84e..bc7f3b9 100644
--- a/libgfortran/m4/pack.m4
+++ b/libgfortran/m4/pack.m4
@@ -169,8 +169,8 @@  pack_'rtype_code` ('rtype` *ret, const 'rtype` *array,
 
 	  ret->offset = 0;
 
-	  /* internal_malloc_size allocates a single byte for zero size.  */
-	  ret->base_addr = internal_malloc_size (sizeof ('rtype_name`) * total);
+	  /* xmalloc allocates a single byte for zero size.  */
+	  ret->base_addr = xmalloc (sizeof ('rtype_name`) * total);
 
 	  if (total == 0)
 	    return;
diff --git a/libgfortran/m4/parity.m4 b/libgfortran/m4/parity.m4
index 037e96d..6ff0ad2 100644
--- a/libgfortran/m4/parity.m4
+++ b/libgfortran/m4/parity.m4
@@ -1,5 +1,5 @@ 
-`/* Implementation of the NORM2 intrinsic
-   Copyright 2010 Free Software Foundation, Inc.
+`/* Implementation of the PARITY intrinsic
+   Copyright 2010, 2012 Free Software Foundation, Inc.
    Contributed by Tobias Burnus  <burnus@net-b.de>
 
 This file is part of the GNU Fortran runtime library (libgfortran).
diff --git a/libgfortran/m4/reshape.m4 b/libgfortran/m4/reshape.m4
index 26ea7e0..b589e53 100644
--- a/libgfortran/m4/reshape.m4
+++ b/libgfortran/m4/reshape.m4
@@ -119,7 +119,7 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
       else
         alloc_size = rs * sizeof ('rtype_name`);
 
-      ret->base_addr = internal_malloc_size (alloc_size);
+      ret->base_addr = xmalloc (alloc_size);
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
 
diff --git a/libgfortran/m4/shape.m4 b/libgfortran/m4/shape.m4
index 66445ce..8b63ade 100644
--- a/libgfortran/m4/shape.m4
+++ b/libgfortran/m4/shape.m4
@@ -50,7 +50,7 @@  shape_'rtype_kind` ('rtype` * const restrict ret,
     {
       GFC_DIMENSION_SET(ret->dim[0], 0, rank - 1, 1);
       ret->offset = 0;
-      ret->base_addr = internal_malloc_size (sizeof ('rtype_name`) * rank);
+      ret->base_addr = xmalloc (sizeof ('rtype_name`) * rank);
     }
 
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
diff --git a/libgfortran/m4/spread.m4 b/libgfortran/m4/spread.m4
index 52c0022..d9779bd 100644
--- a/libgfortran/m4/spread.m4
+++ b/libgfortran/m4/spread.m4
@@ -102,8 +102,8 @@  spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
 	}
       ret->offset = 0;
 
-      /* internal_malloc_size allocates a single byte for zero size.  */
-      ret->base_addr = internal_malloc_size (rs * sizeof('rtype_name`));
+      /* xmalloc allocates a single byte for zero size.  */
+      ret->base_addr = xmalloc (rs * sizeof('rtype_name`));
       if (rs <= 0)
         return;
     }
@@ -245,7 +245,7 @@  spread_scalar_'rtype_code` ('rtype` *ret, const 'rtype_name` *source,
 
   if (ret->base_addr == NULL)
     {
-      ret->base_addr = internal_malloc_size (ncopies * sizeof ('rtype_name`));
+      ret->base_addr = xmalloc (ncopies * sizeof ('rtype_name`));
       ret->offset = 0;
       GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
     }
diff --git a/libgfortran/m4/transpose.m4 b/libgfortran/m4/transpose.m4
index a60ca6d..f5581f1 100644
--- a/libgfortran/m4/transpose.m4
+++ b/libgfortran/m4/transpose.m4
@@ -61,7 +61,7 @@  transpose_'rtype_code` ('rtype` * const restrict ret,
       GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
 			GFC_DESCRIPTOR_EXTENT(source, 1));
 
-      ret->base_addr = internal_malloc_size (sizeof ('rtype_name`) * size0 ((array_t *) ret));
+      ret->base_addr = xmalloc (sizeof ('rtype_name`) * size0 ((array_t *) ret));
       ret->offset = 0;
     } else if (unlikely (compile_options.bounds_check))
     {
diff --git a/libgfortran/m4/unpack.m4 b/libgfortran/m4/unpack.m4
index 0395715..7278857 100644
--- a/libgfortran/m4/unpack.m4
+++ b/libgfortran/m4/unpack.m4
@@ -100,7 +100,7 @@  unpack0_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
 	  rs *= extent[n];
 	}
       ret->offset = 0;
-      ret->base_addr = internal_malloc_size (rs * sizeof ('rtype_name`));
+      ret->base_addr = xmalloc (rs * sizeof ('rtype_name`));
     }
   else
     {
@@ -245,7 +245,7 @@  unpack1_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
 	  rs *= extent[n];
 	}
       ret->offset = 0;
-      ret->base_addr = internal_malloc_size (rs * sizeof ('rtype_name`));
+      ret->base_addr = xmalloc (rs * sizeof ('rtype_name`));
     }
   else
     {
diff --git a/libgfortran/runtime/convert_char.c b/libgfortran/runtime/convert_char.c
index 540c2bf..aa43d97 100644
--- a/libgfortran/runtime/convert_char.c
+++ b/libgfortran/runtime/convert_char.c
@@ -1,5 +1,5 @@ 
 /* Runtime conversion of strings from one character kind to another.
-   Copyright 2008, 2009 Free Software Foundation, Inc.
+   Copyright 2008, 2009, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU Fortran runtime library (libgfortran).
 
@@ -44,7 +44,7 @@  convert_char1_to_char4 (gfc_char4_t **dst, gfc_charlen_type len,
   gfc_charlen_type i, l;
 
   l = len > 0 ? len : 0;
-  *dst = get_mem ((l + 1) * sizeof (gfc_char4_t));
+  *dst = xmalloc ((l + 1) * sizeof (gfc_char4_t));
 
   for (i = 0; i < l; i++)
     (*dst)[i] = src[i];
@@ -60,7 +60,7 @@  convert_char4_to_char1 (unsigned char **dst, gfc_charlen_type len,
   gfc_charlen_type i, l;
 
   l = len > 0 ? len : 0;
-  *dst = get_mem ((l + 1) * sizeof (unsigned char));
+  *dst = xmalloc ((l + 1) * sizeof (unsigned char));
 
   for (i = 0; i < l; i++)
     (*dst)[i] = src[i];
diff --git a/libgfortran/runtime/environ.c b/libgfortran/runtime/environ.c
index 6bd8886..7782cee 100644
--- a/libgfortran/runtime/environ.c
+++ b/libgfortran/runtime/environ.c
@@ -1,7 +1,8 @@ 
-/* Copyright (C) 2002, 2003, 2005, 2007, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2005, 2007, 2009, 2012 
+   Free Software Foundation, Inc.
    Contributed by Andy Vaught
 
-This file is part of the GNU Fortran 95 runtime library (libgfortran).
+This file is part of the GNU Fortran runtime library (libgfortran).
 
 Libgfortran is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -807,7 +808,7 @@  void init_unformatted (variable * v)
     }
   else
     {
-      elist = get_mem (unit_count * sizeof (exception_t));
+      elist = xmalloc (unit_count * sizeof (exception_t));
       do_count = 0;
       p = val;
       do_parse ();
diff --git a/libgfortran/runtime/in_pack_generic.c b/libgfortran/runtime/in_pack_generic.c
index 7ebebca..5360f26 100644
--- a/libgfortran/runtime/in_pack_generic.c
+++ b/libgfortran/runtime/in_pack_generic.c
@@ -178,7 +178,7 @@  internal_pack (gfc_array_char * source)
     return source->base_addr;
 
    /* Allocate storage for the destination.  */
-  destptr = internal_malloc_size (ssize * size);
+  destptr = xmalloc (ssize * size);
   dest = (char *)destptr;
   src = source->base_addr;
   stride0 = stride[0] * size;
diff --git a/libgfortran/runtime/memory.c b/libgfortran/runtime/memory.c
index 044a115..8fa71d3 100644
--- a/libgfortran/runtime/memory.c
+++ b/libgfortran/runtime/memory.c
@@ -27,22 +27,17 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "libgfortran.h"
 #include <stdlib.h>
 
-/* If GFC_CLEAR_MEMORY is defined, the memory allocation routines will
-   return memory that is guaranteed to be set to zero.  This can have
-   a severe efficiency penalty, so it should never be set if good
-   performance is desired, but it can help when you're debugging code.  */
-/* #define GFC_CLEAR_MEMORY */
 
 void *
-get_mem (size_t n)
+xmalloc (size_t n)
 {
   void *p;
 
-#ifdef GFC_CLEAR_MEMORY
-  p = (void *) calloc (1, n);
-#else
-  p = (void *) malloc (n);
-#endif
+  if (n == 0)
+    n = 1;
+
+  p = malloc (n);
+
   if (p == NULL)
     os_error ("Memory allocation failed");
 
@@ -50,18 +45,6 @@  get_mem (size_t n)
 }
 
 
-/* Allocate memory for internal (compiler generated) use.  */
-
-void *
-internal_malloc_size (size_t size)
-{
-  if (unlikely (size == 0))
-    size = 1;
-
-  return get_mem (size);
-}
-
-
 /* calloc wrapper that aborts on error.  */
 
 void *