public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/98965] New: assingment to a struct with an atomic member not atomic
@ 2021-02-03 23:42 msebor at gcc dot gnu.org
  2021-02-03 23:45 ` [Bug c/98965] " msebor at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-02-03 23:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98965
           Summary: assingment to a struct with an atomic member not
                    atomic
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

When a struct with an atomic member is assigned to, the assignment is treated
the same as one to a struct with all ordinary (non-atomic) members.  For
example, in the test case below, GCC emits an atomic assignment for the one in
f() but a series of orinary assignments in g().  Either both assignments should
be atomic, or the second one should trigger a diagnostic.

$ cat t.c && gcc -O2 -S -Wall -Wextra -Wpedantic
-fdump-tree-optimized=/dev/stdout t.c
struct A { char a[33]; };
typedef _Atomic struct A AA;

AA a;

void f (const struct A *p)
{
  a = *p;   // atomic
}

struct B { AA a; } b;

void g (const struct B *p)
{
  b = *p;   // non-atomic
}


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

void f (const struct A * p)
{
  struct A D.1949;

  <bb 2> [local count: 1073741824]:
  D.1949 = *p_2(D);
  __atomic_store (33, &a, &D.1949, 5);
  return;

}



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

void g (const struct B * p)
{
  <bb 2> [local count: 1073741824]:
  b = *p_2(D);
  return;

}

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

end of thread, other threads:[~2021-02-05  0:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 23:42 [Bug c/98965] New: assingment to a struct with an atomic member not atomic msebor at gcc dot gnu.org
2021-02-03 23:45 ` [Bug c/98965] " msebor at gcc dot gnu.org
2021-02-04  8:16 ` rguenth at gcc dot gnu.org
2021-02-04 16:44 ` [Bug c/98965] assignment " msebor at gcc dot gnu.org
2021-02-04 20:57 ` joseph at codesourcery dot com
2021-02-05  0:43 ` 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).