avoid useless if-before-free tests

Jim Meyering jim@meyering.net
Tue Mar 8 10:45:00 GMT 2011


Joseph S. Myers wrote:

Thank you for the prompt feedback.

> On Sat, 5 Mar 2011, Jim Meyering wrote:
>
>> diff --git a/gcc/config/i386/gmm_malloc.h b/gcc/config/i386/gmm_malloc.h
>> index 7a7e840..8993fc7 100644
>> --- a/gcc/config/i386/gmm_malloc.h
>> +++ b/gcc/config/i386/gmm_malloc.h
>> @@ -67,8 +67,7 @@ _mm_malloc (size_t size, size_t align)
>>  static __inline__ void
>>  _mm_free (void * aligned_ptr)
>>  {
>> -  if (aligned_ptr)
>> -    free (((void **) aligned_ptr) [-1]);
>> +  free (((void **) aligned_ptr) [-1]);
>>  }
>
> This one looks suspicious; it's not if (p) free (p); but if (p) free
> (something-derived-from-p);.

Good catch.  That is an invalid transformation.  I've reverted it.
It is also the first one like that that I've seen.
Calling free (((void **) 0) [-1]); would not go down well.

>> diff --git a/libjava/classpath/native/fdlibm/dtoa.c
>> b/libjava/classpath/native/fdlibm/dtoa.c
>> index 458e629..92aa793 100644
>
> http://gcc.gnu.org/codingconventions.html says Classpath changes should go
> via Classpath upstream, not directly into GCC.  I don't know if that's
> still accurate.

Thanks for the tip and for Cc'ing java-patches.
I've omitted the classpath/ changes.

>> diff --git a/zlib/contrib/minizip/unzip.c b/zlib/contrib/minizip/unzip.c
>> index 9ad4766..644ef1b 100644
>
> We definitely don't want to make local changes to zlib for this sort of
> issue, though importing a new upstream version of zlib (making sure the
> local configure code still works) should be fine for 4.7.

I've also omitted zlib/ and intl/ changes.

Is libgo/ in the same boat?  Only one of its files is affected, but
I found no ChangeLog for libgo and no libgo-related ChangeLog entries.
I could always add an entry at the top,

   * libgo/runtime/go-select.c (__go_select): ...



More information about the Gcc-patches mailing list