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

            Bug ID: 108625
           Summary: forwprop introduces new UB
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristerw at gcc dot gnu.org
  Target Milestone: ---

Consider the function

  unsigned char foo(int x)
  {
    int t = -x;
    unsigned char t1 = t;
    unsigned char t2 = t;
    return t1 + t2;
  }

This does not invoke undefined behavior when called as foo(0x40000001),
but forwprop1 optimizes this to

  unsigned char foo (int x)
  {
    int t;
    unsigned char _5;
    int _7;

    <bb 2> :
    t_2 = -x_1(D);
    _7 = t_2 - x_1(D);
    _5 = (unsigned char) _7;
    return _5;
  }

where _7 has signed overflow for x = 0x40000001.

Reply via email to