This is an archive of the discontinued LLVM Phabricator instance.

[clang][CodeGen] Handle throw expression in conditional operator constant folding
ClosedPublic

Authored by tambre on Apr 5 2020, 7:57 AM.

Details

Summary

We're smart and do constant folding when emitting conditional operators.
Thus we emit the live value as a lvalue. This doesn't work if the live value is a throw expression.
Handle this by emitting the throw and returning the dead value as the lvalue.

Fixes PR28184.

Diff Detail

Event Timeline

tambre created this revision.Apr 5 2020, 7:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2020, 7:57 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tambre edited the summary of this revision. (Show Details)Apr 5 2020, 7:59 AM
tambre updated this revision to Diff 255175.Apr 5 2020, 10:02 AM

Fix formatting

rsmith added inline comments.Apr 5 2020, 10:50 PM
clang/lib/CodeGen/CGExpr.cpp
4337

The IR we emit for the dead operand is unreachable; it's a bit wasteful to generate it here and (hopefully!) leave it to the optimizer to remove it again. Perhaps we could produce an undef lvalue instead? See CodeGenFunction::EmitUnsupportedLValue for an example of how to build such a value.

clang/test/CodeGenCXX/throw-expressions.cpp
84–87

Please add some CHECKs in here to make sure we actually emit a call to __cxa_throw.

tambre updated this revision to Diff 255275.Apr 6 2020, 3:46 AM
tambre marked 4 inline comments as done.

Emit undef lvalue, add throw CHECK to test

tambre edited the summary of this revision. (Show Details)Apr 6 2020, 3:46 AM
tambre added inline comments.
clang/lib/CodeGen/CGExpr.cpp
4337

Done.

clang/test/CodeGenCXX/throw-expressions.cpp
84–87

Done.

rsmith accepted this revision.Apr 6 2020, 2:11 PM

Looks good (with the comment suitably tweaked). Thanks!

clang/lib/CodeGen/CGExpr.cpp
4334

Comment doesn't match the code any more.

This revision is now accepted and ready to land.Apr 6 2020, 2:11 PM
tambre updated this revision to Diff 255607.Apr 7 2020, 12:56 AM
tambre marked an inline comment as done.

Update comment

tambre marked an inline comment as done.Apr 7 2020, 12:56 AM

Updated the comment.

Please commit this for me, as I lack commit privileges.

This revision was automatically updated to reflect the committed changes.