public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/101494] New: -Wmaybe-uninitialized false alarm with memrchr of size 0
@ 2021-07-18  2:08 eggert at cs dot ucla.edu
  2021-07-18  9:18 ` [Bug tree-optimization/101494] " bruno at clisp dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: eggert at cs dot ucla.edu @ 2021-07-18  2:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101494
           Summary: -Wmaybe-uninitialized false alarm with memrchr of size
                    0
           Product: gcc
           Version: 11.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

I ran into this problem when compiling Gnulib tests on gcc (GCC) 11.1.1
20210531 (Red Hat 11.1.1-3) on x86-64. Here is a stripped down program
illustrating the bug:

void *malloc (unsigned long)
  __attribute__((__malloc__)) __attribute__((__alloc_size__ (1)));

void *memrchr (const void *, int, unsigned long)
  __attribute__((__access__ (__read_only__, 1, 3)));

int
main (void)
{
  char *input = malloc (1);
  if (!input)
    return 1;
  *input = 0;
  return !!memrchr (input, 'a', 0);
}


The following command:

gcc -Wmaybe-uninitialized -O2 -S w.i

outputs:
w.i: In function 'main':
w.i:14:12: warning: 'input' may be used uninitialized [-Wmaybe-uninitialized]
   14 |   return !!memrchr (input, 'a', 0);
      |            ^~~~~~~~~~~~~~~~~~~~~~~
w.i:4:7: note: in a call to 'memrchr' declared with attribute 'access
(read_onl\
y, 1, 3)' here
    4 | void *memrchr (const void *, int, unsigned long)
      |       ^~~~~~~

This warning is bogus, as 'input' is initialized; and even if "input = 0;" were
removed the call to memrchr would still be valid as the size argument is 0.

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

end of thread, other threads:[~2023-05-29 10:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-18  2:08 [Bug tree-optimization/101494] New: -Wmaybe-uninitialized false alarm with memrchr of size 0 eggert at cs dot ucla.edu
2021-07-18  9:18 ` [Bug tree-optimization/101494] " bruno at clisp dot org
2021-07-21 18:05 ` msebor at gcc dot gnu.org
2021-07-21 18:09 ` [Bug tree-optimization/101494] [11 Regression] " msebor at gcc dot gnu.org
2021-07-22 23:06 ` msebor at gcc dot gnu.org
2021-07-28  7:07 ` rguenth at gcc dot gnu.org
2021-07-28 22:27 ` cvs-commit at gcc dot gnu.org
2021-07-28 22:27 ` msebor at gcc dot gnu.org
2022-04-21  7:49 ` rguenth at gcc dot gnu.org
2023-05-29 10:05 ` jakub 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).