This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [PATCH] Emulate clang atomic built-ins on gcc > 4.7
ClosedPublic

Authored by ajwong on Aug 6 2014, 3:21 PM.

Details

Summary

gcc 4.7 and above has atomic built-ins which slightly different APIs from those provided by clang. Add proxy functions that wrap the gcc built-ins to produce a symbol that is API equivalent to the clang built-ins. This allows libc++'s atomic library to be used with gcc-4.7 and newer.

Constexpr code for __to_gcc_order() by "Hans Boehm" <hboehm@google.com>

Test now passing using gcc-4.7:
atomics/atomics.fences/atomic_signal_fence.pass.cpp
atomics/atomics.fences/atomic_thread_fence.pass.cpp
atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp
atomics/atomics.flag/atomic_flag_clear.pass.cpp
atomics/atomics.flag/atomic_flag_test_and_set_explicit.pass.cpp
atomics/atomics.flag/atomic_flag_test_and_set.pass.cpp
atomics/atomics.flag/clear.pass.cpp
atomics/atomics.flag/default.pass.cpp
atomics/atomics.flag/init.pass.cpp
atomics/atomics.flag/test_and_set.pass.cpp
atomics/atomics.lockfree/lockfree.pass.cpp
atomics/atomics.order/kill_dependency.pass.cpp
atomics/atomics.order/memory_order.pass.cpp
atomics/atomics.types.generic/cstdint_typedefs.pass.cpp
atomics/atomics.types.generic/integral_typedefs.pass.cpp
atomics/atomics.types.generic/trivially_copyable.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong_explicit.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak_explicit.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange_explicit.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and_explicit.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or_explicit.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor_explicit.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_init.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_load_explicit.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_load.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_store_explicit.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_store.pass.cpp
atomics/atomics.types.operations/atomics.types.operations.req/atomic_var_init.pass.cpp
atomics/version.pass.cpp

No regressions on other tests.

Diff Detail

Event Timeline

ajwong updated this revision to Diff 12255.Aug 6 2014, 3:21 PM
ajwong retitled this revision from to Emulate clang atomic built-ins on gcc > 4.7.
ajwong updated this object.
ajwong edited the test plan for this revision. (Show Details)
ajwong updated this revision to Diff 12258.Aug 6 2014, 3:45 PM
ajwong retitled this revision from Emulate clang atomic built-ins on gcc > 4.7 to [libcxx] [PATCH] Emulate clang atomic built-ins on gcc > 4.7.
ajwong updated this object.
ajwong added a reviewer: mclow.lists.
ajwong added a project: deleted.
ajwong added a subscriber: Unknown Object (MLST).
ajwong added a comment.Aug 6 2014, 3:59 PM

This change is ready for review. With it, most of the libc++ atomic tests pass on gcc > 4.7.

Please take a look!

danalbert accepted this revision.Aug 7 2014, 5:10 PM
danalbert added a reviewer: danalbert.
danalbert added a subscriber: danalbert.

LGTM. Will run the tests myself when I get the chance and then commit assuming everything goes well (and mclow doesn't have any objections).

This revision is now accepted and ready to land.Aug 7 2014, 5:10 PM
danalbert closed this revision.Aug 9 2014, 5:02 PM

Sorry for the delay. Submitted as r215305.

I've also tested this on Android.