public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/102453] New: buffer overflow by atomic built-ins not diagnosed
@ 2021-09-22 15:17 msebor at gcc dot gnu.org
  2021-09-22 15:17 ` [Bug middle-end/102453] " msebor at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-09-22 15:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102453
           Summary: buffer overflow by atomic built-ins not diagnosed
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The buffer overflow by the straight assignment in f() below is diagnosed as
expected but the equivalent overflow by the atomic built-in in g() is not even
though both should be.  The problem is simply that due to an oversight, the
access warnings lack support for atomic built-ins.

$ cat y.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout y.c
extern _Atomic char x;

void f (void)
{
  long *p = (long*)&x;

  *p = 0;
}

void g (void)
{
  long *p = (long*)&x;

  __atomic_store_n (p, 0, 0);
}
y.c: In function ‘f’:
y.c:7:3: warning: array subscript ‘long int[0]’ is partly outside array bounds
of ‘_Atomic char[1]’ [-Warray-bounds]
    7 |   *p = 0;
      |   ^~
y.c:1:21: note: object ‘x’ of size 1
    1 | extern _Atomic char x;
      |                     ^

;; Function f (f, funcdef_no=0, decl_uid=1979, cgraph_uid=1, symbol_order=0)

void f ()
{
  <bb 2> [local count: 1073741824]:
  MEM[(long int *)&x] = 0;
  return;

}



;; Function g (g, funcdef_no=1, decl_uid=1983, cgraph_uid=2, symbol_order=1)

void g ()
{
  <bb 2> [local count: 1073741824]:
  __atomic_store_8 (&x, 0, 0); [tail call]
  return;

}

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

end of thread, other threads:[~2021-10-26 23:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 15:17 [Bug middle-end/102453] New: buffer overflow by atomic built-ins not diagnosed msebor at gcc dot gnu.org
2021-09-22 15:17 ` [Bug middle-end/102453] " msebor at gcc dot gnu.org
2021-10-11 21:49 ` msebor at gcc dot gnu.org
2021-10-26 22:54 ` cvs-commit at gcc dot gnu.org
2021-10-26 23:02 ` msebor 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).