This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Fix the atomic expr rebuilding order.
ClosedPublic

Authored by hliao on Sep 23 2019, 10:12 AM.

Details

Summary
  • Rearrange the atomic expr order to the API order when rebuilding atomic expr during template instantiation.

Diff Detail

Repository
rL LLVM

Event Timeline

hliao created this revision.Sep 23 2019, 10:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 23 2019, 10:12 AM

The current BuildAtomicExpr expects the arguments to be in the API order instead of the AST order. If RebuildAtomicExpr uses the same BuildAtomicExpr, it needs to ensure the order of arguments are in API order; otherwise, arguments (especially the one with memory order) will be misplaced.

Yikes, good catch!

Would we be better off instead to just modify how the other switch loads the value? Presumably something like, "if (NeedsRearrangeArgs) SubExprs.append(Args.begin(), Args.end()); else /*the switch*/.

clang/lib/Sema/TreeTransform.h
3319 ↗(On Diff #221363)

When passing a bool, use the comment syntax /*paramname=*/ to make it clear whats happening.

Yikes, good catch!

Would we be better off instead to just modify how the other switch loads the value? Presumably something like, "if (NeedsRearrangeArgs) SubExprs.append(Args.begin(), Args.end()); else /*the switch*/.

Loop from L4762 will check "value" arguments assuming the API order as well. That's why arguments are arranged so that the value checking logic also check the correct arguments.

hliao updated this revision to Diff 221365.Sep 23 2019, 10:33 AM

Add parameter name for that default argument.

hliao marked an inline comment as done.Sep 23 2019, 10:33 AM

It kinda stinks that we have to do this at such a late step. I'd have much preferred doing this as a part of the rebuild, but it appears that the 'form' takes quite a bit to calculate. Also, I'd likely have preferred that the initial reordering happened in codegen instead of this early, though perhaps thats too large of a change to do here.

I think then we're stuck with this reordering step.

That said, I'm not a fan at all of doing this parameter as a bool, particularly one with an ambiguous name. Can you introduce an enum like "enum class AtomicArgumentOrder { API, AST}" that makes it more clear?

Additionally, ReArgs is a confusing name, how about APIOrderedArgs?

Also, can you add a test for GNUCmpXchg in both situations (inside a template, and outside)? It is the most complicated, and would best reflect the issue.

Seems your test changes have disappeared as well? Otherwise, 1 comment then I'm ok with this.

clang/lib/Sema/TreeTransform.h
3319 ↗(On Diff #221369)

The comment is no longer necessary, since the enum describes the purpose.

hliao updated this revision to Diff 221374.Sep 23 2019, 11:31 AM

add test case for compare_exchange.

hliao marked an inline comment as done.Sep 23 2019, 11:33 AM
erichkeane accepted this revision.Sep 23 2019, 11:34 AM
This revision is now accepted and ready to land.Sep 23 2019, 11:34 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 23 2019, 11:51 AM