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

            Bug ID: 101830
           Summary: Incorrect error messages beginning with r12-2591
                    (backward jump threader)
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wschmidt at gcc dot gnu.org
  Target Milestone: ---

I've been adding some code to the rs6000 back end that hasn't yet been part of
the build.  As I got ready to commit the patch to start building the code, I
found that it has recently stopped building due to bogus error messages.  These
started with r12-2591 (new backward jump threader) but is presumably also
related to the new pass for array bounds checking.

$ $GCC_INSTALL/bin/g++ $GCC_SRC/gcc/config/rs6000/rs6000-gen-builtins.c -c -O2
-Wall -Werror
/home/wschmidt/newgcc/gcc/config/rs6000/rs6000-gen-builtins.c: In function 'int
match_bracketed_pair(typeinfo*, char, char, restriction)':
/home/wschmidt/newgcc/gcc/config/rs6000/rs6000-gen-builtins.c:824:22: error:
array subscript 1024 is above array bounds of 'char [1024]'
[-Werror=array-bounds]
  824 |       if (linebuf[pos] != ',')
      |           ~~~~~~~~~~~^
/home/wschmidt/newgcc/gcc/config/rs6000/rs6000-gen-builtins.c:186:13: note:
while referencing 'linebuf'
  186 | static char linebuf[LINELEN];
      |             ^~~~~~~
/home/wschmidt/newgcc/gcc/config/rs6000/rs6000-gen-builtins.c:843:22: error:
array subscript 1024 is above array bounds of 'char [1024]'
[-Werror=array-bounds]
  843 |       if (linebuf[pos] != close)
      |           ~~~~~~~~~~~^
/home/wschmidt/newgcc/gcc/config/rs6000/rs6000-gen-builtins.c:186:13: note:
while referencing 'linebuf'
  186 | static char linebuf[LINELEN];
      |             ^~~~~~~

...and many more, all referencing uses of linebuf[pos].

There are several problems with these messages:

(1) linebuf and pos are global variables, and the compiler cannot tell whether
or not there are problems with array bounds accesses here. Indeed, pos is only
incremented by a function called "safe_inc_pos" that ensures we *don't* ever
access beyond the end of linebuf.

(2) The error message is far too certain of itself!  It says that we have
definitely addressed out of bounds when that is certainly not known to be true.

(3) Some uses of linebuf[pos] are flagged, and others are not, often within the
same function.

You can reproduce this as above with the code that is upstream in trunk.

This is holding up committing some approved patches, so I appreciate anything
you can do to sort this out.

Reply via email to