[Bug c/98965] New: assingment to a struct with an atomic member not atomic

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Feb 3 23:42:29 GMT 2021


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;

}


More information about the Gcc-bugs mailing list