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

            Bug ID: 81065
           Summary: UBSAN: false positive as a result of distribution
                    involving different types
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: babokin at gmail dot com
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at 
gcc dot gnu.org
  Target Milestone: ---

Similar to #80932, but note that x is unsigned char, it's essential.

> cat f.cpp
unsigned char x = 154;
int foo() {
  // 8575 * (254408 - 9057) = 8575 * 245351 = 2103884825 = 0x7d66bc19
  return 8575 * (1652 * x - 9057);
}

int main() {
  foo();
  return 0;
}

> g++ -fsanitize=undefined -O0 f.cpp -o out

> ./out
f.cpp:4:33: runtime error: signed integer overflow: 154 * 14165900 cannot be
represented in type 'int'
f.cpp:4:33: runtime error: signed integer overflow: -2113418696 + -77663775
cannot be represented in type 'int'

Reply via email to