-Warray-bounds false negative

Matt matt@use.net
Fri Nov 13 21:24:00 GMT 2009


On Fri, 13 Nov 2009, Andrew Pinski wrote:

> On Fri, Nov 13, 2009 at 1:09 PM, Matt <matt@use.net> wrote:
>> Hello,
>>
>> I recently came across a false negative in GCC's detection of array bounds
>> violation. At first, I thought the other tool (PC-Lint) was having false
>> positive, but it turns out to be correct. The false negative occurs in GCC
>> 4.3, 4.4.1, and latest trunk (4.5). I'm curious to understand how exactly
>> the detection breaks down, as I think it may affect if/how the loop in
>> question is optimized.
>
> Well in this case, all of the code is considered dead is removed
> before the warning will happen to be emitted.
> If I change it so that data is read from (instead of just written to),
> the trunk warns about this code:
> t.c:21:20: warning: array subscript is above array bounds
>
> I changed the last return to be:
>       return data[2];

d'oh! Next time I'll look at the objdump output first.

Thanks for the quick explanation!

--
tangled strands of DNA explain the way that I behave.
http://www.clock.org/~matt



More information about the Gcc mailing list