This is an archive of the discontinued LLVM Phabricator instance.

[clang][CodeGen] Consistently return nullptr Values for void builtins and scalar initalization
ClosedPublic

Authored by zero9178 on Oct 23 2022, 3:33 AM.

Details

Summary

A common post condition of the various visitor functions in CodeGen is that instructions, that do not return any values, simply return a nullptr Value as a sentinel. This has not been the case however for calls to some builtins returning void, as well as for an initializer expression of the form void(). This would then lead to ICEs in CodeGen on code relying on nullptr being returned for void values, which is eg. the case for conditional expressions [0].
This patch fixes that by returning nullptr Values for intrinsics known not to return any values as well as for a scalar initializer returning void.

Fixes https://github.com/llvm/llvm-project/issues/53127

[0] https://github.com/llvm/llvm-project/blob/266ec801fb23f9f5f1d61ca9466e0805fbdb78a7/clang/lib/CodeGen/CGExprScalar.cpp#L4849-L4892


Note:
I opted to adjust these functions as an idealistic goal to be more consistent with the rest of the codebase. An alternative implementation that would have also fixed the above issue and would be less code is to simply handle it within the visit function of the conditional expression, by simply checking if it the type of the expression is void and returning bailing out by returning nullptr there instead of creating the invalid phi node. If you prefer that version or something of the sorts please let me know

Diff Detail

Event Timeline

zero9178 created this revision.Oct 23 2022, 3:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 23 2022, 3:33 AM
zero9178 requested review of this revision.Oct 23 2022, 3:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 23 2022, 3:33 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
zero9178 updated this revision to Diff 470002.Oct 23 2022, 12:53 PM

Rebase and boop CI

zero9178 updated this revision to Diff 470071.Oct 24 2022, 12:32 AM

clang-format and specify target triple in test since mangling is target dependent

This revision is now accepted and ready to land.Oct 24 2022, 10:56 AM
This revision was landed with ongoing or failed builds.Oct 24 2022, 12:41 PM
This revision was automatically updated to reflect the committed changes.