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

            Bug ID: 109107
           Summary: UBsan since GCC-8 misses an integer-overflow
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
                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: ---

For the following code, UBsan since GCC-8 at -O1 and above misses the integer
overflow. GCC-7 can detect it at all opt levels.

Clang can detect it at all opt levels.

Compiler explorer: https://godbolt.org/z/Pez4jd5aj

% cat a.c
int a = -2147468918, c;
const long b = 676540;
int main() { 
    c = 1 + a - (short)b; 
    return c;
}
%
% gcc-tk -O1 -fsanitize=undefined a.c &&./a.out
%
% gcc-7 -O1 -fsanitize=undefined a.c &&./a.out
/a.c:4:15: runtime error: signed integer overflow: -2147468918 - 21179 cannot
be represented in type 'int'
%

Reply via email to