Avoid calls to realloc for nvptx

Jakub Jelinek jakub@redhat.com
Wed Oct 22 08:40:00 GMT 2014


On Wed, Oct 22, 2014 at 10:32:26AM +0200, Tobias Burnus wrote:
> b) (Re)allocation on assignment, i.e.
>   A = ...
> where A is allocatable. The compiler then allocates the left-hand side if
> unallocated or reallocates it if the array shape, dynamic type or a length
> type parameter on the right doesn't match the one on the left. (The latter
> can occur for strings where the RHS has a different length than the LHS;
> the dynamic type only applies to polymorphic variables and is not yet
> implemented.)
> 
> In particular as the compiler may not reallocate if the size has not changed,
> there should be an array size or character-length check, which isn't far from
> the REALLOC call. Thus, it would be implementable without too much effort.
> (The reason that the reallocate is forbidden by the standard if the size
> already fits is that pointers to "A" do not break due to the changed address
> when using malloc/free.)

But it is the frontend that can know this, not the middle-end.
Having to compute the old size and using some intrinsic unconditionally
on all targets just because the code might be offloaded (and lowering that
after IPA to realloc proper (throwing away the unneeded argument) unless it is
nvptx target) would pessimize all the targets for a benefit of one.
What about any C/C++ code that needs realloc too?

	Jakub



More information about the Gcc-patches mailing list