This is an archive of the discontinued LLVM Phabricator instance.

Add support for ignored bitfield conditional codegen.
ClosedPublic

Authored by erichkeane on Apr 13 2022, 6:54 AM.

Details

Summary

Currently we emit an error in just about every case of conditionals
with a 'non simple' branch if treated as an LValue. This patch adds
support for the special case where this is an 'ignored' lvalue, which
permits the side effects from happening.

It also splits up the emit for conditional LValue in a way that should
be usable to handle simple assignment expressions in similar situations.

Diff Detail

Event Timeline

erichkeane created this revision.Apr 13 2022, 6:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2022, 6:54 AM
erichkeane requested review of this revision.Apr 13 2022, 6:54 AM

This is basically what I expected; the general approach seems fine.

clang/lib/CodeGen/CGExpr.cpp
200

Is there some reason we need to special-case bitfields here?

4635

If we're calling this from EmitIgnoredConditionalOperator, should we be calling back into EmitIgnoredExpr, instead of using EmitLValueOrThrowExpression? Consider, e.g. cond ? s1.field1 = val1 : cond2 ? s1.field2 = val2 : s1.field3 = val3;.

erichkeane added inline comments.Apr 13 2022, 9:17 AM
clang/lib/CodeGen/CGExpr.cpp
200

I don't think it ends up being a problem to support the 'simple' case (or perhaps even the matrix/vector cases?), but I was not really motivated to write test cases for all of those cases (nor write error handling, since that is already so well handled).

4635

First, this is the 'generic function' that is called by the normal ConditionalOperator handling as well, so there would be a bit of branching/etc perhaps to make this call 'ignored'.

That said, I'm not really sure what the implications of that would be. I don't really see harm in the example you gave though, so I can put a patch together to do that.

Added support for chained-conditional operators as requested. All of the variants I could come up with that I was afraid would be breaking ended up having an rvalue conversion (which makes it 'work').

This revision is now accepted and ready to land.Apr 13 2022, 10:32 AM
This revision was landed with ongoing or failed builds.Apr 13 2022, 10:34 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2022, 10:34 AM