This is an archive of the discontinued LLVM Phabricator instance.

Do not use optimized atomic libcalls for misaligned atomics.
ClosedPublic

Authored by rsmith on Sep 7 2018, 2:28 PM.

Details

Summary

The optimized (__atomic_foo_<n>) libcalls assume that the atomic object
is properly aligned, so should never be called on an underaligned
object.

This addresses one of several problems identified in PR38846.

Diff Detail

Repository
rL LLVM

Event Timeline

rsmith created this revision.Sep 7 2018, 2:28 PM
efriedma added inline comments.
lib/CodeGen/CGAtomic.cpp
949 ↗(On Diff #164517)

Is there any particular reason to expect that the pointer operand to __atomic_load_n can't be misaligned? I mean, for most ABIs, integers are naturally aligned, but that isn't actually a hard rule.

rsmith added inline comments.Sep 7 2018, 4:18 PM
lib/CodeGen/CGAtomic.cpp
949 ↗(On Diff #164517)

__atomic_load_n is, by definition, guaranteed to never call an unoptimized atomic library function (see https://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary). [I think the purpose of the ..._n variants is to provide builtins that libatomic's unoptimized library functions can use and have a guarantee that they will not be recursively re-entered.]

efriedma accepted this revision.Sep 7 2018, 4:37 PM

LGTM

lib/CodeGen/CGAtomic.cpp
949 ↗(On Diff #164517)

Oh, okay, makes sense.

This revision is now accepted and ready to land.Sep 7 2018, 4:37 PM
This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.