[PATCH] correct handling of offsets in PHI expressions [PR103215]

Martin Sebor msebor@redhat.com
Mon Nov 22 23:54:19 GMT 2021

In an effort to avoid false positives while still detecting
certain out-of-bounds accesses the warning code that handles
PHI nodes chooses the operand with the most space remaining
as the one representative of the PHI.  That's not right when
the offsets into the operands are unequal, because it overly
constrains the range of offsets that can be substracted from
the pointer.

The attached change corrects the logic here to not only use
the size of the largest operand but also to extend the range
of offsets into it to reflect all operand.  Unfortunately,
as a result of the more conservative offset computation,
the fix leads to a fair number of false negatives.  I tried
to avoid those but couldn't come up with a clean solution
that didn't require design changes, so I defer those to GCC

The diff is relative to the "cleanup" patch submitted below:

Tested on x86_64-linux and by building Glibc and confirming
no new warnings.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-103215.diff
Type: text/x-patch
Size: 35704 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20211122/2228e37d/attachment-0001.bin>

More information about the Gcc-patches mailing list