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

            Bug ID: 65027
           Summary: failure to emit diagnostic when optimizing using
                    undefined behaviour
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rearnsha at gcc dot gnu.org
            Target: x86_64, arm

The following code fragment, when compiled at -O3 is quite reasonably optimized
to return 33 (since any other return value relies on first encountering
undefined behaviour).  However, the -Waggressive-loop-optimizations diagnostic
option fails to cause a warning about this to be reported.

int x[5];

int foo()
{
  int i;
  for (i = 0; i < 30; i++)
    if (x[i] == 0)
      return 33;
  return 1;
}

This code should trigger do_warn_aggressive_loop_optimizations to emit a
diagnostic.

It probably doesn't at present because the loop is removed entirely.

Reply via email to