https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109123
--- Comment #6 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Manuel López-Ibáñez from comment #5)
> Is this code motion valid? Is there any point in the middle-end that checks
> the validity of the pointer beyond a free/realloc?
>
> If there is a point where such check happens, perhaps it would be a good
> place to apply no_warning attribute to the pointer.
Answering to myself: It seems the dispute is over the meaning of "use".
According to the middle-end and for the purposes of realloc/free, "use" means
dereference, while for the warning "use" is any read of the value.
By only warning for dereferences, the warning may miss some obvious cases like:
tmp = realloc(v->_begin, sizeof(double) * n);
v->_end = v->_begin + old_size;
v->_begin = tmp;
However, given that the assumption of the middle-end has worked for decades,
and it will be not possible to fix it, warning only for dereferences (or moving
warning for value-uses to a level not enabled by -Wall) would seem more
user-friendly.