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

            Bug ID: 61520
           Summary: False warning: array subscript is below array bounds
                    (-Warray-bounds -O -ftree-vrp -funroll-loops)
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: svojtovich at gmail dot com

gcc emits false warning for the following code:

gcc -Warray-bounds -O -ftree-vrp -funroll-loops -c dec.c -o dec.o
or gcc -Warray-bounds -O3 -c dec.c -o dec.o

static const int powers10[2 + 1]= { 1, 10, 100 };

int remove_leading_zeroes(int decimals, int var)
{
  decimals%= 2;
  while (var < powers10[decimals--]) /* no-op */;
  return decimals;
}

This is simplified code, original code is available here:
http://bazaar.launchpad.net/~maria-captains/maria/10.0/view/head:/strings/decimal.c#L251

Note that original code ensures (within the same function) that array subscript
won't underrun array bounds.

4.8.2 seem to be also affected, look for compile results for decimal.c:
https://buildbot.askmonty.org/buildbot/builders/kvm-deb-trusty-amd64/builds/261/steps/compile/logs/stdio

Reply via email to