[PATCH] avoid -Wuse-after-free [BZ #26779]
Jeff Law
jeffreyalaw@gmail.com
Tue Jan 25 01:08:00 GMT 2022
On 1/24/2022 5:42 PM, Martin Sebor via Libc-alpha wrote:
> On 1/21/22 17:42, Paul Eggert wrote:
>> On 1/21/22 15:14, Martin Sebor wrote:
>>>>
>>>
>>> That does look cleaner although it wasn't entirely obvious to me
>>> from looking at the code that it's the same. Unfortunately, it
>>> doesn't help. GCC replaces the bool variable with the equality
>>> test of the two pointers, and the warning points that out.
>>
>> That's a GCC bug.
>>
>>> Pedantically speaking it's a bug in GCC that it does that but
>>> I doubt anyone would care to do anything about it.
>>
>> You might be surprised; they do fix bugs in this area. If I could
>> reproduce the bug I'd file a bug report, but my GCC doesn't complain
>> so I guess it's up to you....
>
> I opened a GCC bug for the record:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104215
> GCC 12 is now in its regression-fixing stage so to get it fixed we'd
> need to make it a regression. That's usually only done for bugs that
> trigger under conditions where they didn't before.
The problem is there's no way for the compiler to know that it can't
move the use of q past the realloc call -- there's nothing from a
dataflow standpoint which would prevent such movement.
In some ways the builtin_realloc call would need to say "I'm going to
clobber this argument" and it would have to do so before translating
into SSA form I think.
Jeff
More information about the Libc-alpha
mailing list