public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/100680] New: false positive warning for certain __builtin_memcmp() argument
@ 2021-05-19 13:33 jbeulich at suse dot com
  2021-05-19 13:38 ` [Bug c/100680] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jbeulich at suse dot com @ 2021-05-19 13:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100680
           Summary: false positive warning for certain __builtin_memcmp()
                    argument
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jbeulich at suse dot com
  Target Milestone: ---

In this example

struct s {
        char a[8];
        int i;
        long l;
};

extern char ea[8];
static char sa[8] = { 1, 2, 3, 4 };

int test(void) {
        const struct s*ps = (const struct s *)0x12345678L;

        if(__builtin_memcmp(ps->a, ps->a, 8))
                return 0;

        if(__builtin_memcmp(ps->a, ea, 8))
                return 0;

        if(__builtin_memcmp(ps->a, sa, 8))
                return 0;

        if(__builtin_memcmp(ps->a, "abcdABCD", 8))
                return 0;

        return 1;
}

all except, oddly enough, the first invocation cause "'__builtin_memcmp'
specified bound of 8 exceeds source size of 0 [-Wstringop-overread]". Obviously
the above example is heavily simplified from actual uses in the Xen hypervisor
sources, but clearly in (at least) OS and alike low-level development it is not
uncommon for pointers to get derived from known integer constants.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-29  5:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 13:33 [Bug c/100680] New: false positive warning for certain __builtin_memcmp() argument jbeulich at suse dot com
2021-05-19 13:38 ` [Bug c/100680] " rguenth at gcc dot gnu.org
2021-05-19 15:07 ` [Bug middle-end/100680] " msebor at gcc dot gnu.org
2021-05-19 16:06 ` jbeulich at suse dot com
2022-03-18 18:02 ` cvs-commit at gcc dot gnu.org
2022-03-29  5:54 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).