https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66192
Bug ID: 66192 Summary: C++ static initializer unnecessary __cxa_guard_acquire for TARGET_RELAXED_ORDERING Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dje at gcc dot gnu.org Target Milestone: --- // static_init.cc int* f(void) { static int* p = new int; return p; } $ g++ -O2 -S -fno-exceptions static_init.cc generates an unnecessary call to __cxa_guard_acquire on what should be the fast path for targets with TARGET_RELAXED_ORDERING defined. The guard should be an atomic variable accessed with the equivalent of __atomic_load(ACQUIRE) instead of a heavy-weight __cxa_guard_acquire() call invoking heavier-weight synchronization.