http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59785
Bug ID: 59785 Summary: atomic_store should load source operand atomically? Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ma.jiang at zte dot com.cn gcc provide a atomic_store interface as below. void __atomic_store (type *ptr, type *val, int memmodel) In manual, There is only a simple description ---"This is the generic version of an atomic store. It stores the value of *val into *ptr." But it seemed that this interface could not do what the description said when *val is a global memory which might be messed up by other threads. unsigned long long int ta=123; unsigned long long int tb=321; int test() { __atomic_store(&tb, &ta, __ATOMIC_RELAXED); return 0; } On ARM,the codes above give out a assembly instruction sequence as below. movw r3, #:lower16:ta movt r3, #:upper16:ta ldrd r0, [r3] movw r3, #:lower16:tb movt r3, #:upper16:tb .L3: ldrexd r4, r5, [r3] strexd r2, r0, r1, [r3] cmp r2, #0 bne .L3 the source operand ta was not fetched atomically, so we might get a totally wrong num from tb when ta were modified by other threads. I guess the atomic_store interface only provide a function as--"fetch val non-atomically ,and then store it into ptr atomically." This is exactlly what the gimple tree shows. test () { long long unsigned int ta.0; int D.4127; ta.0 = ta; __atomic_store_8 (&tb, ta.0, 0); D.4127 = 0; return D.4127; } I think it would be better to give a more detailed desctription in the manual. Or make a atomical load in the atomic_store.