[Bug diagnostics/126780] New: false-positive -Wanalyzer-out-of-bounds with __attribute__((access))

"marian.buschsieweke at posteo dot net via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126780

            Bug ID: 126780
           Summary: false-positive -Wanalyzer-out-of-bounds with
                    __attribute__((access))
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: diagnostics
          Assignee: dmalcolm at redhat dot com
          Reporter: marian.buschsieweke at posteo dot net
  Target Milestone: ---

Minimum reproducer:

        __attribute__((access(write_only, 1, 2)))
        void foo(void *ptr, unsigned size);

        void bar(void)
        {
            static char buf[1024];
            foo(buf + 4, sizeof(buf) - 4);
        }

When compiled with `-Os -fanalyzer`, an out of-bounds read is detected. The
static analyzer is completly ignoring the second argument here and assuming an
1024 byte write no matter what. The issue is present in both GCC 16.1 and 16.2.

See https://godbolt.org/z/7dE1roqn1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.