PATCH RFC: Warn about pointer wraparound with -Wstrict-overflow

Richard Guenther richard.guenther@gmail.com
Tue Apr 8 09:31:00 GMT 2008


On Mon, Apr 7, 2008 at 9:35 PM, Ian Lance Taylor <iant@google.com> wrote:
> I'm testing this patch as a response to
>     http://www.kb.cert.org/vuls/id/162289
>
>  This patch treats undefined pointer wraparound optimizations as an
>  instance of undefined signed overflow optimizations (they are of
>  course different, but they seem similar to users not educated in
>  standardese).  You will get a warning with -Wstrict-overflow, and you
>  can disable the optimization with -fno-strict-overflow.
>
>  My plan is to backport this patch to the gcc 4.2 and 4.3 branches.

Please leave at least the 4.2 branch alone.

>  Any comments or concerns?

+/* True if pointer types have undefined overflow.  */
+#define POINTER_TYPE_OVERFLOW_UNDEFINED \
+  (!flag_wrapv && !flag_trapv && flag_strict_overflow)

don't add flag_trapv here, it doesn't make sense.

In general I don't think we should do this.  The tests in this stupid
CERT are bogus and I have never seen such.  Also this test
will cause many false positives I belive, almost any loop with a
pointer induction variable should be affected.

But of course my complaints about -Wstrict-overflow were unheard
in the past as well ;)

Richard.



More information about the Gcc-patches mailing list