VRP miscompiles the following testcase at -O2:

#include <stdlib.h>

void test(int x)
{
        if (x < -3)
                abort();
        if (x > 5)
                abort();
        if (abs(x) != 1)
                abort();
}

int main()
{
        test(1);
        test(-1);
        return 0;
}


The t27.vrp dump shows the problem:

...
x_1: VARYING
D.1823_2: [3, 5]  EQUIVALENCES: { } (0 elements)
x_3: [-3, 5]  EQUIVALENCES: { x_1 x_4 } (2 elements)
x_4: [-3, +INF]  EQUIVALENCES: { x_1 } (1 elements)

Folding predicate D.1823_2 != 1 to 1
...

It concludes that since -3 <= x <= 5, then 3 <= abs(x) <= 5. This is wrong, and
leads to it compiling test() into an unconditional abort.

-- 
           Summary: VRP propagates abs incorrectly
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rmorganl at u dot washington dot edu
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-cygwin
  GCC host triplet: i686-pc-cygwin
GCC target triplet: i686-pc-cygwin


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23126

Reply via email to