https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104215

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
To "use" means to evaluate.  The strict C semantics are that the realloc()
argument becomes indeterminate after the function has returned non-null,
whether or not the returned pointer is the same as the argument.  The argument
is only safe to use after realloc() has returned null.  In other words,
strictly conforming programs must treat every successful call to realloc() as
if it freed the original object.

The warning is based on these strict semantics.  It handles the realloc failure
case, and it tries to accommodate the use case of detecting whether realloc()
has moved the block to a different address by only warning on equality
expressions involving the original argument at level 3.

The warning cannot very well avoid triggering on this case if we want it to
continue to work as designed (I of course do).  The solution I'd like to see is
the forwprop pass checking for the uses of the pointers in the propagated
condition in deallocation calls and suppressing the warning for the propagated
condition statement by calling suppress_warning().  This could be made reliable
by having forwprop and the warning share the same code (a common function to do
the same analysis to determine whether to suppress the warning in forwprop or
whether to trigger in gimple-ssa-warn-access).

Reply via email to