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

            Bug ID: 70507
           Summary: integer overflow builtins not constant expressions
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The integer overflow built-ins like __builtin_mul_overflow are not usable in
constant expressions even when their arguments themselves are constants such
that the computations do not overflow.  This prevents the builtins from being
used by GCC itself to instrument VLAs defined in constexpr functions to detect
overflow in the VLA bounds (see bug 69517 for background).

For additional problem reports caused by not treating the overflow built-ins as
constant expressions see bug 68120 and bug 68971.

$ cat z.cpp && /home/msebor/build/gcc-69517/gcc/xg++
-B/home/msebor/build/gcc-69517/gcc -S -Wall -Wextra -Wpedantic
-fdump-tree-optimized=/dev/stdout z.cpp
constexpr int mul (int x, int y)
{
    int z = 0;
    return __builtin_mul_overflow (x, y, &z) ? 0 : z;
}

constexpr int z1 = 1234 * 5678;        // okay
constexpr int z2 = mul (1234, 5678);   // error

z.cpp:8:24:   in constexpr expansion of ‘mul(1234, 5678)’
z.cpp:4:35: error: call to internal function
     return __builtin_mul_overflow (x, y, &z) ? 0 : z;
            ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~

Reply via email to