This is an archive of the discontinued LLVM Phabricator instance.

Correct atomic libcall support for __atomic_*_fetch builtins.
ClosedPublic

Authored by jyknight on Nov 5 2015, 9:24 AM.

Details

Summary

In r244063, I had caused these builtins to call the same-named library
functions, __atomic_*_fetch_SIZE. However, this was incorrect: while
those functions are in fact supported by GCC's libatomic, they're not
documented by the spec (and gcc doesn't ever call them).

Instead, you're /supposed/ to call the __atomic_fetch_* builtins and
then redo the operation inline to return the final value.

Diff Detail

Event Timeline

jyknight updated this revision to Diff 39375.Nov 5 2015, 9:24 AM
jyknight retitled this revision from to Correct atomic libcall support for __atomic_*_fetch builtins..
jyknight updated this object.
jyknight added a reviewer: rsmith.

Unfortunate that they have this crazy behavior.

lib/CodeGen/CGAtomic.cpp
901

I think we should use [[clang::fallthrough]] instead. It annotates as well as the comment, aids the static analyzer, and should be ignored by compilers that don't support it.

985

Can you add an explanatory message in the assert? (Yes, thats had to come up with since its obvious if you are familiar with this path).

998

Am I mistaken, but, we don't need this unless we have an operation to perform? Cant we sink this into the PostOp condition?

jyknight updated this revision to Diff 39644.Nov 7 2015, 3:55 PM
jyknight marked 2 inline comments as done.

Respond to comments.

lib/CodeGen/CGAtomic.cpp
901

I don't know why, but it appears that this would be the first use of that feature in clang/llvm. Everywhere else uses a comment, so I'd not want to be the first here.

compnerd accepted this revision.Nov 10 2015, 9:49 PM
compnerd added a reviewer: compnerd.
compnerd added inline comments.
lib/CodeGen/CGAtomic.cpp
901

:-(. Very well.

This revision is now accepted and ready to land.Nov 10 2015, 9:49 PM
This revision was automatically updated to reflect the committed changes.