[Bug c/68971] -Woverflow false alarm in code unreachable after __builtin_mul_overflow

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Feb 16 00:04:00 GMT 2017


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

--- Comment #11 from Martin Sebor <msebor at gcc dot gnu.org> ---
Right.  Because the call to __builtin_mul_overflow in the test case is not a
constant expression, the -Woverflow warning detects the overflow in the
multiplication subexpression that is constant.  The __builtin_mul_overflow call
is evaluated into a constant but not until after the warning has detected the
overflow.

The patch for bug 68120 introduced other built-ins to determine overflow at
compile-time.  Using those the return statement in this test case would look
something like this:

    return __builtin_mul_overflow_p (0x7fffffff, 0x7fffffff, 0)
           ? 2 : (0x7fffffff * 0x7fffffff == 0x7fffffff * 0x7fffffff);

and compile with no warning.


More information about the Gcc-bugs mailing list