[Bug c/106119] Bogus use-after-free warning triggered by optimizer
tom.cosgrove at arm dot com
gcc-bugzilla@gcc.gnu.org
Wed Jun 29 13:53:39 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106119
--- Comment #2 from Tom Cosgrove <tom.cosgrove at arm dot com> ---
Further addendum:
If you use a `void *` to save the value of the pointer, you don't get the
warning!
See https://gcc.godbolt.org/z/fof8a747z
i.e. this code does not generate the warning:
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
void calloc_self_test( __attribute__ ((unused)) int verbose )
{
void *buffer1 = calloc( 1, 1 );
void *old_buffer1 = buffer1;
free( buffer1 );
buffer1 = calloc( 1, 1 );
int same = ( old_buffer1 == buffer1 );
if( verbose )
printf( " CALLOC(1 again): passed (%s address)\n",
same ? "same" : "different" );
free( buffer1 );
}
More information about the Gcc-bugs
mailing list