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

            Bug ID: 68971
           Summary: -Woverflow false alarm in code unreachable after
                    __builtin_mul_overflow
           Product: gcc
           Version: 5.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at gnu dot org
  Target Milestone: ---

Compile the following code with 'gcc -O2 -S u.c' (x86-64, GCC 5.3.1 20151207
(Red Hat 5.3.1-2)):

  int
  main (void)
  {
    int result;
    return (__builtin_mul_overflow (0x7fffffff, 0x7fffffff, &result)
            ? 2
            : result == 0x7fffffff * 0x7fffffff);
  }

GCC complains:

  u.c: In function ‘main’:
  u.c:7:29: warning: integer overflow in expression [-Woverflow]
        : result == 0x7fffffff * 0x7fffffff);
                             ^

But line 7 is unreachable, and GCC determined this (as can be seen in the
assembly-language output: 'main' simply returns 2 unconditionally). GCC should
not warn about integer overflows in unreachable code.

This bug appears to be independent of Bug#4210, as the problem occurs in both
if statements and if expressions.

This bug is causing problems with gnulib; see:

http://lists.gnu.org/archive/html/bug-gnulib/2015-12/msg00011.html

I guess we'll work around it in the meantime by compiling the program with
-Wno-overflow, but GCC should get fixed.

Reply via email to