On Fri, 1 Nov 2024, Jan Hubicka wrote: > > 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.
I think we should move -fno-allocation-dce to the middle-end and disable malloc/free pair elision when set (not sure about stack-save/restore pairs) instead. Btw, did you check what happens when doing new/delete without nothrow() and either external or internal EH? I think optimizing is OK in all cases, but I guess EH edges will prevent the optimization? Richard. > 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 > > > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)