> On Fri, Nov 01, 2024 at 11:39:13AM +0100, Jan Hubicka wrote:
> > The testcase does:
> > /* { dg-additional-options "-O3 -fsanitize=undefined" } */
> > 
> > void memory_exhausted();
> > void memcheck(void *ptr) {
> >   if (ptr) /* { dg-warning "leak" } */
> >     memory_exhausted();
> > }
> > 
> > int emalloc(int size) { memcheck(__builtin_malloc(size)); } /* { dg-message 
> > "allocated here" } */
> > int main() { int max_envvar_len = emalloc(max_envvar_len + 1); } /* { 
> > dg-message "use of uninitialized value 'max_envvar_len'" } */
> 
> The PR was an ICE fix, so I think it is ok to say add -fno-allocation-dce
> or somehow arrange in the source for the call not to be optimized away,
> as long as it still ICEs in r12-3094 and succeeds with r12-3095 after
> that change.
> 
> Generally regarding warnings, if the compiler optimizes away the allocation
> altogether, there will be no leak from it, so I think the optimization is
> fine.

I also thin it is OK to optimize here.  
Currently there is -fno option to disable optimization of malloc/free
pairs. -fno-allocation-dce handles only new/delete.  I am not sure why
it was added for C++ only. So in the other testcase compensation I
simply used -fno-tree-dce which would work here too.

Perhaps I can add -fno-malloc-dce to handle the C library variants
(malloc/calloc/strdup/strndup).  I also think I can quite easilly handle
realloc by combining free and malloc logic together.

Honza
> 
>       Jakub
> 

Reply via email to